X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2Fasync%2FAsyncTransport.h;h=26cafbff99d1d7b13e352e302a0cdf4aba89ff8f;hp=b45ed96d5fc3c4c459dfecc575a2e928ae021f45;hb=8f29e4838e58ce0db0557d56c756e9e644437111;hpb=58ddb58be76d43be88709cd45afabe0c785ea9e2 diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index b45ed96d..26cafbff 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -56,6 +56,10 @@ enum class WriteFlags : uint32_t { * will be acknowledged. */ EOR = 0x02, + /* + * this indicates that only the write side of socket should be shutdown + */ + WRITE_SHUTDOWN = 0x04, }; /* @@ -226,6 +230,7 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { virtual bool isPending() const { return readable(); } + /** * Determine if transport is connected to the endpoint * @@ -331,12 +336,8 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { virtual ~AsyncTransport() = default; }; -// Transitional intermediate interface. This is deprecated. -// Wrapper around folly::AsyncTransport, that includes read/write callbacks -class AsyncTransportWrapper : virtual public AsyncTransport { +class AsyncReader { public: - typedef std::unique_ptr UniquePtr; - class ReadCallback { public: virtual ~ReadCallback() = default; @@ -453,6 +454,16 @@ class AsyncTransportWrapper : virtual public AsyncTransport { virtual void readErr(const AsyncSocketException& ex) noexcept = 0; }; + // Read methods that aren't part of AsyncTransport. + virtual void setReadCB(ReadCallback* callback) = 0; + virtual ReadCallback* getReadCallback() const = 0; + + protected: + virtual ~AsyncReader() = default; +}; + +class AsyncWriter { + public: class WriteCallback { public: virtual ~WriteCallback() = default; @@ -480,10 +491,7 @@ class AsyncTransportWrapper : virtual public AsyncTransport { const AsyncSocketException& ex) noexcept = 0; }; - // Read/write methods that aren't part of AsyncTransport - virtual void setReadCB(ReadCallback* callback) = 0; - virtual ReadCallback* getReadCallback() const = 0; - + // Write methods that aren't part of AsyncTransport virtual void write(WriteCallback* callback, const void* buf, size_t bytes, WriteFlags flags = WriteFlags::NONE) = 0; virtual void writev(WriteCallback* callback, const iovec* vec, size_t count, @@ -491,6 +499,40 @@ class AsyncTransportWrapper : virtual public AsyncTransport { virtual void writeChain(WriteCallback* callback, std::unique_ptr&& buf, WriteFlags flags = WriteFlags::NONE) = 0; + + protected: + virtual ~AsyncWriter() = default; +}; + +// Transitional intermediate interface. This is deprecated. +// Wrapper around folly::AsyncTransport, that includes read/write callbacks +class AsyncTransportWrapper : virtual public AsyncTransport, + virtual public AsyncReader, + virtual public AsyncWriter { + public: + using UniquePtr = std::unique_ptr; + + // Alias for inherited members from AsyncReader and AsyncWriter + // to keep compatibility. + using ReadCallback = AsyncReader::ReadCallback; + using WriteCallback = AsyncWriter::WriteCallback; + virtual void setReadCB(ReadCallback* callback) override = 0; + virtual ReadCallback* getReadCallback() const override = 0; + virtual void write(WriteCallback* callback, const void* buf, size_t bytes, + WriteFlags flags = WriteFlags::NONE) override = 0; + virtual void writev(WriteCallback* callback, const iovec* vec, size_t count, + WriteFlags flags = WriteFlags::NONE) override = 0; + virtual void writeChain(WriteCallback* callback, + std::unique_ptr&& buf, + WriteFlags flags = WriteFlags::NONE) override = 0; + /** + * The transport wrapper may wrap another transport. This returns the + * transport that is wrapped. It returns nullptr if there is no wrapped + * transport. + */ + virtual AsyncTransportWrapper* getWrappedTransport() { + return nullptr; + } }; } // folly