Link to home
Start Free TrialLog in
Avatar of r1ccard0
r1ccard0

asked on

select and FD_ISSET problem

I have two processes running A,B. I send B a message from A, which it receiveds, but when FD_ISSET checks the sock descriptor if more data is there, it states yes.  when my code trys a read the result is nothing.
The problem is why does FD_ISSET still think data is there.
The buffer is large enought to hold the data, and the message is received correctly and succesfully.
An attempt to FD_CLR() does not clear the sock des.
I'm, using SunOS 4.1. Unix, not Linux.
Why does the same thing happen when I create and close a socket ?
Avatar of warren_dale
warren_dale

Assuming:
        int myfd;
        fd_set readfds;        
        struct timeval timeval;
        int ready;
Before EVERY read you must have the following sequence:
        FD_ZERO(readfds);
        FD_SET(myfd, &readfds);
        /* either */
        timeval.tv_sec = seconds;
        timeval.tv_usec = 0;
        /* or NULL as the 5th argument to select() */
        ready = select((myfd+1), &readfds, NULL, NULL, &timeval);
        if (ready == -1)
        {
            if (errno == EINTR)
                continue;
            else
                {ERROR}
        }
        else if (ready == 0)
            {TIMEOUT}
        if (FD_ISSET(myfd, &readfds))
            {DO_THE_READ}
In other words you can only use FD_ISSET() after first using FD_ZERO() FS_SET() and select().
ASKER CERTIFIED SOLUTION
Avatar of julio011597
julio011597

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r1ccard0

ASKER

points waarded to julio