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/httpserver | |
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/httpserver')
-rw-r--r-- | lib/httpserver/HTTPServer.cpp | 6 | ||||
-rw-r--r-- | lib/httpserver/HTTPServer.h | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/httpserver/HTTPServer.cpp b/lib/httpserver/HTTPServer.cpp index be1db687..d36be473 100644 --- a/lib/httpserver/HTTPServer.cpp +++ b/lib/httpserver/HTTPServer.cpp @@ -132,10 +132,10 @@ void HTTPServer::Run() // Created: 26/3/04 // // -------------------------------------------------------------------------- -void HTTPServer::Connection(SocketStream &rStream) +void HTTPServer::Connection(std::auto_ptr<SocketStream> apConn) { // Create a get line object to use - IOStreamGetLine getLine(rStream); + IOStreamGetLine getLine(*apConn); // Notify dervived claases HTTPConnectionOpening(); @@ -152,7 +152,7 @@ void HTTPServer::Connection(SocketStream &rStream) } // Generate a response - HTTPResponse response(&rStream); + HTTPResponse response(apConn.get()); try { diff --git a/lib/httpserver/HTTPServer.h b/lib/httpserver/HTTPServer.h index d9f74949..91f4e96c 100644 --- a/lib/httpserver/HTTPServer.h +++ b/lib/httpserver/HTTPServer.h @@ -62,7 +62,7 @@ private: const char *DaemonName() const; const ConfigurationVerify *GetConfigVerify() const; void Run(); - void Connection(SocketStream &rStream); + void Connection(std::auto_ptr<SocketStream> apStream); }; // Root level |