diff options
author | Justin Berger <j.david.berger@gmail.com> | 2017-02-25 22:06:34 (GMT) |
---|---|---|
committer | Justin Berger <j.david.berger@gmail.com> | 2017-07-11 00:12:05 (GMT) |
commit | cf0ae55dcb9224b92a95166f17452c56ba5b6213 (patch) | |
tree | 95f53f8e5aee010f5cd4cb90871bac18216d5402 /Source/cmConnection.h | |
parent | 5ddfb6a472539c3a01a6f8e6d8fa1cb1013fc4f9 (diff) | |
download | CMake-cf0ae55dcb9224b92a95166f17452c56ba5b6213.zip CMake-cf0ae55dcb9224b92a95166f17452c56ba5b6213.tar.gz CMake-cf0ae55dcb9224b92a95166f17452c56ba5b6213.tar.bz2 |
server: Add support for connections that aren't event based
Diffstat (limited to 'Source/cmConnection.h')
-rw-r--r-- | Source/cmConnection.h | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/Source/cmConnection.h b/Source/cmConnection.h index e994716..4b8fcb3 100644 --- a/Source/cmConnection.h +++ b/Source/cmConnection.h @@ -46,43 +46,57 @@ public: // TODO: There should be a callback / flag set for errors }; -/*** - * Abstraction of a connection; ties in event callbacks from libuv and notifies - * the server when appropriate - */ class cmConnection { CM_DISABLE_COPY(cmConnection) public: + cmConnection() {} + + virtual void WriteData(const std::string& data) = 0; + virtual ~cmConnection(); + virtual bool OnConnectionShuttingDown(); + + virtual bool IsOpen() const = 0; + + virtual void SetServer(cmServerBase* s); + + virtual void ProcessRequest(const std::string& request); + + virtual bool OnServeStart(std::string* pString); + +protected: + cmServerBase* Server = nullptr; +}; + +/*** + * Abstraction of a connection; ties in event callbacks from libuv and notifies + * the server when appropriate + */ +class cmEventBasedConnection : public cmConnection +{ + +public: /*** * @param bufferStrategy If no strategy is given, it will process the raw * chunks as they come in. The connection * owns the pointer given. */ - cmConnection(cmConnectionBufferStrategy* bufferStrategy = nullptr); + cmEventBasedConnection(cmConnectionBufferStrategy* bufferStrategy = nullptr); virtual void Connect(uv_stream_t* server); virtual void ReadData(const std::string& data); - virtual bool OnServeStart(std::string* errString); + bool IsOpen() const override; - virtual bool OnServerShuttingDown(); - - virtual bool IsOpen() const; - - virtual void WriteData(const std::string& data); - - virtual void ProcessRequest(const std::string& request); - - virtual void SetServer(cmServerBase* s); + void WriteData(const std::string& data) override; + bool OnConnectionShuttingDown() override; virtual void OnDisconnect(int errorCode); uv_stream_t* ReadStream = nullptr; - cmServerBase* Server = nullptr; uv_stream_t* WriteStream = nullptr; static void on_close(uv_handle_t* handle); |