Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Howard Wilkinson <howard@xxxxxxxxxxx>
- Date: Fri, 12 Oct 2007 09:53:52 +0100
Gordon Messmer wrote:
Howard Wilkinson wrote:Can you suggest such a list - I can only find lists for POSIX threads!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.
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
- Follow-Ups:
- References:
- Prev by Date: Duplicating a F7 installation.
- Next by Date: Re: Sandisk Sansa c250
- Previous by thread: Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- Next by thread: Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- Index(es):
Relevant Pages
|