[openbeosnetteam] Select code...
- From: "David Reid" <dreid@xxxxxxxxxxxx>
- To: "OpenBeOS Network Team" <openbeosnetteam@xxxxxxxxxxxxx>
- Date: Sun, 24 Mar 2002 22:31:45 -0000
This is the code I'm using and it doesn't work!
in net_structures.h
struct select_args {
int mfd;
struct fd_set *rbits;
struct fd_set *wbits;
struct fd_set *ebits;
struct timeval *tv;
};
In libnet.c we take this and make the call to ioctl...
int net_select(int nbits, struct fd_set *rbits,
struct fd_set *wbits,
struct fd_set *ebits,
struct timeval *timeout)
{
int tmpfd = open("/dev/net/socket", O_RDWR);
struct select_args sa;
int error;
int i;
sa.mfd = nbits;
sa.rbits = rbits;
sa.wbits = wbits;
sa.ebits = ebits;
sa.tv = timeout;
for (i=2; i <10;i++) {
if (rbits)
if (FD_ISSET(i, rbits))
printf("socket %d set in read bits...\n",
i);
}
error = ioctl(tmpfd, NET_SOCKET_SELECT, &sa, sizeof(sa));
close(tmpfd);
return error;
}
In the socket driver we call this code...
case NET_SOCKET_SELECT: {
struct select_args *sa = (struct select_args *)data;
int i;
dprintf("NET_SOCKET_SELECT, mfd = %d\n", sa->mfd);
for (i=2; i < sa->mfd;i++) {
dprintf("socket %d: ", i);
if (sa->rbits && FD_ISSET(i, sa->rbits))
dprintf(" read bit ", i);
if (sa->wbits && FD_ISSET(i, sa->wbits))
dprintf(" write bit ", i);
if (sa->ebits && FD_ISSET(i, sa->ebits))
dprintf(" except bit ", i);
dprintf("\n");
}
i = select(sa->mfd, sa->rbits, sa->wbits, sa->ebits,
sa->tv);
dprintf("kernel select returned %d\n", i);
return i;
}
And in test1.c this is how we call it...
struct fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
FD_SET(s, &fds);
tv.tv_sec = 1;
tv.tv_usec = 0;
rv = net_select(s +1, &fds, NULL, NULL, &tv);
printf("select gave %d\n", rv);
rv = net_select(s +1, NULL, &fds, NULL, &tv);
printf("select gave %d\n", rv);
rv = net_select(s +1, NULL, NULL, &fds, &tv);
printf("select gave %d\n", rv);
What does it give???
NET_SOCKET_SELECT, mfd = 5
socket 2:
socket 3:
socket 4: read bit
kernel select returned -2147483643
NET_SOCKET_SELECT, mfd = 5
socket 2:
socket 3:
socket 4: write bit
kernel select returned -2147483643
NET_SOCKET_SELECT, mfd = 5
socket 2:
socket 3:
socket 4: except bit
kernel select returned -2147483643
What's even stranger is that the ioctl cal seems to report it as -1 instead
of the larger value! I think the error code is EINVAL, but am not sure why
as this code works on other OS's... Perhaps I need to copy the contents? I'm
not sure so maybe someone can help! The FD headers are in a new header file
sys/select.h which are an exact copy of the Be ones!
david
Other related posts: