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

#include <StreamSocket.h>

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

Public Member Functions

 StreamSocket ()
 
 StreamSocket (const SocketAddress &address)
 
 StreamSocket (SocketAddress::Family family)
 
 StreamSocket (const Socket &socket)
 
virtual ~StreamSocket ()
 
StreamSocketoperator= (const Socket &socket)
 Destroys the StreamSocket.
 
void connect (const SocketAddress &address)
 
void connect (const SocketAddress &address, const Poco::Timespan &timeout)
 
void connectNB (const SocketAddress &address)
 
void shutdownReceive ()
 
void shutdownSend ()
 Shuts down the receiving part of the socket connection.
 
void shutdown ()
 Shuts down the sending part of the socket connection.
 
int sendBytes (const void *buffer, int length, int flags=0)
 
int sendBytes (const SocketBufVec &buffer, int flags=0)
 
int sendBytes (Poco::FIFOBuffer &buffer)
 
int receiveBytes (void *buffer, int length, int flags=0)
 
int receiveBytes (SocketBufVec &buffer, int flags=0)
 
int receiveBytes (Poco::Buffer< char > &buffer, int flags=0, const Poco::Timespan &timeout=100000)
 
int receiveBytes (Poco::FIFOBuffer &buffer)
 
void sendUrgent (unsigned char data)
 
 StreamSocket (SocketImpl *pImpl)
 
- Public Member Functions inherited from Poco::Net::Socket
 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.
 

Private Types

enum  { BUFFER_SIZE = 1024 }
 

Friends

class ServerSocket
 
class SocketIOS
 

Additional Inherited Members

- Public Types inherited from Poco::Net::Socket
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>
 
- Static Public Member Functions inherited from Poco::Net::Socket
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 inherited from Poco::Net::Socket
 Socket (SocketImpl *pImpl)
 
poco_socket_t sockfd () const
 

Detailed Description

This class provides an interface to a TCP stream socket.

Definition at line 33 of file StreamSocket.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

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

The SocketImpl must be a StreamSocketImpl, otherwise an InvalidArgumentException will be thrown.

Enumerator
BUFFER_SIZE 

Definition at line 202 of file StreamSocket.h.

Constructor & Destructor Documentation

◆ StreamSocket() [1/5]

Poco::Net::StreamSocket::StreamSocket ( )

◆ StreamSocket() [2/5]

Poco::Net::StreamSocket::StreamSocket ( const SocketAddress & address)
explicit

Creates an unconnected stream socket.

Before sending or receiving data, the socket must be connected with a call to connect().

◆ StreamSocket() [3/5]

Poco::Net::StreamSocket::StreamSocket ( SocketAddress::Family family)
explicit

Creates a stream socket and connects it to the socket specified by address.

◆ StreamSocket() [4/5]

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

Creates an unconnected stream socket for the given address family.

This is useful if certain socket options (like send and receive buffer) sizes, that must be set before connecting the socket, will be set later on.

◆ ~StreamSocket()

virtual Poco::Net::StreamSocket::~StreamSocket ( )
virtual

Creates the StreamSocket with the SocketImpl from another socket. The SocketImpl must be a StreamSocketImpl, otherwise an InvalidArgumentException will be thrown.

◆ StreamSocket() [5/5]

Poco::Net::StreamSocket::StreamSocket ( SocketImpl * pImpl)

Sends one byte of urgent data through the socket.

The data is sent with the MSG_OOB flag.

The preferred way for a socket to receive urgent data is by enabling the SO_OOBINLINE option.

Member Function Documentation

◆ connect() [1/2]

void Poco::Net::StreamSocket::connect ( const SocketAddress & address)

Assignment operator.

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

◆ connect() [2/2]

void Poco::Net::StreamSocket::connect ( const SocketAddress & address,
const Poco::Timespan & timeout )

Initializes the socket and establishes a connection to the TCP server at the given address.

Can also be used for UDP sockets. In this case, no connection is established. Instead, incoming and outgoing packets are restricted to the specified address.

◆ connectNB()

void Poco::Net::StreamSocket::connectNB ( const SocketAddress & address)

Initializes the socket, sets the socket timeout and establishes a connection to the TCP server at the given address.

◆ operator=()

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

Destroys the StreamSocket.

◆ receiveBytes() [1/4]

int Poco::Net::StreamSocket::receiveBytes ( Poco::Buffer< char > & buffer,
int flags = 0,
const Poco::Timespan & timeout = 100000 )

Receives data from the socket and stores it in buffers.

Returns the number of bytes received.

The flags parameter can be used to pass system-defined flags for recv() like MSG_OOB, MSG_PEEK or MSG_WAITALL.

◆ receiveBytes() [2/4]

int Poco::Net::StreamSocket::receiveBytes ( Poco::FIFOBuffer & buffer)

Receives data from the socket and stores it in buffers.

Returns the number of bytes received.

The flags parameter can be used to pass system-defined flags for recv() like MSG_OOB, MSG_PEEK or MSG_WAITALL.

◆ receiveBytes() [3/4]

int Poco::Net::StreamSocket::receiveBytes ( SocketBufVec & buffer,
int flags = 0 )

Receives data from the socket and stores it in buffer. Up to length bytes are received.

Returns the number of bytes received. A return value of 0 means a graceful shutdown of the connection from the peer.

Throws a TimeoutException if a receive timeout has been set and nothing is received within that interval. Throws a NetException (or a subclass) in case of other errors.

The flags parameter can be used to pass system-defined flags for recv() like MSG_OOB, MSG_PEEK or MSG_WAITALL.

◆ receiveBytes() [4/4]

int Poco::Net::StreamSocket::receiveBytes ( void * buffer,
int length,
int flags = 0 )

Sends the contents of the given buffer through the socket. FIFOBuffer has writable/readable transition notifications which may be enabled to notify the caller when the buffer transitions between empty, partially full and full states.

Returns the number of bytes sent, which may be less than the number of bytes specified.

Certain socket implementations may also return a negative value denoting a certain condition.

The flags parameter can be used to pass system-defined flags for send() like MSG_OOB.

◆ sendBytes() [1/3]

int Poco::Net::StreamSocket::sendBytes ( const SocketBufVec & buffer,
int flags = 0 )

Sends the contents of the given buffer through the socket.

Returns the number of bytes sent, which may be less than the number of bytes specified.

Certain socket implementations may also return a negative value denoting a certain condition.

The flags parameter can be used to pass system-defined flags for send() like MSG_OOB.

◆ sendBytes() [2/3]

int Poco::Net::StreamSocket::sendBytes ( const void * buffer,
int length,
int flags = 0 )

Shuts down both the receiving and the sending part of the socket connection.

◆ sendBytes() [3/3]

int Poco::Net::StreamSocket::sendBytes ( Poco::FIFOBuffer & buffer)

Sends the contents of the given buffers through the socket.

Returns the number of bytes sent, which may be less than the number of bytes specified.

The flags parameter can be used to pass system-defined flags for send() like MSG_OOB.

◆ sendUrgent()

void Poco::Net::StreamSocket::sendUrgent ( unsigned char data)

Receives data from the socket and stores it in buffer. Up to length bytes are received. FIFOBuffer has writable/readable transition notifications which may be enabled to notify the caller when the buffer transitions between empty, partially full and full states.

Returns the number of bytes received. A return value of 0 means a graceful shutdown of the connection from the peer.

Throws a TimeoutException if a receive timeout has been set and nothing is received within that interval. Throws a NetException (or a subclass) in case of other errors.

◆ shutdown()

void Poco::Net::StreamSocket::shutdown ( )

Shuts down the sending part of the socket connection.

◆ shutdownReceive()

void Poco::Net::StreamSocket::shutdownReceive ( )

Initializes the socket and establishes a connection to the TCP server at the given address. Prior to opening the connection the socket is set to nonblocking mode.

◆ shutdownSend()

void Poco::Net::StreamSocket::shutdownSend ( )

Shuts down the receiving part of the socket connection.

Friends And Related Symbol Documentation

◆ ServerSocket

friend class ServerSocket
friend

Definition at line 207 of file StreamSocket.h.

◆ SocketIOS

friend class SocketIOS
friend

Definition at line 208 of file StreamSocket.h.


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