#include <scim_socket.h>
Inherited by scim::SocketClient, and scim::SocketServer [private]
.
Public Member Functions | |
Socket (int id=-1) | |
Create a Socket object from an already created socket_id. | |
~Socket () | |
Destructor. | |
bool | valid () const |
Check if the socket is valid. | |
int | read (void *buf, size_t size) const |
Read data from socket. | |
int | read_with_timeout (void *buf, size_t size, int timeout) const |
read data from socket with a timeout. | |
int | write (const void *buf, size_t size) const |
Write data to socket. | |
int | wait_for_data (int timeout=-1) const |
Wait until there are some data ready to read. | |
int | get_error_number () const |
Get the number of the last occurred error. | |
String | get_error_message () const |
Get the message of the last occurred error. | |
int | get_id () const |
Get the socket id. | |
Protected Member Functions | |
bool | connect (const SocketAddress &addr) const |
Initiate a connection on a socket. | |
bool | bind (const SocketAddress &addr) const |
Bind a socket to an address, used by SocketServer. | |
bool | listen (int queue_length=5) const |
Listen for connections on a socket. | |
int | accept () const |
Accept a connection on the socket, used by SocketServer. | |
bool | create (SocketFamily family) |
Create a socket for specific family. | |
void | close () |
Close the socket. |
Class Socket provides basic operation of socket, such as bind connect, read, write etc.
This class object cannot be created directly by user. Only the object of its derived classes SocketServer and SocketClient can be created directly.
scim::Socket::Socket | ( | int | id = -1 |
) |
Create a Socket object from an already created socket_id.
id | an file id of an existing socket. |
scim::Socket::~Socket | ( | ) |
Destructor.
bool scim::Socket::valid | ( | ) | const |
Check if the socket is valid.
Reimplemented in scim::SocketServer.
int scim::Socket::read | ( | void * | buf, | |
size_t | size | |||
) | const |
Read data from socket.
buf | the buffer to store the data. | |
size | size of the buffer. |
int scim::Socket::read_with_timeout | ( | void * | buf, | |
size_t | size, | |||
int | timeout | |||
) | const |
read data from socket with a timeout.
buf | the buffer to store the data. | |
size | size of the buffer, and the amount of data to be read. | |
timeout | time out in millisecond (1/1000 second), -1 means infinity. |
int scim::Socket::write | ( | const void * | buf, | |
size_t | size | |||
) | const |
Write data to socket.
buf | the buffer stores the data. | |
size | size of the data to be sent. |
int scim::Socket::wait_for_data | ( | int | timeout = -1 |
) | const |
Wait until there are some data ready to read.
timeout | time out in millisecond (1/1000 second), -1 means infinity. |
int scim::Socket::get_error_number | ( | ) | const |
Get the number of the last occurred error.
Reimplemented in scim::SocketServer.
String scim::Socket::get_error_message | ( | ) | const |
Get the message of the last occurred error.
Reimplemented in scim::SocketServer.
int scim::Socket::get_id | ( | ) | const |
Get the socket id.
bool scim::Socket::connect | ( | const SocketAddress & | addr | ) | const [protected] |
Initiate a connection on a socket.
addr | the address to be connected to. |
bool scim::Socket::bind | ( | const SocketAddress & | addr | ) | const [protected] |
Bind a socket to an address, used by SocketServer.
addr | the address to be binded to. |
bool scim::Socket::listen | ( | int | queue_length = 5 |
) | const [protected] |
Listen for connections on a socket.
queue_length | the length of the waiting queue. |
int scim::Socket::accept | ( | ) | const [protected] |
Accept a connection on the socket, used by SocketServer.
bool scim::Socket::create | ( | SocketFamily | family | ) | [protected] |
Create a socket for specific family.
family | the family type. |
void scim::Socket::close | ( | ) | [protected] |