#include <socket.h>
Inheritance diagram for sockets::Socket:
Public Types | |
enum | { ssCreated = 0x00000001, ssLocalInfo = 0x00000002, ssRemoteInfo = 0x00000004, ssBound = 0x00000008, ssConnecting = 0x00000010, ssConnected = 0x00000020, ssListening = 0x00000040, ssMonitored = 0x00000080, ssReadable = 0x00000100, ssWritable = 0x00000200, ssCloseFlags, ssCopyFlags = (ssLocalInfo | ssRemoteInfo) } |
Possible flags for socket status. More... | |
Public Member Functions | |
Socket (int family=PF_UNSPEC, int type=0, int protocol=0) | |
Constructor. | |
Socket (Socket const &s) | |
Copy constructor. | |
virtual Socket & | operator= (Socket const &right) |
Assignment operator. | |
virtual | ~Socket () |
Destructor. | |
virtual bool | assign (int fd, uint32_t status) |
Assigns a socket file descriptor. | |
virtual bool | read_event () |
Read event -- For call by the Monitor-derived classes. | |
virtual bool | write_event () |
Write event -- For call by the Monitor and derived classes. | |
int | family () const |
Returns the socket protocol family. | |
int | type () const |
Returns the socket type. | |
int | protocol () const |
Returns the socket protocol. | |
uint32_t | status () const |
Returns the socket status. | |
std::string const & | monitor () const |
Returns the monitor name. | |
bool | monitor (std::string const &name) |
Sets the monitor used by this socket. | |
Static Public Member Functions | |
static char const * | hostname () |
Returns the hostname of the current processor. | |
Protected Member Functions | |
virtual bool | create () |
Creates the socket. | |
virtual bool | close () |
Closes the socket. | |
virtual bool | watch () |
Monitors a socket. | |
virtual void | unwatch () |
Unmonitors a socket. | |
int | fd () const |
Returns the socket file descriptor. | |
int | family (int family) |
Sets the socket protocol family. | |
int | type (int type) |
Sets the socket type. | |
int | protocol (int protocol) |
Sets the socket protocol. | |
uint32_t | status_add (uint32_t flags) |
Adds a flag to the socket status. | |
uint32_t | status_remove (uint32_t flags) |
Removes a flag from the socket status. |
It handles socket creation and destruction, and provides means to track socket status.
|
|
|
Constructor.
|
|
This copy constructor copies the socket family, type, protocol, monitor and part of the status only.
|
|
This destructor calls the close() function. |
|
Assigns a socket file descriptor to the socket object, that is then used by the object for all operations on the socket. The ssCreated status flag must not be set prior to calling this function; it is set once the function returns successfully.
Reimplemented in sockets::IPSocket, and sockets::TCPClient. |
|
Closes the socket, if it has been created. The ssCloseFlags flags are removed from the socket status on success. If the socket is monitored, the unwatch() function is called as well.
Reimplemented in sockets::TCPClient. |
|
Creates the socket. The socket protocol family, type and protocol must have been set prior to calling this function. Upon successful creation, the ssCreated flag is added to the socket status. This function may be overriden to change the socket options, etc. as needed.
Reimplemented in sockets::IPSocket. |
|
Sets the socket protocol family. No change is done when the ssCreated status flag is set on the socket.
|
|
Returns the socket file descriptor.
|
|
Sets the monitor used by this socket. This can't be changed once the ssMonitored status flag is set on the socket.
|
|
This assignment operator copies the socket family, type, protocol, monitor and part of the status only.
|
|
Sets the socket protocol. No change is done when the ssCreated status flag is set on the socket.
|
|
This function is called by the Monitor-derived classes when a read event happens.
Reimplemented in sockets::TCPClient. |
|
Returns the socket status, which is an or'ed set of the ss* flags defined in the Socket class.
|
|
Adds a flag to the socket status. Possible flags include all ss* flags defined in the Socket class.
|
|
Removes a flag from the socket status. Possible flags include all ss* flags defined in the Socket class.
|
|
Sets the socket type. No change is done when the ssCreated status flag is set on the socket.
|
|
Unmonitors a socket. The ssMonitored flag is always unset after this function returns. |
|
Monitors a socket. The Monitor::add(), Monitor::update() function is called with an appropriate event set depending on whether the ssMonitored, ssReadable and ssWritable status flags are set. The ssMonitored flag is always set after this function returns successfully.
|
|
This function is called by the Monitor-derived classes when a write event happens.
Reimplemented in sockets::TCPClient. |