Socket communication class.
More...
#include <scim_socket.h>
List of all members.
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.
|
Detailed Description
Socket communication class.
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.
Constructor & Destructor Documentation
scim::Socket::Socket |
( |
int |
id = -1 | ) |
|
Create a Socket object from an already created socket_id.
- Parameters:
-
id | an file id of an existing socket. |
scim::Socket::~Socket |
( |
| ) |
|
Member Function Documentation
bool scim::Socket::valid |
( |
| ) |
const |
Check if the socket is valid.
- Returns:
- true if the socket is ready to read and write.
Reimplemented in scim::SocketServer.
int scim::Socket::read |
( |
void * |
buf, |
|
|
size_t |
size |
|
) |
| const |
Read data from socket.
- Parameters:
-
buf | the buffer to store the data. |
size | size of the buffer. |
- Returns:
- the amount of data actually read, -1 means error occurred.
int scim::Socket::read_with_timeout |
( |
void * |
buf, |
|
|
size_t |
size, |
|
|
int |
timeout |
|
) |
| const |
read data from socket with a timeout.
- Parameters:
-
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. |
- Returns:
- the amount of data actually read, 0 means the connection is closed, -1 means error occurred.
int scim::Socket::write |
( |
const void * |
buf, |
|
|
size_t |
size |
|
) |
| const |
Write data to socket.
- Parameters:
-
buf | the buffer stores the data. |
size | size of the data to be sent. |
- Returns:
- the amount of data acutally sent, or -1 if an error occurred.
int scim::Socket::wait_for_data |
( |
int |
timeout = -1 | ) |
const |
Wait until there are some data ready to read.
- Parameters:
-
timeout | time out in millisecond (1/1000 second), -1 means infinity. |
- Returns:
- > 0 if data is OK, == 0 if time is out, < 0 if an error occurred.
int scim::Socket::get_error_number |
( |
| ) |
const |
Get the number of the last occurred error.
- Returns:
- the standard errno value.
Reimplemented in scim::SocketServer.
String scim::Socket::get_error_message |
( |
| ) |
const |
Get the message of the last occurred error.
- Returns:
- the error message of the last occurred error.
Reimplemented in scim::SocketServer.
int scim::Socket::get_id |
( |
| ) |
const |
Get the socket id.
- Returns:
- the file id of this socket object.
Initiate a connection on a socket.
- Parameters:
-
addr | the address to be connected to. |
- Returns:
- true if success.
Bind a socket to an address, used by SocketServer.
- Parameters:
-
addr | the address to be binded to. |
- Returns:
- true if success.
bool scim::Socket::listen |
( |
int |
queue_length = 5 | ) |
const |
|
protected |
Listen for connections on a socket.
- Parameters:
-
queue_length | the length of the waiting queue. |
- Returns:
- true if success.
int scim::Socket::accept |
( |
| ) |
const |
|
protected |
Accept a connection on the socket, used by SocketServer.
- Returns:
- the id of the accepted client socket, or -1 if an error is occurred.
Create a socket for specific family.
- Parameters:
-
- Returns:
- true if success.
void scim::Socket::close |
( |
| ) |
|
|
protected |
The documentation for this class was generated from the following file: