Public Member Functions | |
void | close () |
Closes connection. | |
int | getHandler () const |
Returns system connection handler. | |
bool | opened () const |
Returns non-zero if connection was opened. | |
ssize_t | read (std::string &s) const |
Reads data and saves it in string object. | |
ssize_t | read (void *buf, size_t s) const |
Reads data from the socket. | |
Socket (int fd) | |
The constructor with file descriptor specification. | |
Socket () | |
The default constructor. | |
ssize_t | write (const void *buf, size_t s) const |
Writes data to socket. | |
virtual | ~Socket () |
The destructor. | |
Protected Attributes | |
bool | m_opened |
int | m_sock |
Socket::Socket | ( | int | fd | ) | [inline] |
[in] | fd | The file descriptor new socket object must be associated with |
virtual Socket::~Socket | ( | ) | [inline, virtual] |
This destructor closes socket if it was opened and not closed.
void Socket::close | ( | ) |
This method will be called automatically on socket object deletion if it was not closed explicitly. You can call this method in any situation, there is checking, not opened object will not be closed.
int Socket::getHandler | ( | ) | const |
This method just returned file descriptor associated with current connection, but it may not be called for not opened sockets.
bool Socket::opened | ( | ) | const |
This method checks internal variables and let you know is this object is ready for I/O operations or not.
ssize_t Socket::read | ( | std::string & | s | ) | const |
This method tries to read 2048 bytes and saves available data in string object. The number of read bytes does not have any meaning are there more bytes to read or not. You should explicitly use select() function or ioctrl(FIONREAD) calls to determine this.
[out] | s | The string object to receive data |
ssize_t Socket::read | ( | void * | buf, | |
size_t | s | |||
) | const |
This method performs one read() call with appropriate parameters. The value returned by this function is the native value from read() system call.
[out] | buf | The buffer to receive data |
[in] | s | The size of a buffer to receive data |
ssize_t Socket::write | ( | const void * | buf, | |
size_t | s | |||
) | const |
This method performs one write() call with appropriate parameters. The value returned by this function is the native value from write() system call.
[in] | buf | The a buffer with data to write |
[in] | s | The number of bytes to write |