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.h126
1 files changed, 0 insertions, 126 deletions
diff --git a/src/stable/tcpsocket.h b/src/stable/tcpsocket.h
deleted file mode 100644
index 69cc4fd..0000000
--- a/src/stable/tcpsocket.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * Copyright (C) 2007-2019 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_TCP_SOCKET_H
9#define BU_TCP_SOCKET_H
10
11#include <stdint.h>
12
13#include "bu/config.h"
14#include "bu/stream.h"
15#include "bu/string.h"
16#include "bu/exceptionbase.h"
17
18namespace Bu
19{
20 subExceptionDeclBegin( TcpSocketException );
21 enum {
22 cRead,
23 cWrite,
24 cBadRead,
25 cClosed,
26 cTimeout
27 };
28 subExceptionDeclEnd();
29
30 /**
31 * Network socket stream class. This class provides a mechanism for
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
34 * standard STREAM TCP/IP sockets.
35 *
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,
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.
40 *
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
43 * will terminate your program immediately unless handled properly. Most
44 * people doing any connections with TcpSocket will want to put this in
45 * their program somewhere before they use it:
46 *@code
47 #include <signal.h>
48 ...
49 ...
50 ...
51 sigset( SIGPIPE, SIG_IGN ); // do this before you use a Bu::TcpSocket
52 @endcode
53 * When this is done, Bu::TcpSocket will simply throw a broken pipe
54 * exception just like every other error condition, allowing your program
55 * to handle it sanely.
56 *
57 *@ingroup Serving
58 *@ingroup Streams
59 */
60 class TcpSocket : public Stream
61 {
62 public:
63#ifdef WIN32
64 typedef unsigned int handle;
65#else
66 typedef int handle;
67#endif
68
69 TcpSocket( handle nTcpSocket );
70 TcpSocket( const String &sAddr, int nPort, int nTimeout=30,
71 bool bBlocking=true );
72 virtual ~TcpSocket();
73
74 virtual void close();
75 virtual size read( void *pBuf, size nBytes );
76 virtual size read( void *pBuf, size nBytes,
77 uint32_t nSec, uint32_t nUSec=0 );
78 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 );
81 using Stream::write;
82
83 virtual size tell();
84 virtual void seek( size offset );
85 virtual void setPos( size pos );
86 virtual void setPosEnd( size pos );
87 virtual bool isEos();
88 virtual bool isOpen();
89
90 virtual void flush();
91
92 virtual bool canRead();
93 virtual bool canWrite();
94
95 virtual bool isReadable();
96 virtual bool isWritable();
97 virtual bool isSeekable();
98
99 virtual bool isBlocking();
100 virtual void setBlocking( bool bBlocking=true );
101
102 virtual void setSize( size iSize );
103
104 Bu::String getAddress() const;
105 operator handle() const;
106
107 handle getHandle() const;
108 handle takeHandle();
109
110 virtual size getSize() const;
111 virtual size getBlockSize() const;
112 virtual Bu::String getLocation() const;
113
114 private:
115 void setAddress();
116
117 handle nTcpSocket;
118
119 bool bActive;
120 bool bBlocking;
121 String sReadBuf;
122 String sAddress;
123 };
124}
125
126#endif