From e69755ce728dd2d2b6abb61b82045e9d555630ba Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 20 May 2008 07:55:42 -0500 Subject: [PATCH] Fix duplex streams --- extra/io/sockets/sockets-tests.factor | 24 +++++++++++++++++++++++- extra/io/streams/duplex/duplex.factor | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/extra/io/sockets/sockets-tests.factor b/extra/io/sockets/sockets-tests.factor index dfeb311312..8264bec032 100755 --- a/extra/io/sockets/sockets-tests.factor +++ b/extra/io/sockets/sockets-tests.factor @@ -1,6 +1,7 @@ IN: io.sockets.tests USING: io.sockets sequences math tools.test namespaces accessors -kernel destructors calendar io.timeouts ; +kernel destructors calendar io.timeouts io.encodings.utf8 io +concurrency.promises threads io.streams.string ; [ B{ 1 2 3 4 } ] [ "1.2.3.4" T{ inet4 } inet-pton ] unit-test @@ -68,3 +69,24 @@ kernel destructors calendar io.timeouts ; [ ] [ 1 seconds "datagram3" get set-timeout ] unit-test [ "datagram3" get receive ] must-fail + +! See what happens if other end is closed +[ ] [ "port" set ] unit-test + +[ ] [ + [ + "127.0.0.1" 0 utf8 + dup addr>> "port" get fulfill + [ + accept drop + dup stream-readln drop + "hello" swap stream-copy + ] with-disposal + ] "Socket close test" spawn drop +] unit-test + +[ "hello" f ] [ + "port" get ?promise utf8 [ + "hi\n" write flush readln readln + ] with-client +] unit-test diff --git a/extra/io/streams/duplex/duplex.factor b/extra/io/streams/duplex/duplex.factor index 86b9f90ff5..02d7ab61be 100755 --- a/extra/io/streams/duplex/duplex.factor +++ b/extra/io/streams/duplex/duplex.factor @@ -24,8 +24,8 @@ M: duplex-stream dispose #! are attached to the same file descriptor, the output #! buffer needs to be flushed before we close the fd. [ - [ out>> &dispose drop ] [ in>> &dispose drop ] + [ out>> &dispose drop ] bi ] with-destructors ;