Ark Server API (ASE) - Wiki
|
#include <SocketImpl.h>
Public Types | |
enum | SelectMode { SELECT_READ = 1 , SELECT_WRITE = 2 , SELECT_ERROR = 4 } |
Public Member Functions | |
virtual SocketImpl * | acceptConnection (SocketAddress &clientAddr) |
virtual void | connect (const SocketAddress &address) |
virtual void | connect (const SocketAddress &address, const Poco::Timespan &timeout) |
virtual void | connectNB (const SocketAddress &address) |
virtual void | bind (const SocketAddress &address, bool reuseAddress=false) |
virtual void | bind (const SocketAddress &address, bool reuseAddress, bool reusePort) |
virtual void | bind6 (const SocketAddress &address, bool reuseAddress=false, bool ipV6Only=false) |
virtual void | bind6 (const SocketAddress &address, bool reuseAddress, bool reusePort, bool ipV6Only) |
virtual void | listen (int backlog=64) |
virtual void | close () |
virtual void | shutdownReceive () |
Close the socket. | |
virtual void | shutdownSend () |
Shuts down the receiving part of the socket connection. | |
virtual void | shutdown () |
Shuts down the sending part of the socket connection. | |
virtual int | sendBytes (const void *buffer, int length, int flags=0) |
virtual int | sendBytes (const SocketBufVec &buffers, int flags=0) |
virtual int | receiveBytes (void *buffer, int length, int flags=0) |
virtual int | receiveBytes (SocketBufVec &buffers, int flags=0) |
virtual int | receiveBytes (Poco::Buffer< char > &buffer, int flags=0, const Poco::Timespan &timeout=100000) |
virtual int | sendTo (const void *buffer, int length, const SocketAddress &address, int flags=0) |
virtual int | sendTo (const SocketBufVec &buffers, const SocketAddress &address, int flags=0) |
int | receiveFrom (void *buffer, int length, struct sockaddr **ppSA, poco_socklen_t **ppSALen, int flags=0) |
virtual int | receiveFrom (void *buffer, int length, SocketAddress &address, int flags=0) |
virtual int | receiveFrom (SocketBufVec &buffers, SocketAddress &address, int flags=0) |
int | receiveFrom (SocketBufVec &buffers, struct sockaddr **ppSA, poco_socklen_t **ppSALen, int flags) |
virtual void | sendUrgent (unsigned char data) |
virtual int | available () |
virtual bool | poll (const Poco::Timespan &timeout, int mode) |
virtual void | setSendBufferSize (int size) |
virtual int | getSendBufferSize () |
Sets the size of the send buffer. | |
virtual void | setReceiveBufferSize (int size) |
virtual int | getReceiveBufferSize () |
Sets the size of the receive buffer. | |
virtual void | setSendTimeout (const Poco::Timespan &timeout) |
virtual Poco::Timespan | getSendTimeout () |
Sets the send timeout for the socket. | |
virtual void | setReceiveTimeout (const Poco::Timespan &timeout) |
virtual Poco::Timespan | getReceiveTimeout () |
virtual SocketAddress | address () |
virtual SocketAddress | peerAddress () |
Returns the IP address and port number of the socket. | |
void | setOption (int level, int option, int value) |
Returns the IP address and port number of the peer socket. | |
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) |
virtual void | setRawOption (int level, int option, const void *value, poco_socklen_t length) |
void | getOption (int level, int option, int &value) |
void | getOption (int level, int option, unsigned &value) |
void | getOption (int level, int option, unsigned char &value) |
void | getOption (int level, int option, Poco::Timespan &value) |
void | getOption (int level, int option, IPAddress &value) |
virtual void | getRawOption (int level, int option, void *value, poco_socklen_t &length) |
void | setLinger (bool on, int seconds) |
void | getLinger (bool &on, int &seconds) |
Sets the value of the SO_LINGER socket option. | |
void | setNoDelay (bool flag) |
Returns the value of the SO_LINGER socket option. | |
bool | getNoDelay () |
Sets the value of the TCP_NODELAY socket option. | |
void | setKeepAlive (bool flag) |
Returns the value of the TCP_NODELAY socket option. | |
bool | getKeepAlive () |
Sets the value of the SO_KEEPALIVE socket option. | |
void | setReuseAddress (bool flag) |
Returns the value of the SO_KEEPALIVE socket option. | |
bool | getReuseAddress () |
Sets the value of the SO_REUSEADDR socket option. | |
void | setReusePort (bool flag) |
Returns the value of the SO_REUSEADDR socket option. | |
bool | getReusePort () |
void | setOOBInline (bool flag) |
bool | getOOBInline () |
Sets the value of the SO_OOBINLINE socket option. | |
void | setBroadcast (bool flag) |
Returns the value of the SO_OOBINLINE socket option. | |
bool | getBroadcast () |
Sets the value of the SO_BROADCAST socket option. | |
virtual void | setBlocking (bool flag) |
Returns the value of the SO_BROADCAST socket option. | |
virtual bool | getBlocking () const |
virtual bool | secure () const |
int | socketError () |
poco_socket_t | sockfd () const |
Returns the value of the SO_ERROR socket option. | |
void | ioctl (poco_ioctl_request_t request, int &arg) |
void | ioctl (poco_ioctl_request_t request, void *arg) |
A wrapper for the ioctl system call. | |
bool | initialized () const |
A wrapper for the ioctl system call. | |
Public Member Functions inherited from Poco::RefCountedObject | |
RefCountedObject () | |
void | duplicate () const |
void | release () const noexcept |
Increments the object's reference count. | |
int | referenceCount () const |
Protected Member Functions | |
SocketImpl () | |
Returns true iff the underlying socket is initialized. | |
SocketImpl (poco_socket_t sockfd) | |
Creates a SocketImpl. | |
virtual | ~SocketImpl () |
Creates a SocketImpl using the given native socket. | |
virtual void | init (int af) |
void | initSocket (int af, int type, int proto=0) |
void | reset (poco_socket_t fd=POCO_INVALID_SOCKET) |
void | checkBrokenTimeout (SelectMode mode) |
Allows subclasses to set the socket manually, iff no valid socket is set yet. | |
Protected Member Functions inherited from Poco::RefCountedObject | |
virtual | ~RefCountedObject () |
Returns the reference count. | |
Static Protected Member Functions | |
static int | lastError () |
static void | error () |
Returns the last error code. | |
static void | error (const std::string &arg) |
Throws an appropriate exception for the last error. | |
static void | error (int code) |
Throws an appropriate exception for the last error. | |
static void | error (int code, const std::string &arg) |
Throws an appropriate exception for the given error code. | |
Private Member Functions | |
SocketImpl (const SocketImpl &) | |
Throws an appropriate exception for the given error code. | |
SocketImpl & | operator= (const SocketImpl &) |
Private Attributes | |
poco_socket_t | _sockfd |
Poco::Timespan | _recvTimeout |
Poco::Timespan | _sndTimeout |
bool | _blocking |
bool | _isBrokenTimeout |
Friends | |
class | Socket |
class | SecureSocketImpl |
class | PollSetImpl |
This class encapsulates the Berkeley sockets API.
Subclasses implement specific socket types like stream or datagram sockets. You should not create any instances of this class.
Definition at line 33 of file SocketImpl.h.
Enumerator | |
---|---|
SELECT_READ | |
SELECT_WRITE | |
SELECT_ERROR |
Definition at line 42 of file SocketImpl.h.
|
protected |
Returns true iff the underlying socket is initialized.
|
protected |
Creates a SocketImpl.
|
protectedvirtual |
Creates a SocketImpl using the given native socket.
|
private |
Throws an appropriate exception for the given error code.
|
virtual |
|
virtual |
Returns the receive timeout for the socket.
The returned timeout may be different than the timeout previously set with setReceiveTimeout(), as the system is free to adjust the value.
|
virtual |
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.
|
virtual |
Bind a local address to the socket.
This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.
If reuseAddress is true, sets the SO_REUSEADDR socket option.
|
virtual |
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.
|
virtual |
Bind a local IPv6 address to the socket.
This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.
If reuseAddress is true, sets the SO_REUSEADDR socket option.
The given address must be an IPv6 address. The IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket according to the ipV6Only parameter.
If the library has not been built with IPv6 support, a Poco::NotImplementedException will be thrown.
|
virtual |
Bind a local address to the socket.
This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.
If reuseAddress is true, sets the SO_REUSEADDR socket option.
If reusePort is true, sets the SO_REUSEPORT socket option.
|
protected |
Allows subclasses to set the socket manually, iff no valid socket is set yet.
|
virtual |
Puts the socket into listening state.
The socket becomes a passive socket that can accept incoming connection requests.
The backlog argument specifies the maximum number of connections that can be queued for this socket.
|
virtual |
Get the next completed connection from the socket's completed connection queue.
If the queue is empty, waits until a connection request completes.
Returns a new TCP socket for the connection with the client.
The client socket's address is returned in clientAddr.
|
virtual |
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.
|
virtual |
Initializes the socket, sets the socket timeout and establishes a connection to the TCP server at the given address.
|
staticprotected |
Returns the last error code.
|
staticprotected |
Throws an appropriate exception for the last error.
|
staticprotected |
Throws an appropriate exception for the last error.
|
staticprotected |
Throws an appropriate exception for the given error code.
|
inlinevirtual |
Sets the socket in blocking mode if flag is true, disables blocking mode if flag is false.
Definition at line 551 of file SocketImpl.h.
bool Poco::Net::SocketImpl::getBroadcast | ( | ) |
Sets the value of the SO_BROADCAST socket option.
bool Poco::Net::SocketImpl::getKeepAlive | ( | ) |
Sets the value of the SO_KEEPALIVE socket option.
void Poco::Net::SocketImpl::getLinger | ( | bool & | on, |
int & | seconds ) |
Sets the value of the SO_LINGER socket option.
bool Poco::Net::SocketImpl::getNoDelay | ( | ) |
Sets the value of the TCP_NODELAY socket option.
bool Poco::Net::SocketImpl::getOOBInline | ( | ) |
Sets the value of the SO_OOBINLINE socket option.
void Poco::Net::SocketImpl::getOption | ( | int | level, |
int | option, | ||
int & | value ) |
Sets the socket option specified by level and option to the given time value.
void Poco::Net::SocketImpl::getOption | ( | int | level, |
int | option, | ||
IPAddress & | value ) |
Returns the value of the socket option specified by level and option.
void Poco::Net::SocketImpl::getOption | ( | int | level, |
int | option, | ||
Poco::Timespan & | value ) |
Returns the value of the socket option specified by level and option.
void Poco::Net::SocketImpl::getOption | ( | int | level, |
int | option, | ||
unsigned & | value ) |
Returns the value of the socket option specified by level and option.
void Poco::Net::SocketImpl::getOption | ( | int | level, |
int | option, | ||
unsigned char & | value ) |
Returns the value of the socket option specified by level and option.
|
virtual |
Returns the value of the socket option specified by level and option.
|
virtual |
Sets the size of the receive buffer.
|
virtual |
Sets the receive timeout for the socket.
On systems that do not support SO_RCVTIMEO, a workaround using poll() is provided.
bool Poco::Net::SocketImpl::getReuseAddress | ( | ) |
Sets the value of the SO_REUSEADDR socket option.
bool Poco::Net::SocketImpl::getReusePort | ( | ) |
Sets the value of the SO_REUSEPORT socket option. Does nothing if the socket implementation does not support SO_REUSEPORT.
|
virtual |
Sets the size of the send buffer.
|
virtual |
Sets the send timeout for the socket.
|
protectedvirtual |
Destroys the SocketImpl. Closes the socket if it is still open.
|
inline |
A wrapper for the ioctl system call.
Definition at line 535 of file SocketImpl.h.
|
protected |
Creates the underlying native socket.
Subclasses must implement this method so that it calls initSocket() with the appropriate arguments.
The default implementation creates a stream socket.
void Poco::Net::SocketImpl::ioctl | ( | poco_ioctl_request_t | request, |
int & | arg ) |
Returns the socket descriptor for the underlying native socket.
void Poco::Net::SocketImpl::ioctl | ( | poco_ioctl_request_t | request, |
void * | arg ) |
A wrapper for the ioctl system call.
|
inlinestaticprotected |
Definition at line 541 of file SocketImpl.h.
|
virtual |
Bind a local IPv6 address to the socket.
This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.
If reuseAddress is true, sets the SO_REUSEADDR socket option.
If reusePort is true, sets the SO_REUSEPORT socket option.
The given address must be an IPv6 address. The IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket according to the ipV6Only parameter.
If the library has not been built with IPv6 support, a Poco::NotImplementedException will be thrown.
|
private |
|
virtual |
Returns the IP address and port number of the socket.
|
virtual |
Returns the number of bytes available that can be read without causing the socket to block.
|
virtual |
Receives data from the socket and stores it in buffers.
Returns the number of bytes received.
Always returns zero for platforms where not implemented.
|
virtual |
Receives data from the socket and stores it in buffer. Up to length bytes are received.
Returns the number of bytes received.
Certain socket implementations may also return a negative value denoting a certain condition.
|
virtual |
Receives data from the socket and stores it in buffers.
Returns the number of bytes received.
Always returns zero for platforms where not implemented.
|
virtual |
Receives data from the socket and stores it in buffer. Up to length bytes are received. Stores the address of the sender in address.
Returns the number of bytes received.
int Poco::Net::SocketImpl::receiveFrom | ( | SocketBufVec & | buffers, |
struct sockaddr ** | ppSA, | ||
poco_socklen_t ** | ppSALen, | ||
int | flags ) |
Receives data from the socket and stores it in buffers. Stores the address of the sender in address.
Returns the number of bytes received.
Always returns zero for platforms where not implemented.
|
virtual |
Receives data from the socket and stores it in buffer. Up to length bytes are received. Stores the native address of the sender in ppSA, and the length of native address in ppSALen.
Returns the number of bytes received.
int Poco::Net::SocketImpl::receiveFrom | ( | void * | buffer, |
int | length, | ||
struct sockaddr ** | ppSA, | ||
poco_socklen_t ** | ppSALen, | ||
int | flags = 0 ) |
Sends the contents of the buffers through the socket to the given address.
Returns the number of bytes sent, which may be less than the number of bytes specified.
Always returns zero for platforms where not implemented.
|
protected |
Creates the underlying native socket.
The first argument, af, specifies the address family used by the socket, which should be either AF_INET or AF_INET6.
The second argument, type, specifies the type of the socket, which can be one of SOCK_STREAM, SOCK_DGRAM or SOCK_RAW.
The third argument, proto, is normally set to 0, except for raw sockets.
|
virtual |
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!
|
virtual |
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.
|
virtual |
Shuts down both the receiving and the sending part of the socket connection.
|
virtual |
Sends the contents of the given buffer through the socket to the given address.
Returns the number of bytes sent, which may be less than the number of bytes specified.
|
virtual |
Receives data from the socket and stores it in the buffer. If needed, the buffer will be resized to accomodate the data. Note that this function may impose additional performance penalties due to the check for the available amount of data.
Returns the number of bytes received.
|
virtual |
Receives data from the socket and stores it in buffers. Stores the native address of the sender in ppSA, and the length of native address in ppSALen.
Returns the number of bytes received.
|
virtual |
Returns the value of the SO_BROADCAST socket option.
void Poco::Net::SocketImpl::setBroadcast | ( | bool | flag | ) |
Returns the value of the SO_OOBINLINE socket option.
void Poco::Net::SocketImpl::setKeepAlive | ( | bool | flag | ) |
Returns the value of the TCP_NODELAY socket option.
void Poco::Net::SocketImpl::setLinger | ( | bool | on, |
int | seconds ) |
Returns the value of the socket option specified by level and option.
void Poco::Net::SocketImpl::setNoDelay | ( | bool | flag | ) |
Returns the value of the SO_LINGER socket option.
void Poco::Net::SocketImpl::setOOBInline | ( | bool | flag | ) |
Returns the value of the SO_REUSEPORT socket option.
Returns false if the socket implementation does not support SO_REUSEPORT.
void Poco::Net::SocketImpl::setOption | ( | int | level, |
int | option, | ||
const IPAddress & | value ) |
Sets the socket option specified by level and option to the given time value.
void Poco::Net::SocketImpl::setOption | ( | int | level, |
int | option, | ||
const Poco::Timespan & | value ) |
Sets the socket option specified by level and option to the given integer value.
void Poco::Net::SocketImpl::setOption | ( | int | level, |
int | option, | ||
int | value ) |
Returns the IP address and port number of the peer socket.
void Poco::Net::SocketImpl::setOption | ( | int | level, |
int | option, | ||
unsigned char | value ) |
Sets the socket option specified by level and option to the given integer value.
void Poco::Net::SocketImpl::setOption | ( | int | level, |
int | option, | ||
unsigned | value ) |
Sets the socket option specified by level and option to the given integer value.
|
virtual |
Sets the socket option specified by level and option to the given time value.
|
virtual |
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.
|
virtual |
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.
void Poco::Net::SocketImpl::setReuseAddress | ( | bool | flag | ) |
Returns the value of the SO_KEEPALIVE socket option.
void Poco::Net::SocketImpl::setReusePort | ( | bool | flag | ) |
Returns the value of the SO_REUSEADDR socket option.
|
virtual |
Determines the status of the socket, using a call to 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.
|
virtual |
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.
|
virtual |
Shuts down the sending part of the socket connection.
|
virtual |
Close the socket.
|
virtual |
Shuts down the receiving part of the socket connection.
int Poco::Net::SocketImpl::socketError | ( | ) |
Returns true iff the socket's connection is secure (using SSL or TLS).
|
inline |
Returns the value of the SO_ERROR socket option.
Definition at line 529 of file SocketImpl.h.
|
friend |
Definition at line 522 of file SocketImpl.h.
|
friend |
Definition at line 521 of file SocketImpl.h.
|
friend |
Definition at line 520 of file SocketImpl.h.
|
private |
Definition at line 517 of file SocketImpl.h.
|
private |
Definition at line 518 of file SocketImpl.h.
|
private |
Definition at line 515 of file SocketImpl.h.
|
private |
Definition at line 516 of file SocketImpl.h.
|
private |
Definition at line 514 of file SocketImpl.h.