[plt-scheme] FFI stuff: getting a fileno file descriptor from an input port?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Aug 31 19:38:07 EDT 2005

> > I'll be using scheme_get_port_file_descriptor() to hook into the
> > 'sendfile' C function; I want to see if it will help improve the speed
> > of sending static files for the web-server collection.
>
> Let me know. I'm curious to hear how much it improves.


Hi Matthew,

I'm not sure if you're added scheme_get_port_file_descriptor() yet; I'll
work on the assumption that it might not yet in, and have been writing
some code to do the descriptor extraction from those ports, so if you're
working on it, no hurry: I can just hack it for now.

I realized, though, that when I tried to call sendfile, I forgot one
crucial thing: I forgot about the tcp socket descriptor that I also need.
So I need access to that one too.

Since sendfile will probably only work on Unix, I've been concentrating on
network.c's definition of the tcp_t type:

################################
typedef struct Scheme_Tcp_Buf {
  MZTAG_IF_REQUIRED
  short refcount;
  char *buffer, *out_buffer;
  short bufpos, bufmax;
  short hiteof, bufmode;
  short out_bufpos, out_bufmax;
  short out_bufmode;
} Scheme_Tcp_Buf;

typedef struct Scheme_Tcp {
  Scheme_Tcp_Buf b;
  tcp_t tcp;
  ...
################################

I see that it shouldn't be too hard to call SCHEME_OUTPORT_VAL to get at a
Scheme_Tcp data structure.  So I almost have what I need to get at that
tcp-port file descriptor.

But one of the problem I have is this: I'd like my extension to work with
both the standard conservative GC-ed mzscheme as well as the precise one,
and the size of the Scheme_Tcp_Buf struct is different depending on if I'm
using mzscheme or mzscheme3m.

Is there a nice runtime way to know if one is running under mzscheme3m or
mzscheme?  How do people write FFI extensions that are supposed to
interact with both the conservative and precise collectors?


Thanks again!



Posted on the users mailing list.