[plt-scheme] FFI + errno

From: Ben Goetter (goetter at mazama.net)
Date: Mon Dec 7 18:48:55 EST 2009

If the PLT runtime itself calls any C runtime function between the time 
that your call to socket() sets errno and the time that you can access 
your thunk to errno, then errno will no longer contain the value set by 
socket().

Hence you cannot use errno usefully through the FFI.  Mechanically, you 
could access the contents of that variable through make-c-parameter or 
the like.

I would favor the existing scheme/tcp or scheme/udp bindings, if at all 
possible.


Steve Huffman wrote:
> Hi All,
>
> I'm using OS X and trying to access the raw socket api using PLT's
> FFI. For example:
>
> (define _socket
>   (get-ffi-obj "socket" #f (_fun _int _int _int -> _int)))
>
> (define _connect
>   (get-ffi-obj "connect" #f (_fun _int _sockaddr_in-pointer _int -> _int)))
>
> Things are mostly working, except I'm having trouble accessing the
> global errno value to see error codes. I've tried wrapping the
> __error() function, but am not receive relevant error codes.
>
> I gather from searching this list that PLT itself might be using errno
> for its own purposes before I get a chance to see it. Is that
> accurate?
>
> Should I write my own wrapper functions in C around the socket
> functions and capture/store errno someplace else?
>
> Thanks,
>
> Steve
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>   



Posted on the users mailing list.