[gambit-list] Is there a way to derive file descriptor values from Gambit-internal TCP socket ports, and use them in non-Gambit-internal I/O routines in C?
Christian Jaeger
christian at pflanze.mine.nu
Fri Sep 5 09:08:14 EDT 2008
Mikael More wrote:
> Now that we have found a way to make a Gambit-internal port of OS file
> descriptors, how about the other way around, i.e.,
>
> a) How get file descriptor values of active Gambit-internal TCP socket
> connection ports?
>
I don't have an answer, but Gambit is handling the lowlevel stuff in C
code (lib/os_io.c), and it seems the filehandle (either a stdio stream
or an fd) in C structs, as can also be seen when inspecting the port
structure. For inspecting random Scheme objects, I've written a helper
library here which turns objects to a sexpr based representation so that
you can see it more easily. It also detects cycles (it will output a
<seen> sexpr in that case).
http://scheme.mine.nu/gambit/experimental/object-to-sexpr/
git clone http://scheme.mine.nu/gambit/experimental/object-to-sexpr/.git
Using this you'll for example see (for an output-only port in this case):
...
(rdevice-condvar #f)
(wdevice-condvar
(<structure>
(value: #<condition-variable #51 #<foreign #52 0x6a0ea0>>)
(type-chain: (#<type #53 condition-variable>))
(btq-deq-next (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-deq-prev (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-color (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-parent (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-left (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-leftmost (<seen> #<condition-variable #51 #<foreign #52 0x6a0ea0>>))
(btq-owner 2)
(name #<foreign #52 0x6a0ea0>)
(specific #!void)))
and it seems Gambit accesses the filehandle from that foreign object. I
haven't looked at the code yet how it gets to it (and won't have time
today).
Christian.
More information about the Gambit-list
mailing list