From 9d099f181674ae075aa8ccaeb56acc7b732638af Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 19 Jan 2009 21:46:48 +0000 Subject: This should fix the problem of never knowing if your sockets are closed. Now Bu::Socket::read will throw an exception if the socket has been closed. Also, you'll get an exception at object creation if the socket could connect to a computer, but not the given port. --- src/tests/socketbreak.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/tests/socketbreak.cpp (limited to 'src/tests') diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp new file mode 100644 index 0000000..82069de --- /dev/null +++ b/src/tests/socketbreak.cpp @@ -0,0 +1,27 @@ +#include "bu/serversocket.h" +#include "bu/socket.h" + +int main() +{ + Bu::ServerSocket sSrv( 9987 ); + + Bu::Socket sSend("localhost", 9987 ); + + Bu::Socket sRecv( sSrv.accept() ); + + printf("Connected sockets.\n"); + + sleep( 1 ); + printf("Closing sRecv.\n"); + sRecv.close(); + sleep( 1 ); + + char buf[3]; + printf("About to write.\n"); + printf("write: %d\n", sSend.write("hi", 2 ) ); + printf("About to read.\n"); + printf("read: %d\n", sSend.read( buf, 2 ) ); + + return 0; +} + -- cgit v1.2.3