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