Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!



Gordon Messmer wrote:
Howard Wilkinson wrote:
I wanted to add a socketpair connection from the master process to the servers which implement the actual functionality. I created the socketpair, set both ends non-blocking and added it to the select set of fd's. I get an immediate return saying that the socket is ready to read but when I issue a recv I get -1 (EAGAIN). Nothing I have tried sets the required behaviour of only returning when there is 'real' data to read.

You're probably better off asking on a Posix programming list than here. Wherever you ask, though, you should post the code in question, or code that demonstrates the problem in a state that can be compiled and verified by others. While you've described what you think you've done, you haven't given enough information for us to do anything but guess at the problem.

Can you suggest such a list - I can only find lists for POSIX threads!

Code goes as follows

int fd[2] = { -1, -1 };
fd_set rfd;
int rv;
char buf[1024];
struct timeval timeout = { 10, 0 };

rv = socketpair(PF_UNIX, SOCK_DGRAM, 0, fd);
if (rv < 0) Err("socketpair");

fcntl(fd[0], F_SETFL, fcntl(fd[0], F_GETFL, 0) | O_NONBLOCK);

FD_ZERO(rfd);
FD_SET(fd[0], rfd);

rv = select(fd[0]+1, &rfd, NULL, NULL, &timeout);

if (FD_ISSET(fd[0], rfd)) {
printf("Socket is ready to read\n");
rv = recv(fd[0], buf, sizeof(buf), MSG_DONTWAIT);
if (rv < 0) Err("recv - %s(%d)", strerror(errno), errno);
printf("Socket returned %d bytes\n", rv);
} else {
printf("Socket is not ready to read\n");
}
exit (0);

I contend that this should (if I understand the semantics correctly) print out "Socket not ready to read" instead I get "recv - Resource temporarily unavailable(11)"

Anybody?

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

Relevant Pages

  • Re: Synchronization with CAsyncSocket in CE 6.0
    ... number of bytes in the first packet, followed by packets of, say 1024 bytes. ... recv() operations, reassembling it into the format that you need. ... don't forget that recv can return zero, if the socket has ... So, CAsyncSocket while possibly a bad way to do things, does not appear to ...
    (microsoft.public.windowsce.embedded)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Re: Receive no data
    ... It is a best practice to shutdown ... a socket for sending once all data has been sent. ... I see multiple recv() statements in the code. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Winsock Question
    ... Non-blocking means the recv call won't wait for data if there's no ... socket will block until there's enough data to fill the supplied buffer, ... Winsock fills that stack as long as it has free space, ...
    (microsoft.public.win32.programmer.networks)