// Use of this source code is governed by a BSD 3-Clause License // that can be found in the LICENSE file. // Author: caozhiyi (caozhiyi5@gmail.com) #ifndef CPPNET_SOCKET_READ_WRITE_SOCKET #define CPPNET_SOCKET_READ_WRITE_SOCKET #include "socket_interface.h" #include "include/cppnet_socket.h" namespace cppnet { class Event; class Dispatcher; class BufferQueue; class AlloterWrap; class BlockMemoryPool; class RWSocket: public Socket, public CNSocket, public std::enable_shared_from_this { public: RWSocket(std::shared_ptr alloter); RWSocket(uint64_t sock, std::shared_ptr alloter); virtual ~RWSocket(); virtual bool GetAddress(std::string& ip, uint16_t& port); virtual bool Close(); virtual void Read(); virtual bool Write(const char* src, uint32_t len) { return false; } virtual void Connect(const std::string& ip, uint16_t port); virtual void Disconnect(); virtual uint64_t AddTimer(uint32_t interval, bool always = false); virtual void StopTimer(uint64_t timer_id); virtual void OnTimer(); virtual void OnRead(uint32_t len = 0) {} virtual void OnWrite(uint32_t len = 0) {} virtual void OnConnect(uint16_t err); virtual void OnDisConnect(uint16_t err); std::shared_ptr GetReadBuffer() { return _read_buffer; } std::shared_ptr GetWriteBuffer() { return _write_buffer; } protected: std::shared_ptr _block_pool; std::shared_ptr _event; std::shared_ptr _write_buffer; std::shared_ptr _read_buffer; }; std::shared_ptr MakeRWSocket(std::shared_ptr alloter); std::shared_ptr MakeRWSocket(uint64_t sock, std::shared_ptr alloter); } #endif