#include <socket.h>
Inheritance diagram for PSocket:
Socket establishment functions | |
enum | Reusability { CanReuseAddress, AddressIsExclusive } |
Flags to reuse of port numbers in Listen() function. More... | |
virtual BOOL | Connect (const PString &address) |
virtual BOOL | Listen (unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive) |
virtual BOOL | Accept (PSocket &socket) |
virtual BOOL | Shutdown (ShutdownValue option) |
Port/Service database functions | |
virtual WORD | GetPortByService (const PString &service) const |
virtual PString | GetServiceByPort (WORD port) const |
void | SetPort (WORD port) |
void | SetPort (const PString &service) |
WORD | GetPort () const |
PString | GetService () const |
WORD | GetProtocolByName (const PString &name) |
PString | GetNameByProtocol (WORD proto) |
WORD | GetPortByService (const char *protocol, const PString &service) |
PString | GetServiceByPort (const char *protocol, WORD port) |
Public Types | |
Public Member Functions | |
BOOL | Read (void *ptr, PINDEX len) |
~PSocket () | |
Socket options functions | |
BOOL | SetOption (int option, int value, int level=SOL_SOCKET) |
BOOL | SetOption (int option, const void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET) |
BOOL | GetOption (int option, int &value, int level=SOL_SOCKET) |
BOOL | GetOption (int option, void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET) |
Static Public Member Functions | |
Multiple socket selection functions | |
int | Select (PSocket &sock1, PSocket &sock2) |
int | Select (PSocket &sock1, PSocket &sock2, const PTimeInterval &timeout) |
Errors | Select (SelectList &read) |
Errors | Select (SelectList &read, const PTimeInterval &timeout) |
Errors | Select (SelectList &read, SelectList &write) |
Errors | Select (SelectList &read, SelectList &write, const PTimeInterval &timeout) |
Errors | Select (SelectList &read, SelectList &write, SelectList &except) |
Errors | Select (SelectList &read, SelectList &write, SelectList &except, const PTimeInterval &timeout) |
Integer conversion functions | |
WORD | Host2Net (WORD v) |
Convert from host to network byte order. | |
DWORD | Host2Net (DWORD v) |
Convert from host to network byte order. | |
WORD | Net2Host (WORD v) |
Convert from network to host byte order. | |
DWORD | Net2Host (DWORD v) |
Convert from network to host byte order. | |
Protected Member Functions | |
PSocket () | |
virtual BOOL | OpenSocket ()=0 |
virtual const char * | GetProtocolName () const =0 |
int | os_close () |
int | os_socket (int af, int type, int proto) |
BOOL | os_connect (struct sockaddr *sin, PINDEX size) |
BOOL | os_recvfrom (void *buf, PINDEX len, int flags, struct sockaddr *from, PINDEX *fromlen) |
BOOL | os_sendto (const void *buf, PINDEX len, int flags, struct sockaddr *to, PINDEX tolen) |
BOOL | os_accept (PSocket &listener, struct sockaddr *addr, PINDEX *size) |
Protected Attributes | |
WORD | port |
Port to be used by the socket when opening the channel. |
A socket represents a bidirectional communications channel to a { port} at a remote { host}.
|
Flags to reuse of port numbers in Listen() function.
|
|
|
|
|
|
Open a socket to a remote host on the specified port number. This is an "accepting" socket. When a "listening" socket has a pending connection to make, this will accept a connection made by the "connecting" socket created to establish a link. The port that the socket uses is the one used in the #Listen()# command of the #socket# parameter. Note an error occurs if the #socket# parameter has not had the #Listen()# function called on it. Note that this function will block until a remote system connects to the port number specified in the "listening" socket. The time that the function will block is determined by the read timeout of the #socket# parameter. This will normally be #PMaxTimeInterval# which indicates an infinite time. The default behaviour is to assert.
Reimplemented in PSPXSocket, PTCPSocket, PSocksSocket, and PTelnetSocket. |
|
Connect a socket to a remote host on the specified port number. This is typically used by the client or initiator of a communications channel. This connects to a "listening" socket at the other end of the communications channel. Use the SetReadTimeout function to set a maximum time for the Connect
Reimplemented in PEthSocket, PIPSocket, PIPXSocket, PUDPSocket, PSocksSocket, PSocksUDPSocket, and PTelnetSocket. |
|
Get the name of the protocol number specified.
|
|
Get options on the socket. These options are defined as Berkeley socket options of the class SOL_SOCKET.
|
|
Get options on the socket. These options are defined as Berkeley socket options of the class SOL_SOCKET.
|
|
Get the port the TCP socket channel object instance is using.
|
|
Get the port number for the specified service name. A name is a unique string contained in a system database. The parameter here may be either this unique name, an integer value or both separated by a space (name then integer). In the latter case the integer value is used if the name cannot be found in the database. The exact behviour of this function is dependent on whether TCP or UDP transport is being used. The PTCPSocket# and PUDPSocket# classes will implement this function. The static version of the function is independent of the socket type as its first parameter may be "tcp" or "udp",
|
|
Get the port number for the specified service name.
|
|
Get the number of the protocol associated with the specified name.
|
|
This function returns the protocol name for the socket type. Implemented in PEthSocket, PICMPSocket, PIPXSocket, PSPXSocket, PTCPSocket, and PUDPSocket. |
|
Get a service name for the port number the TCP socket channel object instance is using.
|
|
Get the service name from the port number. A service name is a unique string contained in a system database. The parameter here may be either this unique name, an integer value or both separated by a space (name then integer). In the latter case the integer value is used if the name cannot be found in the database. The exact behviour of this function is dependent on whether TCP or UDP transport is being used. The PTCPSocket# and PUDPSocket# classes will implement this function. The static version of the function is independent of the socket type as its first parameter may be "tcp" or "udp",
|
|
Get the service name from the port number.
|
|
Convert from host to network byte order.
|
|
Convert from host to network byte order.
|
|
Listen on a socket for a remote host on the specified port number. This may be used for server based applications. A "connecting" socket begins a connection by initiating a connection to this socket. An active socket of this type is then used to generate other "accepting" sockets which establish a two way communications channel with the "connecting" socket. If the port# parameter is zero then the port number as defined by the object instance construction or the descendent classes SetPort() or SetService() function.
Reimplemented in PEthSocket, PIPSocket, PIPXSocket, PSPXSocket, PTCPSocket, PSocksSocket, and PSocksUDPSocket. |
|
Convert from network to host byte order.
|
|
Convert from network to host byte order.
|
|
Implemented in PEthSocket, PICMPSocket, PIPXSocket, PSPXSocket, PTCPSocket, and PUDPSocket. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Low level read from the channel. This function may block until the requested number of characters were read or the read timeout was reached. The GetLastReadCount() function returns the actual number of bytes read. The GetErrorCode() function should be consulted after Read() returns FALSE to determine what caused the failure.
Reimplemented from PChannel. Reimplemented in PEthSocket, PTCPSocket, PUDPSocket, and PTelnetSocket. |
|
Select a socket with available data. This function will block until the timeout or data is available to be read or written to the specified sockets. The #read#, #write# and #except# lists are modified by the call so that only the sockets that have data available are present. If the call timed out then all of these lists will be empty. If no timeout is specified then the call will block until a socket has data available.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Select a socket with available data.
|
|
Set options on the socket. These options are defined as Berkeley socket options of the class SOL_SOCKET.
|
|
Set options on the socket. These options are defined as Berkeley socket options of the class SOL_SOCKET.
|
|
Set the port number for the channel. This a 16 bit number representing an agreed high level protocol type. The string version looks up a database of names to find the number for the string name. A service name is a unique string contained in a system database. The parameter here may be either this unique name, an integer value or both separated by a space (name then integer). In the latter case the integer value is used if the name cannot be found in the database. The port number may not be changed while the port is open and the function will assert if an attempt is made to do so.
|
|
Set the port number for the channel.
|
|
Close one or both of the data streams associated with a socket
Reimplemented from PChannel. |
|
Port to be used by the socket when opening the channel.
|