Re: Problem using sockets

Emilio Lopes <[email protected]> Sun, 26 Aug 2007 15:22:19 +0200
Newsgroups gmane.lisp.scheme.scsh
Organization The Church of Emacs
Message-ID <[email protected]>
Michael Sperber writes:

> I know it's late ...    Sorry.

No problem, I already imagined you'd be busy with other affairs... :-)

> The gc-protection-mismatch problem is obvious enough.  After that, I
> don't get any exceptions with your example.  Could you try again with
> the patch?

Yes, writing to the socket now works, thank you.  But closing the
socket still gives an error/warning/exception:

   Welcome to scsh 0.6.7 (R6RS)
   Type ,? for help.
   > ,open threads
   > (define (server-start socket socket-addr)
     (format #t "Hello, ~a!\n" (host-info:name (host-info socket-addr)))
     (let ((inport (socket:inport socket))
           (outport (socket:outport socket)))
       (let loop ()
         (let ((input (read-line inport 'trim)))
           (cond
            ((eof-object? input)
             (display "Goodbye.\n" outport)
             (shutdown-socket socket shutdown/sends+receives))
            (else
             (format outport "You said: \"~A\".\n" input)
             (loop)))))))
   > (spawn
    (lambda ()
      (bind-listen-accept-loop protocol-family/internet server-start 6666)))
   > (define *server-socket* (socket-connect protocol-family/internet socket-type/stream "localhost" 6666))
   Hello, jumeirah!
   > (send-message *server-socket* "hi!\n")
   > (read-line (socket:inport *server-socket*))
   "You said: \"hi!\"."
   > (close-socket *server-socket*)
   > Warning: error when flushing buffer; closing port
       #{Output-fdport #{Output-channel 8}}
       (exception 117 os-error 32 #{Byte-vector (length 255) 71 111 111 100 98 121 101 46 10 32 34 104 105 33 34 46 ...} 0 9 #{Output-channel 8} Broken pipe)

   > 

-- 
Emílio C. Lopes
Munich, Germany