ost::TCPSocket - TCP sockets are used for stream based connected sessions between two sockets.
Contents
Constructor & Destructor Documentation
ost::TCPSocket::TCPSocket(constIPV4Address&bind,tpport_tport,unsignedbacklog=5,unsignedmss=536)
A TCP 'server' is created as a TCP socket that is bound to a hardware address and port number on the
local machine and that has a backlog queue to listen for remote connection requests. If the server cannot
be created, an exception is thrown.
Parametersbind local ip address or interface to use.
port number to bind socket under.
backlog size of connection request queue.
mss maximum segment size for accepted streams.
ost::TCPSocket::TCPSocket(constchar*name,unsignedbacklog=5,unsignedmss=536)
Create a named tcp socket by service and/or interface id. For IPV4 we use [host:]svc or [host/]svc for
the string. If we have getaddrinfo, we use that to obtain the addr to bind for.
Parametersname of host interface and service port to bind.
backlog size of connection request queue.
mss maximum segment size for streaming buffers.
virtualost::TCPSocket::~TCPSocket()[virtual]
Use base socket handler for ending this socket.
Detailed Description
TCP sockets are used for stream based connected sessions between two sockets.
Both error recovery and flow control operate transparently for a TCP socket connection. The TCP socket
base class is primary used to bind a TCP 'server' for accepting TCP streams.
An implicit and unique TCPSocket object exists in Common C++ to represent a bound TCP socket acting as a
'server' for receiving connection requests. This class is not part of TCPStream because such objects
normally perform no physical I/O (read or write operations) other than to specify a listen backlog queue
and perform 'accept' operations for pending connections. The Common C++ TCPSocket offers a Peek method to
examine where the next pending connection is coming from, and a Reject method to flush the next request
from the queue without having to create a session.
The TCPSocket also supports a 'OnAccept' method which can be called when a TCPStream related object is
created from a TCPSocket. By creating a TCPStream from a TCPSocket, an accept operation automatically
occurs, and the TCPSocket can then still reject the client connection through the return status of it's
OnAccept method.
Author
David Sugar dyfet@tycho.com
bound server for TCP streams and sessions.
Examplestcp.cpp, tcpservice.cpp, tcpstr1.cpp, and tcpthread.cpp.
Member Data Documentation
intost::TCPSocket::segsize[protected]
Member Function Documentation
IPV4Hostost::TCPSocket::getLocal(tpport_t*port=NULL)const[inline]
Used to get local bound address.
References ost::Socket::getIPV4Local().
IPV4Hostost::TCPSocket::getRequest(tpport_t*port=NULL)const[inline]
Return address and port of next connection request. This can be used instead of OnAccept() to pre-
evaluate connection requests.
Returns
host requesting a connection.
Parametersport number of requestor.
References ost::Socket::getIPV4Sender().
intost::TCPSocket::getSegmentSize(void)[inline]
Get the buffer size for servers.
SOCKETost::TCPSocket::getSocket(void)[inline]
Fetch out the socket.
boolost::TCPSocket::isPendingConnection(timeout_ttimeout=TIMEOUT_INF)[inline]
Used to wait for pending connection requests.
Returns
true if data packets available.
Parameterstimeout in milliseconds. TIMEOUT_INF if not specified.
Examplestcpstr1.cpp, and tcpthread.cpp.
References ost::Socket::isPending(), and ost::Socket::pendingInput.
virtualboolost::TCPSocket::onAccept(constIPV4Host&ia,tpport_tport)[virtual]
A method to call in a derived TCPSocket class that is acting as a server when a connection request is
being accepted. The server can implement protocol specific rules to exclude the remote socket from being
accepted by returning false. The Peek method can also be used for this purpose.
Returns
true if client should be accepted.
Parametersia internet host address of the client.
port number of the client.
voidost::TCPSocket::reject(void)
Used to reject the next incoming connection request.
voidost::TCPSocket::setSegmentSize(unsignedmss)[protected]Name
ost::TCPSocket - TCP sockets are used for stream based connected sessions between two sockets.
Synopsis
#include <socket.h>
Inherits ost::Socket.
PublicMemberFunctions
virtual bool onAccept (const IPV4Host &ia, tpport_t port)
A method to call in a derived TCPSocket class that is acting as a server when a connection request is
being accepted.
SOCKETgetSocket (void)
Fetch out the socket.
int getSegmentSize (void)
Get the buffer size for servers.
TCPSocket (const IPV4Address &bind, tpport_t port, unsigned backlog=5, unsigned mss=536)
A TCP 'server' is created as a TCP socket that is bound to a hardware address and port number on the
local machine and that has a backlog queue to listen for remote connection requests.
TCPSocket (const char *name, unsigned backlog=5, unsigned mss=536)
Create a named tcp socket by service and/or interface id.
IPV4HostgetRequest (tpport_t *port=NULL) const
Return address and port of next connection request.
void reject (void)
Used to reject the next incoming connection request.
IPV4HostgetLocal (tpport_t *port=NULL) const
Used to get local bound address.
bool isPendingConnection (timeout_t timeout=TIMEOUT_INF)
Used to wait for pending connection requests.
virtual ~TCPSocket ()
Use base socket handler for ending this socket.
ProtectedMemberFunctions
void setSegmentSize (unsigned mss)
ProtectedAttributes
int segsizeAdditionalInheritedMembers