Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Net::Socket Class Reference

#include <Socket.h>

+ Inheritance diagram for Poco::Net::Socket:
+ Collaboration diagram for Poco::Net::Socket:

Public Types

enum  SelectMode { SELECT_READ = 1 , SELECT_WRITE = 2 , SELECT_ERROR = 4 }
 The mode argument to poll() and select(). More...
 
using BufVec = SocketBufVec
 
using SocketList = std::vector<Socket>
 

Public Member Functions

 Socket ()
 
 Socket (const Socket &socket)
 Creates an uninitialized socket.
 
Socketoperator= (const Socket &socket)
 
virtual ~Socket ()
 
bool operator== (const Socket &socket) const
 
bool operator!= (const Socket &socket) const
 
bool operator< (const Socket &socket) const
 
bool operator<= (const Socket &socket) const
 Compares the SocketImpl pointers.
 
bool operator> (const Socket &socket) const
 Compares the SocketImpl pointers.
 
bool operator>= (const Socket &socket) const
 Compares the SocketImpl pointers.
 
void close ()
 Compares the SocketImpl pointers.
 
bool poll (const Poco::Timespan &timeout, int mode) const
 
int available () const
 
void setSendBufferSize (int size)
 
int getSendBufferSize () const
 Sets the size of the send buffer.
 
void setReceiveBufferSize (int size)
 
int getReceiveBufferSize () const
 Sets the size of the receive buffer.
 
void setSendTimeout (const Poco::Timespan &timeout)
 
Poco::Timespan getSendTimeout () const
 Sets the send timeout for the socket.
 
void setReceiveTimeout (const Poco::Timespan &timeout)
 
Poco::Timespan getReceiveTimeout () const
 
void setOption (int level, int option, int value)
 
void setOption (int level, int option, unsigned value)
 
void setOption (int level, int option, unsigned char value)
 
void setOption (int level, int option, const Poco::Timespan &value)
 
void setOption (int level, int option, const IPAddress &value)
 
void getOption (int level, int option, int &value) const
 
void getOption (int level, int option, unsigned &value) const
 
void getOption (int level, int option, unsigned char &value) const
 
void getOption (int level, int option, Poco::Timespan &value) const
 
void getOption (int level, int option, IPAddress &value) const
 
void setLinger (bool on, int seconds)
 
void getLinger (bool &on, int &seconds) const
 Sets the value of the SO_LINGER socket option.
 
void setNoDelay (bool flag)
 Returns the value of the SO_LINGER socket option.
 
bool getNoDelay () const
 Sets the value of the TCP_NODELAY socket option.
 
void setKeepAlive (bool flag)
 Returns the value of the TCP_NODELAY socket option.
 
bool getKeepAlive () const
 Sets the value of the SO_KEEPALIVE socket option.
 
void setReuseAddress (bool flag)
 Returns the value of the SO_KEEPALIVE socket option.
 
bool getReuseAddress () const
 Sets the value of the SO_REUSEADDR socket option.
 
void setReusePort (bool flag)
 Returns the value of the SO_REUSEADDR socket option.
 
bool getReusePort () const
 
void setOOBInline (bool flag)
 
bool getOOBInline () const
 Sets the value of the SO_OOBINLINE socket option.
 
void setBlocking (bool flag)
 Returns the value of the SO_OOBINLINE socket option.
 
bool getBlocking () const
 
SocketAddress address () const
 
SocketAddress peerAddress () const
 Returns the IP address and port number of the socket.
 
SocketImplimpl () const
 Returns the IP address and port number of the peer socket.
 
bool secure () const
 Returns the SocketImpl for this socket.
 
void init (int af)
 Returns true if the system supports IPv6.
 

Static Public Member Functions

static int select (SocketList &readList, SocketList &writeList, SocketList &exceptList, const Poco::Timespan &timeout)
 Closes the socket.
 
static bool supportsIPv4 ()
 
static bool supportsIPv6 ()
 Returns true if the system supports IPv4.
 
static SocketBuf makeBuffer (void *buffer, std::size_t length)
 
static SocketBufVec makeBufVec (std::size_t size, std::size_t bufLen)
 
static void destroyBufVec (SocketBufVec &buf)
 
static SocketBufVec makeBufVec (const std::vector< char * > &vec)
 
static SocketBufVec makeBufVec (const std::vector< std::string > &vec)
 

Protected Member Functions

 Socket (SocketImpl *pImpl)
 
poco_socket_t sockfd () const
 

Private Attributes

SocketImpl_pImpl
 Returns the socket descriptor for this socket.
 

Detailed Description

Socket is the common base class for StreamSocket, ServerSocket, DatagramSocket and other socket classes.

It provides operations common to all socket types.

Definition at line 30 of file Socket.h.

Member Typedef Documentation

◆ BufVec

Definition at line 38 of file Socket.h.

◆ SocketList

using Poco::Net::Socket::SocketList = std::vector<Socket>

Definition at line 48 of file Socket.h.

Member Enumeration Documentation

◆ SelectMode

The mode argument to poll() and select().

Enumerator
SELECT_READ 
SELECT_WRITE 
SELECT_ERROR 

Definition at line 40 of file Socket.h.

Constructor & Destructor Documentation

◆ Socket() [1/3]

Poco::Net::Socket::Socket ( )

◆ Socket() [2/3]

Poco::Net::Socket::Socket ( const Socket & socket)

Creates an uninitialized socket.

◆ ~Socket()

virtual Poco::Net::Socket::~Socket ( )
virtual

Assignment operator.

Releases the socket's SocketImpl and attaches the SocketImpl from the other socket and increments the reference count of the SocketImpl.

◆ Socket() [3/3]

Poco::Net::Socket::Socket ( SocketImpl * pImpl)
protected

Creates and returns a vector of requested size, with buffers pointing to the supplied data (so, vec must remain available at the time of use) and lengths set accordingly. Note:: this function is not suitable for creation of buffers used for writing (ie. reading from socket into buffers).

Member Function Documentation

◆ address()

SocketAddress Poco::Net::Socket::address ( ) const
inline

Returns the blocking mode of the socket. This method will only work if the blocking modes of the socket are changed via the setBlocking method!

Definition at line 628 of file Socket.h.

+ Here is the call graph for this function:

◆ available()

int Poco::Net::Socket::available ( ) const
inline

Determines the status of the socket, using a call to poll() or select().

The mode argument is constructed by combining the values of the SelectMode enumeration.

Returns true if the next operation corresponding to mode will not block, false otherwise.

Definition at line 418 of file Socket.h.

+ Here is the call graph for this function:

◆ close()

void Poco::Net::Socket::close ( )
inline

Compares the SocketImpl pointers.

Definition at line 406 of file Socket.h.

+ Here is the call graph for this function:

◆ destroyBufVec()

static void Poco::Net::Socket::destroyBufVec ( SocketBufVec & buf)
static

Creates and returns a vector of requested size, with allocated buffers and lengths set accordingly. This utility function works well when all buffers are of same size.

◆ getBlocking()

bool Poco::Net::Socket::getBlocking ( ) const
inline

Sets the socket in blocking mode if flag is true, disables blocking mode if flag is false.

Definition at line 610 of file Socket.h.

+ Here is the call graph for this function:

◆ getKeepAlive()

bool Poco::Net::Socket::getKeepAlive ( ) const
inline

Sets the value of the SO_KEEPALIVE socket option.

Definition at line 562 of file Socket.h.

+ Here is the call graph for this function:

◆ getLinger()

void Poco::Net::Socket::getLinger ( bool & on,
int & seconds ) const
inline

Sets the value of the SO_LINGER socket option.

Definition at line 538 of file Socket.h.

+ Here is the call graph for this function:

◆ getNoDelay()

bool Poco::Net::Socket::getNoDelay ( ) const
inline

Sets the value of the TCP_NODELAY socket option.

Definition at line 550 of file Socket.h.

+ Here is the call graph for this function:

◆ getOOBInline()

bool Poco::Net::Socket::getOOBInline ( ) const
inline

Sets the value of the SO_OOBINLINE socket option.

Definition at line 598 of file Socket.h.

+ Here is the call graph for this function:

◆ getOption() [1/5]

void Poco::Net::Socket::getOption ( int level,
int option,
int & value ) const
inline

Sets the socket option specified by level and option to the given time value.

Definition at line 502 of file Socket.h.

+ Here is the call graph for this function:

◆ getOption() [2/5]

void Poco::Net::Socket::getOption ( int level,
int option,
IPAddress & value ) const
inline

Returns the value of the socket option specified by level and option.

Definition at line 526 of file Socket.h.

+ Here is the call graph for this function:

◆ getOption() [3/5]

void Poco::Net::Socket::getOption ( int level,
int option,
Poco::Timespan & value ) const
inline

Returns the value of the socket option specified by level and option.

Definition at line 520 of file Socket.h.

+ Here is the call graph for this function:

◆ getOption() [4/5]

void Poco::Net::Socket::getOption ( int level,
int option,
unsigned & value ) const
inline

Returns the value of the socket option specified by level and option.

Definition at line 508 of file Socket.h.

+ Here is the call graph for this function:

◆ getOption() [5/5]

void Poco::Net::Socket::getOption ( int level,
int option,
unsigned char & value ) const
inline

Returns the value of the socket option specified by level and option.

Definition at line 514 of file Socket.h.

+ Here is the call graph for this function:

◆ getReceiveBufferSize()

int Poco::Net::Socket::getReceiveBufferSize ( ) const
inline

Sets the size of the receive buffer.

Definition at line 442 of file Socket.h.

+ Here is the call graph for this function:

◆ getReceiveTimeout()

Poco::Timespan Poco::Net::Socket::getReceiveTimeout ( ) const
inline

Sets the send timeout for the socket.

On systems that do not support SO_RCVTIMEO, a workaround using poll() is provided.

Definition at line 466 of file Socket.h.

+ Here is the call graph for this function:

◆ getReuseAddress()

bool Poco::Net::Socket::getReuseAddress ( ) const
inline

Sets the value of the SO_REUSEADDR socket option.

Definition at line 574 of file Socket.h.

+ Here is the call graph for this function:

◆ getReusePort()

bool Poco::Net::Socket::getReusePort ( ) const
inline

Sets the value of the SO_REUSEPORT socket option. Does nothing if the socket implementation does not support SO_REUSEPORT.

Definition at line 586 of file Socket.h.

+ Here is the call graph for this function:

◆ getSendBufferSize()

int Poco::Net::Socket::getSendBufferSize ( ) const
inline

Sets the size of the send buffer.

Definition at line 430 of file Socket.h.

+ Here is the call graph for this function:

◆ getSendTimeout()

Poco::Timespan Poco::Net::Socket::getSendTimeout ( ) const
inline

Sets the send timeout for the socket.

Definition at line 454 of file Socket.h.

+ Here is the call graph for this function:

◆ impl()

SocketImpl * Poco::Net::Socket::impl ( ) const
inline

Returns the IP address and port number of the peer socket.

Definition at line 616 of file Socket.h.

◆ init()

void Poco::Net::Socket::init ( int af)
inline

Returns true if the system supports IPv6.

Definition at line 662 of file Socket.h.

+ Here is the call graph for this function:

◆ makeBuffer()

static SocketBuf Poco::Net::Socket::makeBuffer ( void * buffer,
std::size_t length )
static

Creates the underlying system socket for the given address family.

Normally, this method should not be called directly, as socket creation will be handled automatically. There are a few situations where calling this method after creation of the Socket object makes sense. One example is setting a socket option before calling bind() on a ServerSocket.

◆ makeBufVec() [1/3]

static SocketBufVec Poco::Net::Socket::makeBufVec ( const std::vector< char * > & vec)
static

Releases the memory pointed to by vector members and shrinks the vector to size 0. The vector must be created by makeBufVec(size_t, size_t).

◆ makeBufVec() [2/3]

static SocketBufVec Poco::Net::Socket::makeBufVec ( const std::vector< std::string > & vec)
static

Creates and returns a vector of requested size, with buffers pointing to the supplied data (so, vec must remain available at the time of use) and lengths set accordingly. Notes:

  • data length is determined using strlen, so this function is not meant to be used with binary data.
  • if the returned buffer is used for read operations (ie. operations that write to the bufer), pointing to string literals will result in undefined behavior, in best case an I/O error and subsequent exception

◆ makeBufVec() [3/3]

static SocketBufVec Poco::Net::Socket::makeBufVec ( std::size_t size,
std::size_t bufLen )
static

Creates and returns buffer. Suitable for creating the appropriate buffer for the platform.

◆ operator!=()

bool Poco::Net::Socket::operator!= ( const Socket & socket) const
inline

Returns true if both sockets share the same SocketImpl, false otherwise.

Definition at line 376 of file Socket.h.

◆ operator<()

bool Poco::Net::Socket::operator< ( const Socket & socket) const
inline

Returns false if both sockets share the same SocketImpl, true otherwise.

Definition at line 382 of file Socket.h.

◆ operator<=()

bool Poco::Net::Socket::operator<= ( const Socket & socket) const
inline

Compares the SocketImpl pointers.

Definition at line 388 of file Socket.h.

◆ operator=()

Socket & Poco::Net::Socket::operator= ( const Socket & socket)

Copy constructor.

Attaches the SocketImpl from the other socket and increments the reference count of the SocketImpl.

◆ operator==()

bool Poco::Net::Socket::operator== ( const Socket & socket) const
inline

Destroys the Socket and releases the SocketImpl.

Definition at line 370 of file Socket.h.

◆ operator>()

bool Poco::Net::Socket::operator> ( const Socket & socket) const
inline

Compares the SocketImpl pointers.

Definition at line 394 of file Socket.h.

◆ operator>=()

bool Poco::Net::Socket::operator>= ( const Socket & socket) const
inline

Compares the SocketImpl pointers.

Definition at line 400 of file Socket.h.

◆ peerAddress()

SocketAddress Poco::Net::Socket::peerAddress ( ) const
inline

Returns the IP address and port number of the socket.

Definition at line 634 of file Socket.h.

+ Here is the call graph for this function:

◆ poll()

bool Poco::Net::Socket::poll ( const Poco::Timespan & timeout,
int mode ) const
inline

Determines the status of one or more sockets, using a call to select().

ReadList contains the list of sockets which should be checked for readability.

WriteList contains the list of sockets which should be checked for writeability.

ExceptList contains a list of sockets which should be checked for a pending error.

Returns the number of sockets ready.

After return,

  • readList contains those sockets ready for reading,
  • writeList contains those sockets ready for writing,
  • exceptList contains those sockets with a pending error.

If the total number of sockets passed in readList, writeList and exceptList is zero, select() will return immediately and the return value will be 0.

If one of the sockets passed to select() is closed while select() runs, select will return immediately. However, the closed socket will not be included in any list. In this case, the return value may be greater than the sum of all sockets in all list.

Definition at line 412 of file Socket.h.

+ Here is the call graph for this function:

◆ secure()

bool Poco::Net::Socket::secure ( ) const
inline

Returns the SocketImpl for this socket.

Definition at line 640 of file Socket.h.

+ Here is the call graph for this function:

◆ select()

static int Poco::Net::Socket::select ( SocketList & readList,
SocketList & writeList,
SocketList & exceptList,
const Poco::Timespan & timeout )
static

Closes the socket.

◆ setBlocking()

void Poco::Net::Socket::setBlocking ( bool flag)
inline

Returns the value of the SO_OOBINLINE socket option.

Definition at line 604 of file Socket.h.

+ Here is the call graph for this function:

◆ setKeepAlive()

void Poco::Net::Socket::setKeepAlive ( bool flag)
inline

Returns the value of the TCP_NODELAY socket option.

Definition at line 556 of file Socket.h.

+ Here is the call graph for this function:

◆ setLinger()

void Poco::Net::Socket::setLinger ( bool on,
int seconds )
inline

Returns the value of the socket option specified by level and option.

Definition at line 532 of file Socket.h.

+ Here is the call graph for this function:

◆ setNoDelay()

void Poco::Net::Socket::setNoDelay ( bool flag)
inline

Returns the value of the SO_LINGER socket option.

Definition at line 544 of file Socket.h.

+ Here is the call graph for this function:

◆ setOOBInline()

void Poco::Net::Socket::setOOBInline ( bool flag)
inline

Returns the value of the SO_REUSEPORT socket option.

Returns false if the socket implementation does not support SO_REUSEPORT.

Definition at line 592 of file Socket.h.

+ Here is the call graph for this function:

◆ setOption() [1/5]

void Poco::Net::Socket::setOption ( int level,
int option,
const IPAddress & value )
inline

Sets the socket option specified by level and option to the given time value.

Definition at line 496 of file Socket.h.

+ Here is the call graph for this function:

◆ setOption() [2/5]

void Poco::Net::Socket::setOption ( int level,
int option,
const Poco::Timespan & value )
inline

Sets the socket option specified by level and option to the given integer value.

Definition at line 490 of file Socket.h.

+ Here is the call graph for this function:

◆ setOption() [3/5]

void Poco::Net::Socket::setOption ( int level,
int option,
int value )
inline

Returns the receive timeout for the socket.

The returned timeout may be different than the timeout previously set with getReceiveTimeout(), as the system is free to adjust the value.

Definition at line 472 of file Socket.h.

+ Here is the call graph for this function:

◆ setOption() [4/5]

void Poco::Net::Socket::setOption ( int level,
int option,
unsigned char value )
inline

Sets the socket option specified by level and option to the given integer value.

Definition at line 484 of file Socket.h.

+ Here is the call graph for this function:

◆ setOption() [5/5]

void Poco::Net::Socket::setOption ( int level,
int option,
unsigned value )
inline

Sets the socket option specified by level and option to the given integer value.

Definition at line 478 of file Socket.h.

+ Here is the call graph for this function:

◆ setReceiveBufferSize()

void Poco::Net::Socket::setReceiveBufferSize ( int size)
inline

Returns the size of the send buffer.

The returned value may be different than the value previously set with setSendBufferSize(), as the system is free to adjust the value.

Definition at line 436 of file Socket.h.

+ Here is the call graph for this function:

◆ setReceiveTimeout()

void Poco::Net::Socket::setReceiveTimeout ( const Poco::Timespan & timeout)
inline

Returns the send timeout for the socket.

The returned timeout may be different than the timeout previously set with setSendTimeout(), as the system is free to adjust the value.

Definition at line 460 of file Socket.h.

+ Here is the call graph for this function:

◆ setReuseAddress()

void Poco::Net::Socket::setReuseAddress ( bool flag)
inline

Returns the value of the SO_KEEPALIVE socket option.

Definition at line 568 of file Socket.h.

+ Here is the call graph for this function:

◆ setReusePort()

void Poco::Net::Socket::setReusePort ( bool flag)
inline

Returns the value of the SO_REUSEADDR socket option.

Definition at line 580 of file Socket.h.

+ Here is the call graph for this function:

◆ setSendBufferSize()

void Poco::Net::Socket::setSendBufferSize ( int size)
inline

Returns the number of bytes available that can be read without causing the socket to block.

Definition at line 424 of file Socket.h.

+ Here is the call graph for this function:

◆ setSendTimeout()

void Poco::Net::Socket::setSendTimeout ( const Poco::Timespan & timeout)
inline

Returns the size of the receive buffer.

The returned value may be different than the value previously set with setReceiveBufferSize(), as the system is free to adjust the value.

Definition at line 448 of file Socket.h.

+ Here is the call graph for this function:

◆ sockfd()

poco_socket_t Poco::Net::Socket::sockfd ( ) const
inlineprotected

Creates the Socket and attaches the given SocketImpl. The socket takes ownership of the SocketImpl.

Definition at line 622 of file Socket.h.

+ Here is the call graph for this function:

◆ supportsIPv4()

bool Poco::Net::Socket::supportsIPv4 ( )
inlinestatic

Returns true iff the socket's connection is secure (using SSL or TLS).

Definition at line 646 of file Socket.h.

◆ supportsIPv6()

bool Poco::Net::Socket::supportsIPv6 ( )
inlinestatic

Returns true if the system supports IPv4.

Definition at line 652 of file Socket.h.

Member Data Documentation

◆ _pImpl

SocketImpl* Poco::Net::Socket::_pImpl
private

Returns the socket descriptor for this socket.

Definition at line 363 of file Socket.h.


The documentation for this class was generated from the following file: