[gambit-list] Get OS file descriptor of TCP socket port Re: Location of ___device_tcp_client_struct definition

Taylor Venable taylor at metasyntax.net
Sun Jan 17 11:45:16 EST 2010


On Sun, 2010-01-17 at 13:10 +0100, Mikael wrote:
> The code attached at the bottom does what you want, without need for
> linking to os_io.c . In case Gambit would change it might need update.

Thanks for the alternate approach.  Specifically I've been looking at
using this for adding libevent support; the code is checked into my CVS
repository on my website at

http://metasyntax.net/cgi-bin/cvsweb/Libraries/Scheme/libevent/

A question about your approach: doesn't this assume that the socket file
descriptor will always be located in memory immediately after the device
stream struct base?  It seems like that would be prone to the same
problems of a change in Gambit that including the definition of
___device_tcp_client_struct would, but perhaps with less possibility of
the compiler warning you.

Is there some trick to accessing util#device-port-rdevince-condvar?
When I compile that I get:

WARNING -- "util#device-port-rdevice-condvar" is not defined

for which reason in my code I use (##include "_gambit#.scm") and then
call macro-device-port-rdevice-condvar.

> (define (tcp-socket-port->fd port)
>   (let* ((___device_tcp_client (condition-variable-name
> (util#device-port-rdevice-condvar port)))
>          (ptr (foreign-address ___device_tcp_client)))
>     ((c-lambda (unsigned-long) int #<<C
>        int ptrv = ___arg1;
>        // fprintf(stderr,"In C now, the pointer value is %i.
> sizeof(___device_stream) is %i.\n\n",ptrv,sizeof(___device_stream));
>        // ___device_stream* v = ___CAST(___device_stream*,(int*)
> ptrv);
>        // fprintf(stderr,"v is %i.\n",(int) v);
>        ptrv += sizeof(___device_stream);
>        int* ptr = (int*) ptrv;
>        // fprintf(stderr,"In C now, after having added to the pointer,
> it's %i (%i). The value found at its location is %i.\n\n",(int)
> ptr,ptrv,*ptr);
>        ___result = *ptr;
> C
>                ) ptr)))

Thanks,

-- 
Taylor Venable
http://metasyntax.net/




More information about the Gambit-list mailing list