TCP/IP I/O stream problem?
Hi,
I have the following situation:
(let ((stream (comm:open-tcp-stream “localhost” 27017)))
(stream:stream-write-buffer stream …) ;; (1)
(loop (let ((intermediate-result ;; (2)
(loop (stream:with-stream-input-buffer (buffer index limit) stream
(loop ...))
(unless (stream:stream-fill-buffer stream)
(error “something wrong”)))))
(stream:stream-write-buffer stream ...)))) ;; (3)
What this code does is write some kind of command via the stream to a server (1), then process the result returned by the server by reading something from the stream (2), and while doing so send more commands to the server (3), based on intermediate results. The important bit here is that the sending of the new commands in (3) happens while the previous result hasn’t been fully processed yet (so the input buffer still has characters coming in). Bypassing the internal output buffer by using stream-write-buffer directly is intentional.
It seems that LispWorks gets stuck here and ends up in a deadlock somehow, making no progress anymore. When interrupting the execution, the backtrace shows me that LispWorks is stuck somewhere at stream-write-buffer at (3). Is this a known issue? Is this something that’s generally true of TCP/IP sockets (my knowledge here is not that firm), that input and output should not be interweaved?
When I split up the stream in two separate input and output streams, everything is fine, and that’s the workaround I’m currently using:
(let ((input (comm:open-tcp-stream “localhost” 27017))
(output (comm:open-tcp-stream "localhost" 27017)))
(stream:stream-write-buffer output …) ;; (1)
(loop (let ((intermediate-result ;; (2)
(loop (stream:with-stream-input-buffer (buffer index limit) input
(loop ...))
(unless (stream:stream-fill-buffer input)
(error “something wrong”)))))
(stream:stream-write-buffer output ...)))) ;; (3)
Any enlightenment would be highly appreciated.
Thanks,
Pascal
--
Pascal Costanza, ExaScience Life Lab, Intel, Belgium
pascal.costanza@intel.com
The views expressed in this email are my own, and not those of my employer.
Intel Corporation NV/SA
Kings Square, Veldkant 31
2550 Kontich
RPM (Bruxelles) 0415.497.718.
Citibank, Brussels, account 570/1031255/09
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html