aboutsummaryrefslogtreecommitdiff
path: root/src/stable/tcpsocket.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/tcpsocket.h')
-rw-r--r--src/stable/tcpsocket.h200
1 files changed, 100 insertions, 100 deletions
diff --git a/src/stable/tcpsocket.h b/src/stable/tcpsocket.h
index 92b3c1f..16eca12 100644
--- a/src/stable/tcpsocket.h
+++ b/src/stable/tcpsocket.h
@@ -17,110 +17,110 @@
17 17
18namespace Bu 18namespace Bu
19{ 19{
20 subExceptionDeclBegin( TcpSocketException ); 20 subExceptionDeclBegin( TcpSocketException );
21 enum { 21 enum {
22 cRead, 22 cRead,
23 cWrite, 23 cWrite,
24 cBadRead, 24 cBadRead,
25 cClosed, 25 cClosed,
26 cTimeout 26 cTimeout
27 }; 27 };
28 subExceptionDeclEnd(); 28 subExceptionDeclEnd();
29 29
30 /** 30 /**
31 * Network socket stream class. This class provides a mechanism for 31 * Network socket stream class. This class provides a mechanism for
32 * communicating over a network using TCP/IP. It will provide other low 32 * communicating over a network using TCP/IP. It will provide other low
33 * level protocol and addressing support later on, but for now it's just 33 * level protocol and addressing support later on, but for now it's just
34 * standard STREAM TCP/IP sockets. 34 * standard STREAM TCP/IP sockets.
35 * 35 *
36 * Unlike system sockets, these sockets are opened by default in 36 * Unlike system sockets, these sockets are opened by default in
37 * non-blocking mode, you can specify your own timeout for opening a socket, 37 * non-blocking mode, you can specify your own timeout for opening a socket,
38 * and a number of non-fatal error messages have been automatically handled 38 * and a number of non-fatal error messages have been automatically handled
39 * and treated as standard no-data-available-yet situations on read. 39 * and treated as standard no-data-available-yet situations on read.
40 * 40 *
41 * Please note that there is a condition that will occur eventually (at 41 * Please note that there is a condition that will occur eventually (at
42 * least on *nix systems) that will trigger a SIGPIPE condition. This 42 * least on *nix systems) that will trigger a SIGPIPE condition. This
43 * will terminate your program immediately unless handled properly. Most 43 * will terminate your program immediately unless handled properly. Most
44 * people doing any connections with TcpSocket will want to put this in 44 * people doing any connections with TcpSocket will want to put this in
45 * their program somewhere before they use it: 45 * their program somewhere before they use it:
46 *@code 46 *@code
47 #include <signal.h> 47 #include <signal.h>
48 ... 48 ...
49 ... 49 ...
50 ... 50 ...
51 sigset( SIGPIPE, SIG_IGN ); // do this before you use a Bu::TcpSocket 51 sigset( SIGPIPE, SIG_IGN ); // do this before you use a Bu::TcpSocket
52 @endcode 52 @endcode
53 * When this is done, Bu::TcpSocket will simply throw a broken pipe 53 * When this is done, Bu::TcpSocket will simply throw a broken pipe
54 * exception just like every other error condition, allowing your program 54 * exception just like every other error condition, allowing your program
55 * to handle it sanely. 55 * to handle it sanely.
56 * 56 *
57 *@ingroup Serving 57 *@ingroup Serving
58 *@ingroup Streams 58 *@ingroup Streams
59 */ 59 */
60 class TcpSocket : public Stream 60 class TcpSocket : public Stream
61 { 61 {
62 public: 62 public:
63#ifdef WIN32 63#ifdef WIN32
64 typedef unsigned int handle; 64 typedef unsigned int handle;
65#else 65#else
66 typedef int handle; 66 typedef int handle;
67#endif 67#endif
68 68
69 TcpSocket( handle nTcpSocket ); 69 TcpSocket( handle nTcpSocket );
70 TcpSocket( const String &sAddr, int nPort, int nTimeout=30, 70 TcpSocket( const String &sAddr, int nPort, int nTimeout=30,
71 bool bBlocking=true ); 71 bool bBlocking=true );
72 virtual ~TcpSocket(); 72 virtual ~TcpSocket();
73 73
74 virtual void close(); 74 virtual void close();
75 virtual size read( void *pBuf, size nBytes ); 75 virtual size read( void *pBuf, size nBytes );
76 virtual size read( void *pBuf, size nBytes, 76 virtual size read( void *pBuf, size nBytes,
77 uint32_t nSec, uint32_t nUSec=0 ); 77 uint32_t nSec, uint32_t nUSec=0 );
78 virtual size write( const void *pBuf, size nBytes ); 78 virtual size write( const void *pBuf, size nBytes );
79 virtual size write( const void *pBuf, size nBytes, 79 virtual size write( const void *pBuf, size nBytes,
80 uint32_t nSec, uint32_t nUSec=0 ); 80 uint32_t nSec, uint32_t nUSec=0 );
81 using Stream::write; 81 using Stream::write;
82 82
83 virtual size tell(); 83 virtual size tell();
84 virtual void seek( size offset ); 84 virtual void seek( size offset );
85 virtual void setPos( size pos ); 85 virtual void setPos( size pos );
86 virtual void setPosEnd( size pos ); 86 virtual void setPosEnd( size pos );
87 virtual bool isEos(); 87 virtual bool isEos();
88 virtual bool isOpen(); 88 virtual bool isOpen();
89 89
90 virtual void flush(); 90 virtual void flush();
91 91
92 virtual bool canRead(); 92 virtual bool canRead();
93 virtual bool canWrite(); 93 virtual bool canWrite();
94 94
95 virtual bool isReadable(); 95 virtual bool isReadable();
96 virtual bool isWritable(); 96 virtual bool isWritable();
97 virtual bool isSeekable(); 97 virtual bool isSeekable();
98 98
99 virtual bool isBlocking(); 99 virtual bool isBlocking();
100 virtual void setBlocking( bool bBlocking=true ); 100 virtual void setBlocking( bool bBlocking=true );
101 101
102 virtual void setSize( size iSize ); 102 virtual void setSize( size iSize );
103 103
104 Bu::String getAddress() const; 104 Bu::String getAddress() const;
105 operator handle() const; 105 operator handle() const;
106 106
107 handle getHandle() const; 107 handle getHandle() const;
108 handle takeHandle(); 108 handle takeHandle();
109 109
110 virtual size getSize() const; 110 virtual size getSize() const;
111 virtual size getBlockSize() const; 111 virtual size getBlockSize() const;
112 virtual Bu::String getLocation() const; 112 virtual Bu::String getLocation() const;
113 113
114 private: 114 private:
115 void setAddress(); 115 void setAddress();
116 116
117 handle nTcpSocket; 117 handle nTcpSocket;
118 118
119 bool bActive; 119 bool bActive;
120 bool bBlocking; 120 bool bBlocking;
121 String sReadBuf; 121 String sReadBuf;
122 String sAddress; 122 String sAddress;
123 }; 123 };
124} 124}
125 125
126#endif 126#endif