Poco Library Chinese Programming Reference Guide (3) poco::net::socket
- Liu Poechant
- Blog: blog.csdn.net/poechant
- E-Mail: zhongchao.ustc#gmail.com (#, @)
- Date: April 14th, 2012
1 SelectMode
enum SelectMode /// The mode argument to poll() and select().{ SELECT_READ = 1, SELECT_WRITE = 2, SELECT_ERROR = 4};
2 Socketlist
typedef std::vector<Socket> SocketList;
3 constructors
Uninitialized socket:
Socket();
Copy constructor
Socket(const Socket& socket);
4 Overloaded operators
Assignment operators:
Socket& operator = (const Socket& socket);
Comparison operators:
bool operator == (const Socket& socket) const;bool operator != (const Socket& socket) const;bool operator < (const Socket& socket) const;bool operator <= (const Socket& socket) const;bool operator > (const Socket& socket) const;bool operator >= (const Socket& socket) const;
5 Common socket Operations
Returns the number of bytes of readable data for the socket, which does not cause the socket to block:
int available() const;
To close the socket:
void close();
Poll
bool poll(const Poco::Timespan& timeout, int mode) const; /// 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.SocketImpl* impl() const; /// Returns the SocketImpl for this socket.
Check if the connection to this socket is secure (using SSL or TLS):
bool secure() const;
6 buffers
Buffer for sending data:
void setSendBufferSize(int size);int getSendBufferSize() const;
Buffer to receive data:
void setReceiveBufferSize(int size);int getReceiveBufferSize() const;
7 Timeout period
Time-out period for sending data:
void setSendTimeout(const Poco::Timespan& timeout);Poco::Timespan getSendTimeout() const;
Timeout time to receive data:
void setReceiveTimeout(const Poco::Timespan& timeout);Poco::Timespan getReceiveTimeout() const;
8 Other interfaces
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 setopt Ion (int level, int option, const ipaddress& value), void GetOption (int. level, int option, int& value) const;void ge Toption (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, Ipaddre ss& value) const;void Setlinger (bool on, int. seconds), void Getlinger (bool& on, int& seconds) const;void Setnod Elay (BOOL flag), BOOL Getnodelay () const;void setkeepalive (BOOL flag), BOOL Getkeepalive () const;void setreuseaddress ( BOOL flag), BOOL Getreuseaddress () const;void Setreuseport (BOOL flag), BOOL Getreuseport () const;void Setoobinline (bool flag); bool Getoobinline () Const;voID setblocking (BOOL flag); bool Getblocking () const;
Get the IP and port of the socket:
SocketAddress address() const;
Get the IP address and port of the peer socket:
SocketAddress peerAddress() const;
9 Static functions
Select
static int Select (socketlist& readlist, socketlist& writelist, socketlist& exceptlist, const poco::timespan& timeout); 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 Thos E 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 () would retur n Immediately and the Return value would be 0. If one of the sockets passed to select () are closed while///select () runs, select'll return immediately. However,///The closed socket is not being included in any list. In this case, the return value is greater than the sum//of all sockets in the all list.
Check whether IPV4 or IPV6 are supported:
static bool supportsIPv4();static bool supportsIPv6();
-
From:blog.csdn.net/poechant
Poco Library Chinese Programming Reference Guide (3) poco::net::socket