diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-03-01 10:42:48 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-03-01 10:42:48 +0000 |
commit | 2b6ac135fa7071290289741c9e35747bb9f1012f (patch) | |
tree | 037507c43ac097fb2cd5850bbd57f25a553e20e8 /lib/server/Protocol.h | |
parent | 2ef0a9aa8cd3cd4dcfa0cd9d2014051832c52e8a (diff) |
Make Protocol take control of the socket object passed in.
We pass a std::auto_ptr<SocketStream> to every Protocol subclass when we
construct it, and it takes control of this object. This reduces the risk of:
* accidentally reusing the same SocketStream for multiple Protocols
(it happened to me in testbackupstore);
* holding onto a reference to the SocketStream;
* allowing a locally-scoped SocketStream to go out of scope and be released
while still being referenced by a live Protocol.
Diffstat (limited to 'lib/server/Protocol.h')
-rw-r--r-- | lib/server/Protocol.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/server/Protocol.h b/lib/server/Protocol.h index 42cb0ff8..0995393d 100644 --- a/lib/server/Protocol.h +++ b/lib/server/Protocol.h @@ -19,6 +19,7 @@ #include "Message.h" class IOStream; +class SocketStream; // default timeout is 15 minutes #define PROTOCOL_DEFAULT_TIMEOUT (15*60*1000) @@ -36,7 +37,7 @@ class IOStream; class Protocol { public: - Protocol(IOStream &rStream); + Protocol(std::auto_ptr<SocketStream> apConn); virtual ~Protocol(); private: @@ -175,6 +176,8 @@ public: FILE *GetLogToFile() { return mLogToFile; } void SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;} void SetLogToFile(FILE *File = 0) {mLogToFile = File;} + int64_t GetBytesRead() const; + int64_t GetBytesWritten() const; protected: virtual std::auto_ptr<Message> MakeMessage(int ObjType) = 0; @@ -190,7 +193,7 @@ private: void EnsureBufferAllocated(int Size); int SendStreamSendBlock(uint8_t *Block, int BytesInBlock); - IOStream &mrStream; + std::auto_ptr<SocketStream> mapConn; bool mHandshakeDone; unsigned int mMaxObjectSize; int mTimeout; |