35 class SocketProtocol ;
37 class DatagramSocket ;
121 bool listen(
int backlog = 1 ) ;
126 virtual ssize_type
write(
const char * buf , size_type len ) ;
196 void shutdown(
bool for_writing =
true ) ;
199 int fd( Credentials )
const ;
204 Socket(
int domain ,
int type ,
int protocol ) ;
216 static bool error(
int rc ) ;
217 static bool sizeError( ssize_type size ) ;
223 std::pair<bool,Address>
getAddress(
bool )
const ;
235 void operator=(
const Socket & ) ;
286 ssize_type
read(
char * buffer , size_type buffer_length ) ;
ssize_type write(const char *buffer, size_type len, const Address &dst)
Sends a datagram to the given address.
bool canBindHint(const Address &address)
Returns true if the socket can probably be bound with the given address.
DatagramSocket()
Default constructor.
bool listen(int backlog=1)
Starts the socket listening on the bound address for incoming connections or incoming datagrams...
std::pair< bool, Address > getLocalAddress() const
Retrieves local address of the socket.
void dropReadHandler()
Reverses addReadHandler().
void addExceptionHandler(EventHandler &handler)
Adds this socket to the event source list so that the given handler receives exception events...
bool connect(const Address &addr, bool *done=NULL)
Initiates a connection to (or association with) the given address.
virtual ssize_type write(const char *buf, size_type len)
Sends data.
bool eWouldBlock()
Returns true if the previous socket operation failed with the EWOULDBLOCK or EGAIN error status...
void addWriteHandler(EventHandler &handler)
Adds this socket to the event source list so that the given handler receives write events when flow c...
virtual ~DatagramSocket()
Destructor.
std::pair< bool, Address > getAddress(bool) const
The Address class encapsulates an IP transport address.
The Socket class encapsulates a non-blocking Unix socket file descriptor or a Windows 'SOCKET' handle...
A derivation of Socket for a connectionless datagram socket.
void addReadHandler(EventHandler &handler)
Adds this socket to the event source list so that the given handler receives read events...
virtual ~StreamSocket()
Destructor.
A network file descriptor.
StreamSocket()
Default constructor. Check with valid().
static bool sizeError(ssize_type size)
std::auto_ptr< StreamSocket > first_type
bool bind(const Address &address)
Binds the socket with an INADDR_ANY network address and the port number taken from the given address...
int fd(Credentials) const
Returns the socket descriptor as an integer.
void dropExceptionHandler()
Reverses addExceptionHandler().
bool eMsgSize()
Returns true if the previous socket operation failed with the EMSGSIZE error status.
void dropWriteHandler()
Reverses addWriteHandler().
AcceptPair(StreamSocket *new_p, Address a)
Constructor.
std::string reasonString() const
Returns the failure reason as a string.
void disconnect()
Releases the association between two datagram endpoints reversing the effect of the previous Socket::...
std::pair< bool, Address > getPeerAddress() const
Retrieves address of socket's peer.
A derivation of Socket for a stream socket.
ssize_type read(void *buffer, size_type len, Address &src)
Reads a datagram and returns the sender's address by reference.
Socket::ssize_type ssize_type
virtual ~Socket()
Destructor.
Socket(int domain, int type, int protocol)
Constructor used by derived classes.
A class which is used to return a new()ed socket to calling code, together with associated informatio...
A base class for classes that handle asynchronous socket events.
bool eInProgress()
Returns true if the previous socket operation failed with the EINPROGRESS error status.
bool hasPeer() const
Returns true if the socket has a valid peer.
ssize_type read(char *buffer, size_type buffer_length)
Reads data from the socket stream.
bool valid() const
Returns true if the socket handle is valid (open).
friend class SocketProtocolTest
A credentials class that allows SocketProtocol to call Socket::fd().
Socket::size_type size_type
void shutdown(bool for_writing=true)
Shuts the socket for writing (or reading).
AcceptPair & operator=(const AcceptPair &rhs)
Assignment operator.
AcceptPair accept()
Accepts an incoming connection, returning a new()ed socket and the peer address.
An interface for implementing a low-level protocol layer by means of calling read() and write() on a ...
static bool error(int rc)
std::string asString() const
Returns the socket handle as a string.