select() & gsk_secure_soc_read() questions

Kelly Beard <[email protected]> Tue, 13 Feb 2024 13:48:28 -0600
Newsgroups gmane.comp.lang.as400.c
Message-ID <CAOvM2Su4Z33EU25iw+5_Z8uZJG9D6scjSssMxpOiw=eYzp14tA@mail.gmail.com>
I've done some socket programming in my past, and select() has been my
go-to to prevent hanging reads.  Something isn't working in this case.
We've purposely asked the vendor we're sending to to not send a response in
order to test our timeout code.  That appears to be working, at least on
their end.  My tried-and-true method of ensuring that I don't hang on a
read when there is nothing there, is not.  Below is what I have going on.
In essence, select() is returning right away with 1 as though there is
something available, but soc_read() hangs forever until something happens
(several minutes) and the read is terminated.

So, has anyone seen something like this before?  Is there another method I
can use?

    int amtRead = 0, totalRead = 0, select_rc;
    fd_set read_set, write_set, error_set;
    struct timeval timeout = { 10, 0 };         // 10 second timeout
    FD_ZERO(&read_set);
    FD_ZERO(&error_set);
    FD_SET(sd, &read_set);
    FD_SET(sd, &error_set);
    timeout.tv_sec = TV_SEC;           // reset this on every new iteration.
    timeout.tv_usec = 0;

    do {
        if (bDebug) {
            CERR2 << "calling select()...\n";
        }
        select_rc = select(sd + 1, &read_set, NULL, &error_set, &timeout);
        if (bDebug) {
            CERR << "select_rc=" << select_rc << '\n';
        }

        if (select_rc == 0) {       // TIMEOUT
            break;
        }
        else if (select_rc == 1 && FD_ISSET(sd, &read_set)) {
            timeout.tv_sec  = 0;
            timeout.tv_usec = 500000;

            //Read via TLS
            rc = gsk_secure_soc_read(my_session_handle, buff2,
sizeof(buff2), &amtRead);
            if (rc != GSK_OK) {
                sstr << "gsk_secure_soc_write() failed with rc = " << rc <<
" (" << gsk_strerror(rc) << "), errno=" << strerror(errno);
                throw runtime_error(sstr.str());
            }
            // keep an accumualtor going
            totalRead += amtRead;

...
code continues...

-- 
Kelly Beard
-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/c400-l.