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 10:52:01 +0100
Stephen Croll wrote:
Howard Wilkinson wrote:Thanks for that!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:
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
--I obviously oversimplified the code - attached is my real test case .....
Steve Croll
server - Socket is ready to write
server - Socket is not ready to read
master - Socket is ready to write
master - Socket is ready to read
master - recv - Resource temporarily unavailable(11)
Hmmm!
#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 socktest(int fd, char *prefix) {
fd_set rfd, wfd, efd;
int rv;
char buf[1024];
struct timeval timeout = { 10, 0 };
FD_ZERO(&rfd);
FD_ZERO(&wfd);
FD_ZERO(&efd);
FD_SET(fd, &rfd);
FD_SET(fd, &wfd);
FD_SET(fd, &efd);
rv = select(fd+1, &rfd, &wfd, &efd, &timeout);
if (rv < 0) {
printf("%s - socketpair %s", prefix, strerror(errno));
exit(1);
}
if (FD_ISSET(fd, &wfd)) printf("%s - Socket is ready to write\n", prefix);
if (FD_ISSET(fd, &efd)) printf("%s - Socket is in except\n", prefix);
if (FD_ISSET(fd, &rfd)) {
printf("%s - Socket is ready to read\n", prefix);
rv = recv(fd, buf, sizeof(buf), MSG_DONTWAIT);
if (rv < 0) {
printf("%s - recv - %s(%d)\n", prefix, strerror(errno), errno);
exit (1);
}
printf("%s - Socket returned %d bytes\n", prefix, rv);
} else {
printf("%s - Socket is not ready to read\n", prefix);
}
exit (0);
}
int main() {
int fd[2] = { -1, -1 };
int rv;
pid_t pid;
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);
if ((pid = fork()) > 0) {
shutdown(fd[1], 2);
close(fd[1]);
socktest(fd[0], "master");
} else {
shutdown(fd[0], 2);
close(fd[0]);
socktest(fd[1], "server");
}
}
--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
- Follow-Ups:
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Luciano Rocha
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Andy Green
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Miles Sabin
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- 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
- Re: Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- From: Stephen Croll
- Problem with socketpair , AF_UNIX and select call - can anybody through any light on this!
- Prev by Date: Re: Ipods
- 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
|