[openbeosnetteam] Re: Select()

Yep that's the one! It's exactly what I did and it doesn't work for me...

Code to follow in a minute...

david

----- Original Message -----
From: "Andreas 'powARman' Regel" <andreas.regel@xxxxxx>
To: "David Reid" <openbeosnetteam@xxxxxxxxxxxxx>
Sent: Sunday, March 24, 2002 10:17 PM
Subject: [openbeosnetteam] Re: Select()


> David Reid wrote:
>
> > Philippe come back! All is forgiven!
>
> > I tried to add select hooks and they don't work, so can someone
> > remember/find the code that Philippe posted about how he got it work?
Bruno?
> > I can't seem to find it though I did think I had it in my mail folders
> > somewhere!
>
> Do you mean this?:
>
> Okay, you guys were right about R5.0.3 and select() problem!
> My code doesn't works under R5.0.3. :-( (beside the need to fix some
> compilation errors...)
>
> Not without some tweaks :-)
>
> Problems are:
> - R5.0.3 kernel_intel have a select() call, but is not exported.
> - Be Inc' libnet.so export a select() call, but this one don't works
> with file descriptors, only with R5 net_server sockets.
>
> /me thinks this point explain the previous one: name collision, so
> someone at Be thinks as select() is mostly used with sockets,
>  it's best to overide the kernel fd select() instead of renaming the
> libnet.so call into something like socketselect(), like they did for
> closesocket()...
>
> - lib_tester app can't link against _KERNEL_ to use the kernel select()
> call.
>
> Now, the good news:
>
> - net_stack_driver, like any driver, can perfectly link against
> _KERNEL_ (in fact they have to!). So, from our driver,
> we can call the kernel select() call. It's where the tweak is:
> I've added a special ioctl to *publish* real select() call to userland
> app/lib...
> ;-)
>
> device_control(fd, op_code, ...)
> {
>         switch ( op_code ) {
>         case NET_STACK_SELECT:
>                 {
>                 select_ioctl * ctl = (select_ioctl *) data;
>
>                 DEBUG_ONLY( dprintf(LOGID "--- device_control %p:
select().\n",
> ep) );
>                 return select(ctl->nbits, ctl->read_set, ctl->write_set,
ctl->
> exception_set, ctl->timeout);
>                 };
> ..
> }
>
> - In lib/socket.c I add a net_select() call, which in turn open the /
> dev/net/stack driver to do the real call:
>
> int net_select(int nbits, struct fd_set *rbits, struct fd_set *wbits,
> struct fd_set *ebits, struct timeval *timeout)
> {
>         int                             tmp_sock;
>         select_ioctl    ctl;
>         int                             rc;
>
>         tmp_sock = open(g_stack_driver_path, O_RDWR);
>         if (tmp_sock < 0)
>                 return tmp_sock;
>
>         ctl.nbits                       = nbits;
>         ctl.read_set            = rbits;
>         ctl.write_set           = wbits;
>         ctl.exception_set               = ebits;
>         ctl.timeout                     = timeout;
>
>         rc = ioctl(tmp_sock, NET_STACK_SELECT, &ctl);
>         close(tmp_sock);
>         return rc;
> }
>
> I don't try to name it select(), but I guess it should works too...
>
> - notify_select_event() perfectly works under R5.0.3 kernel :-)
> For read, write and exception events. Remember, the R5 libnet.so'
> select() only works for sockets and only for ready to read event!...
>
> Here the result:
>
> $ lib_tester
> socket(AF_INET, SOCK_STREAM, 0) -> 3
> connect(3, INADDR_LOOPBACK, 21) failed!
> select_test_thread: triggering 2 select event...
> socket 3 ready to write.
>
> Messages send into /var/log/syslog by the driver:
> KERN 'lib_tester'[3820]: net_stack: --- init_driver, built Mar  1 2002
> 01:02:29
> KERN 'lib_tester'[3820]: net_stack: load_driver_symbols("net_stack")
> done.
> KERN 'lib_tester'[3820]: net_stack: --- find_device net/stack
> KERN 'lib_tester'[3820]: net_stack: --- device_open net/stack (O_RDWR)
> -> 0x01731200
> KERN 'lib_tester'[3820]: net_stack: --- device_control 0x01731200:
> socket(1, 2, 0).
> KERN 'lib_tester'[3820]: net_stack: --- device_control 0x01731200:
> connect().
> KERN 'lib_tester'[3820]: net_stack: --- device_open net/stack (O_RDWR)
> -> 0x00de91d0
> KERN 'lib_tester'[3820]: net_stack: --- device_control 0x00de91d0:
> select().
> KERN 'lib_tester'[3820]: net_stack: --- device_select 0x01731200: 1,
> 16777219, 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_select 0x01731200: 2,
> 33554435, 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_select 0x01731200: 3,
> 50331651, 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_deselect 0x01731200: 1,
> 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_deselect 0x01731200: 2,
> 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_deselect 0x01731200: 3,
> 0x0177b244
> KERN 'lib_tester'[3820]: net_stack: --- device_close 0x00de91d0
> KERN 'lib_tester'[3820]: net_stack: --- device_free 0x00de91d0
> KERN 'lib_tester'[3820]: net_stack: --- device_close 0x01731200
> KERN 'lib_tester'[3820]: net_stack: --- device_free 0x01731200
> KERN 'lib_tester'[3820]: net_stack: --- uninit_driver
>
> R5 kernel have full select() support, but it's not exported to userland
> apps only because of name collision with net_server sockets dedicated
> select() call, exported by R5 libnet.so...
> It would be very easy to make a small driver + library only to add real
> file descriptor select() support to R5.0.x...
>
> Could be easier, but anyway it *works* !!!
>
> Time to have some sleep...
>
> -Philippe.
>
>
>


Other related posts: