source: box/trunk/lib/server/SocketStream.h @ 3084

Revision 3084, 2.0 KB checked in by chris, 3 months ago (diff)

Add experimental "TCP Nice" mode, disabled by default.

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    SocketStream.h
5//              Purpose: I/O stream interface for sockets
6//              Created: 2003/07/31
7//
8// --------------------------------------------------------------------------
9
10#ifndef SOCKETSTREAM__H
11#define SOCKETSTREAM__H
12
13#include "IOStream.h"
14#include "Socket.h"
15
16#ifdef WIN32
17        typedef SOCKET tOSSocketHandle;
18        #define INVALID_SOCKET_VALUE (tOSSocketHandle)(-1)
19#else
20        typedef int tOSSocketHandle;
21        #define INVALID_SOCKET_VALUE -1
22#endif
23
24// --------------------------------------------------------------------------
25//
26// Class
27//              Name:    SocketStream
28//              Purpose: Stream interface for sockets
29//              Created: 2003/07/31
30//
31// --------------------------------------------------------------------------
32class SocketStream : public IOStream
33{
34public:
35        SocketStream();
36        SocketStream(int socket);
37        SocketStream(const SocketStream &rToCopy);
38        ~SocketStream();
39       
40        void Open(Socket::Type Type, const std::string& rName, int Port = 0);
41        void Attach(int socket);
42
43        virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
44        virtual void Write(const void *pBuffer, int NBytes);
45        virtual void Close();
46        virtual bool StreamDataLeft();
47        virtual bool StreamClosed();
48
49        virtual void Shutdown(bool Read = true, bool Write = true);
50
51        virtual bool GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut);
52
53protected:
54        void MarkAsReadClosed() {mReadClosed = true;}
55        void MarkAsWriteClosed() {mWriteClosed = true;}
56
57private:
58        tOSSocketHandle mSocketHandle;
59        bool mReadClosed;
60        bool mWriteClosed;
61
62protected:
63        off_t mBytesRead;
64        off_t mBytesWritten;
65
66public:
67        off_t GetBytesRead() const {return mBytesRead;}
68        off_t GetBytesWritten() const {return mBytesWritten;}
69        void ResetCounters() {mBytesRead = mBytesWritten = 0;}
70        bool IsOpened() { return mSocketHandle != INVALID_SOCKET_VALUE; }
71       
72        /**
73         * Only for use by NiceSocketStream!
74         */
75        tOSSocketHandle GetSocketHandle();
76};
77
78#endif // SOCKETSTREAM__H
79
Note: See TracBrowser for help on using the repository browser.