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.
data::v_io_size read Read data from socket.
data::v_io_size write Write data to socket.
void setNonBlocking Set socket for nonblocking I/O.
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(data::v_io_size maxToRead, data::v_io_size maxToWrite)

Socket::read

Read data from socket.

  • @param data - buffer to read data to.
  • @param count - buffer size.
  • @return - actual amount of data read from socket.

data::v_io_size read(void *data, data::v_io_size count) override

Socket::write

Write data to socket.

  • @param data - data to write to socket.
  • @param count - data size.
  • @return - actual amount of data written to socket.

data::v_io_size write(const void *data, data::v_io_size count) override

Socket::setNonBlocking

Set socket for nonblocking I/O.

  • @param nonBlocking - true for nonblocking.

void setNonBlocking(bool nonBlocking)

Socket::close

Close socket pipes.

void close()