[gambit-list] How to monitor arbitrary file descriptors?

Marc Feeley feeley at iro.umontreal.ca
Tue Jul 16 08:48:39 EDT 2019


Nice catch of the ignored “settings” parameter!  Now fixed...

Marc



> On Jul 15, 2019, at 2:49 PM, Jörg F. Wittenberger <Joerg.Wittenberger at softeyes.net> wrote:
> 
> Am Mon, 15 Jul 2019 11:39:26 -0400
> schrieb Marc Feeley <feeley at iro.umontreal.ca>:
> 
>> You can use the ##open-predefined procedure to convert a file
>> descriptor into a Scheme port.  The ##wait-input-port procedure can
>> then be used on the port as shown in the example below.  You can also
>> use the usual Gambit I/O procedures for doing I/O (for example a
>> read-char on the port will block until data is available on the file
>> descriptor).
>> 
>> Marc
> 
> Thank you Marc.  This looks like the thing I've been looking for.
> 
> So far I did not try.  Just reading the source makes me wonder:
> 
> lib/io.scm around line 5280 I found the definition of
> `##open-predefined`.  It looks as if there is an oversight: it
> completedly ignores the optional `settings` parameter.  Shouldn't this
> be somehow mangled into the second parameter of the call to
> `##make-path-psettings`?
> 
> Best
> 
> /Jörg
> 
>> 
>> (c-declare #<<end-of-c-declare
>> 
>> #include <sys/types.h>
>> #include <sys/stat.h>
>> #include <fcntl.h>
>> 
>> end-of-c-declare
>> )
>> 
>> (define O_RDONLY ((c-lambda () int "___return(O_RDONLY);")))
>> (define O_WRONLY ((c-lambda () int "___return(O_WRONLY);")))
>> (define O_RDWR   ((c-lambda () int "___return(O_RDWR);")))
>> 
>> (define posix-open (c-lambda (char-string int int) int "open"))
>> 
>> (define (open path)
>>  (let* ((fd (posix-open path O_RDWR 0))
>>         (port (##open-predefined 3 path fd)))
>>    port))
>> 
>> (define fifo (open "fifo")) ;; created with: mkfifo fifo
>> 
>> (println "waiting for data on fifo...")
>> (##wait-input-port fifo) ;; wait for data to be readable on fd
>> (println "done waiting!")
>> (println (read-char fifo))
>> 
>> 
>>> On Jul 15, 2019, at 9:43 AM, Jörg F. Wittenberger
>>> <Joerg.Wittenberger at softeyes.net> wrote:
>>> 
>>> Hi,
>>> 
>>> I'm trying to wait for IO on some file descriptor.
>>> 
>>> The case at hand is not really relevant, it's a unix domain socket
>>> in this case.  But the same issue would easily apply to other
>>> libraries too.
>>> 
>>> So far I found the gamsock library as a start.  But this ties up the
>>> processor in a loop attempting to receive, learn EWOULDBLOCK and
>>> retry.
>>> 
>>> As I said, I'm not at all sold to the gamsock library or the API.  I
>>> just want a thread to block on a raw file descriptor for IO.  So
>>> maybe there is a way to create a port from a raw file descriptor?
>>> Or anything like that?  How would it be done?
>>> 
>>> Thank you so much.
>>> 
>>> /Jörg
>>> 
>>> 
>>> _______________________________________________
>>> Gambit-list mailing list
>>> Gambit-list at iro.umontreal.ca
>>> https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list  
>> 
>> 
> 
> 





More information about the Gambit-list mailing list