# Socket.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/network/virtual_/Socket.hpp"
# Socket
Virtual socket implementation. Can be used as a bidirectional data transfer between different threads of the same process.
Under the hood it uses a pair of oatpp::network::virtual_::Pipe. One to write data to, and one to read data from. Extends oatpp::base::Countable and oatpp::data::stream::IOStream.
namespace oatpp { namespace network { namespace virtual_ {
class Socket : public oatpp::data::stream::IOStream, public oatpp::base::Countable {}
}}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | Socket | Constructor. |
std::shared_ptr<Socket> | createShared | Create shared socket. |
[none] | ~Socket | Virtual destructor. Close corresponding pipes. |
void | setMaxAvailableToReadWrtie | Limit the available amount of bytes to read from socket and limit the available amount of bytes to write to socket. |
v_io_size | read | Read data from socket. |
v_io_size | write | Write data to socket. |
void | setOutputStreamIOMode | Set OutputStream I/O mode. |
oatpp::data::stream::IOMode | getOutputStreamIOMode | Set OutputStream I/O mode. |
void | setInputStreamIOMode | Set InputStream I/O mode. |
oatpp::data::stream::IOMode | getInputStreamIOMode | Get InputStream I/O mode. |
oatpp::data::stream::Context& | getOutputStreamContext | Get output stream context. |
oatpp::data::stream::Context& | getInputStreamContext | Get input stream context. |
void | close | Close socket pipes. |
# Socket::Socket
Constructor.
- @param pipeIn - pipe to read data from.
- @param pipeOut - pipe to write data to.
Socket(const std::shared_ptr<Pipe>& pipeIn, const std::shared_ptr<Pipe>& pipeOut)
# Socket::createShared
Create shared socket.
- @param pipeIn - pipe to read data from.
- @param pipeOut - pipe to write data to.
- @return -
std::shared_ptr
to Socket.
static std::shared_ptr<Socket> createShared(const std::shared_ptr<Pipe>& pipeIn, const std::shared_ptr<Pipe>& pipeOut)
# Socket::~Socket
Virtual destructor. Close corresponding pipes.
~Socket()
# Socket::setMaxAvailableToReadWrtie
Limit the available amount of bytes to read from socket and limit the available amount of bytes to write to socket.
This method is used for testing purposes only.
- @param maxToRead - maximum available amount of bytes to read.
- @param maxToWrite - maximum available amount of bytes to write.
void setMaxAvailableToReadWrtie(v_io_size maxToRead, v_io_size maxToWrite)
# Socket::read
Read data from socket.
- @param data - buffer to read data to.
- @param count - buffer size.
- @param action - async specific action. If action is NOT oatpp::async::Action::TYPE_NONE, then caller MUST return this action on coroutine iteration.
- @return - actual amount of data read from socket.
v_io_size read(void *data, v_buff_size count, async::Action& action) override
# Socket::write
Write data to socket.
- @param data - data to write to socket.
- @param count - data size.
- @param action - async specific action. If action is NOT oatpp::async::Action::TYPE_NONE, then caller MUST return this action on coroutine iteration.
- @return - actual amount of data written to socket.
v_io_size write(const void *data, v_buff_size count, async::Action& action) override
# Socket::setOutputStreamIOMode
Set OutputStream I/O mode.
- @param ioMode
void setOutputStreamIOMode(oatpp::data::stream::IOMode ioMode) override
# Socket::getOutputStreamIOMode
Set OutputStream I/O mode.
- @return
oatpp::data::stream::IOMode getOutputStreamIOMode() override
# Socket::setInputStreamIOMode
Set InputStream I/O mode.
- @param ioMode
void setInputStreamIOMode(oatpp::data::stream::IOMode ioMode) override
# Socket::getInputStreamIOMode
Get InputStream I/O mode.
- @return
oatpp::data::stream::IOMode getInputStreamIOMode() override
# Socket::getOutputStreamContext
Get output stream context.
- @return
oatpp::data::stream::Context& getOutputStreamContext() override
# Socket::getInputStreamContext
Get input stream context.
- @return
oatpp::data::stream::Context& getInputStreamContext() override
# Socket::close
Close socket pipes.
void close()