aboutsummaryrefslogtreecommitdiff
path: root/src/udpsocket.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/udpsocket.h')
-rw-r--r--src/udpsocket.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/udpsocket.h b/src/udpsocket.h
new file mode 100644
index 0000000..8fe114d
--- /dev/null
+++ b/src/udpsocket.h
@@ -0,0 +1,81 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_UDP_SOCKET_H
9#define BU_UDP_SOCKET_H
10
11#include <stdint.h>
12
13#include "bu/stream.h"
14
15namespace Bu
16{
17 subExceptionDecl( UdpSocketException );
18
19 class UdpSocket : public Stream
20 {
21 public:
22 UdpSocket( int iUdpSocket );
23 UdpSocket( const Bu::String &sAddr, int iPort, int iFlags );
24 virtual ~UdpSocket();
25
26 typedef uint32_t addr;
27
28 static Bu::String addrToStr( const addr &a );
29
30 virtual void close();
31 virtual Bu::size read( void *pBuf, Bu::size nBytes );
32 virtual Bu::size read( void *pBuf, Bu::size nBytes,
33 addr &sHost, int &iPort );
34 virtual Bu::size write( const void *pBuf, Bu::size nBytes );
35 using Stream::write;
36
37 virtual Bu::size tell();
38 virtual void seek( Bu::size offset );
39 virtual void setPos( Bu::size pos );
40 virtual void setPosEnd( Bu::size pos );
41 virtual bool isEos();
42 virtual bool isOpen();
43
44 virtual void flush();
45
46 virtual bool canRead();
47 virtual bool canWrite();
48
49 virtual bool isReadable();
50 virtual bool isWritable();
51 virtual bool isSeekable();
52
53 virtual bool isBlocking();
54 virtual void setBlocking( bool bBlocking=true );
55
56 virtual void setSize( Bu::size iSize );
57
58 enum {
59 // Flags
60 Read = 0x01, ///< Open udp socket for reading
61 Write = 0x02, ///< Open udp socket for writing
62 ReadWrite = 0x03, ///< Open for both read and write
63 Broadcast = 0x04, ///< Open for broadcast
64 };
65
66 virtual size getSize() const;
67 virtual size getBlockSize() const;
68 virtual Bu::String getLocation() const;
69
70 private:
71#ifdef WIN32
72 unsigned int iUdpSocket;
73#else
74 int iUdpSocket;
75#endif
76 void *paTarget;
77 bool bBound;
78 };
79};
80
81#endif