Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Stephen Croll <scroll@xxxxxxxxxxx>
- Date: Fri, 12 Oct 2007 04:22:23 -0500
Howard Wilkinson wrote:
Can you suggest such a list - I can only find lists for POSIX threads!comp.unix.programmer
Code goes as followsI haven't really looked at the code, except for making mods to get it to compile, but it works for me:
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)"
pika.localdomain:~/tmp 0:12> uname -a
Linux pika.localdomain 2.6.22.9-91.fc7 #1 SMP Thu Sep 27 20:47:39 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
pika.localdomain:~/tmp 0:13> cat socketpair.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main()
{
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) printf("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) printf("recv - %s(%d)", strerror(errno), errno);
printf("Socket returned %d bytes\n", rv);
} else {
printf("Socket is not ready to read\n");
}
exit (0);
}
pika.localdomain:~/tmp 0:14> gcc -Wall socketpair.c
pika.localdomain:~/tmp 0:15> time ./a.out
Socket is not ready to read
real 0m10.000s
user 0m0.001s
sys 0m0.000s
pika.localdomain:~/tmp 0:16> ./a.out
Socket is not ready to read
--
Steve Croll
--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
- Follow-Ups:
- References:
- Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Howard Wilkinson
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Gordon Messmer
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Howard Wilkinson
- Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- Prev by Date: Re: Duplicating a F7 installation.
- Next by Date: Re: Ipods
- 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
|