aboutsummaryrefslogtreecommitdiff
path: root/src/tests/socketbreak.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-19 21:46:48 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-19 21:46:48 +0000
commit9d099f181674ae075aa8ccaeb56acc7b732638af (patch)
treea376da5671e044e74b4014d43c9125974b4dee0c /src/tests/socketbreak.cpp
parent8c1f4d7bace6ff2c99d546cedaba890b349e88f8 (diff)
downloadlibbu++-9d099f181674ae075aa8ccaeb56acc7b732638af.tar.gz
libbu++-9d099f181674ae075aa8ccaeb56acc7b732638af.tar.bz2
libbu++-9d099f181674ae075aa8ccaeb56acc7b732638af.tar.xz
libbu++-9d099f181674ae075aa8ccaeb56acc7b732638af.zip
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.
Diffstat (limited to '')
-rw-r--r--src/tests/socketbreak.cpp27
1 files changed, 27 insertions, 0 deletions
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 @@
1#include "bu/serversocket.h"
2#include "bu/socket.h"
3
4int main()
5{
6 Bu::ServerSocket sSrv( 9987 );
7
8 Bu::Socket sSend("localhost", 9987 );
9
10 Bu::Socket sRecv( sSrv.accept() );
11
12 printf("Connected sockets.\n");
13
14 sleep( 1 );
15 printf("Closing sRecv.\n");
16 sRecv.close();
17 sleep( 1 );
18
19 char buf[3];
20 printf("About to write.\n");
21 printf("write: %d\n", sSend.write("hi", 2 ) );
22 printf("About to read.\n");
23 printf("read: %d\n", sSend.read( buf, 2 ) );
24
25 return 0;
26}
27