aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 17:48:45 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 17:48:45 +0000
commitc259f95bd0e58b247940a339bb9b4b401b4e9438 (patch)
tree5ad7bc14bc3b70abbe700131ee519795fd83f150 /src/tests
parentd5709e74f66a7a0f8585e8dadeae3bfcd55da09d (diff)
downloadlibbu++-c259f95bd0e58b247940a339bb9b4b401b4e9438.tar.gz
libbu++-c259f95bd0e58b247940a339bb9b4b401b4e9438.tar.bz2
libbu++-c259f95bd0e58b247940a339bb9b4b401b4e9438.tar.xz
libbu++-c259f95bd0e58b247940a339bb9b4b401b4e9438.zip
UdpSocket is pretty much working. Non-blocking mode isn't, which is odd, but
we can figure that out later.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/udpsocket.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/tests/udpsocket.cpp b/src/tests/udpsocket.cpp
index 3038560..18c7bb9 100644
--- a/src/tests/udpsocket.cpp
+++ b/src/tests/udpsocket.cpp
@@ -2,22 +2,57 @@
2#include "bu/sio.h" 2#include "bu/sio.h"
3 3
4#include <errno.h> 4#include <errno.h>
5#include <arpa/inet.h>
6#include <sys/socket.h>
7#include <netinet/in.h>
8#include <sys/utsname.h>
5 9
6using namespace Bu; 10using namespace Bu;
7 11
8int main( int argc, char *argv[] ) 12int main( int argc, char *argv[] )
9{ 13{
10 if( argv[1][0] == 'l' ) 14 sio << Fmt::hex(8) << INADDR_ANY << sio.nl << Fmt::hex(8) << inet_addr("0.0.0.0") << sio.nl;
15 if( argc == 1 )
16 {
17 sio << "Options are 'l' for listening and 'b' for broadcasting."
18 << sio.nl;
19 }
20 else if( argv[1][0] == 'l' )
11 { 21 {
12 sio << "Listening..." << sio.nl; 22 sio << "Listening..." << sio.nl;
13 Bu::UdpSocket udp( "255.255.255.255", 6688, UdpSocket::Read|UdpSocket::Broadcast ); 23 Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast );
14 24
15 for(;;) 25 for(;;)
16 { 26 {
17 char buf[1501]; 27 char buf[1501];
18 int iRead = udp.read( buf, 1500 ); 28 int iRead = udp.read( buf, 1500 );
19 buf[iRead] = '\0'; 29 if( iRead >= 0 )
20 sio << "Read(" << iRead << "): '" << buf << "'" << sio.nl; 30 {
31 buf[iRead] = '\0';
32 sio << "Read(" << iRead << "): '" << buf << "'" << sio.nl;
33 }
34 else
35 {
36 sio << "Got " << iRead << ": " << strerror( errno ) << sio.nl;
37 }
38 }
39 }
40 else if( argv[1][0] == 'L' )
41 {
42 sio << "Listening..." << sio.nl;
43 Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast );
44
45 for(;;)
46 {
47 char buf[1501];
48 Bu::UdpSocket::addr aHost;
49 int iPort;
50 int iRead = udp.read( buf, 1500, aHost, iPort );
51 if( iRead >= 0 )
52 {
53 buf[iRead] = '\0';
54 sio << "Read(" << iRead << ") from " << Bu::UdpSocket::addrToStr( aHost ) << ":" << iPort << ": '" << buf << "'" << sio.nl;
55 }
21 } 56 }
22 } 57 }
23 else if( argv[1][0] == 'b' ) 58 else if( argv[1][0] == 'b' )