fdhwlib
2.0.25
|
#include <simplesocket.h>
Implements a simple socket for use with any server.
Every instance of the class will establish a connection with a server. By default the connection will use a timeout of SIMPLESOCKET_TIMEOUT milliseconds. The timeout can be changed when using the socket connection with setTimeout. A value of zero for the timeout will turn off the timeout and makes every access blocking.
Changes:
Definition at line 56 of file simplesocket.h.
SimpleSocket::SimpleSocket | ( | const char * | server, |
unsigned short | port | ||
) |
Create connection.
There will be no timeout. To change the timeout after the connection is established use setTimeout function.
server | hostname of the server application |
port | port number of the server application |
SimpleSocket::SimpleSocket | ( | const char * | server, |
unsigned short | port, | ||
unsigned long | timeout | ||
) |
Create connection with timeout To change the timeout after the connection is established use setTimeout function.
server | hostname of the server application |
port | port number of the server application |
timeout | given in miliseconds |
SimpleSocket::SimpleSocket | ( | const char * | server, |
unsigned short | port, | ||
struct timeval | timeout | ||
) |
Create connection with timeout To change the timeout after the connection is established use setTimeout function.
server | hostname of the server application |
port | port number of the server application |
timeout |
SimpleSocket::~SimpleSocket | ( | ) |
Destructor of class SimpleSocket.
void SimpleSocket::connectServer | ( | const char * | server, |
unsigned short | port | ||
) | [private] |
Connect to server.
int SimpleSocket::getFD | ( | ) |
Get the file desciptor.
char* SimpleSocket::getHostName | ( | ) |
char* SimpleSocket::getPeerName | ( | ) |
int SimpleSocket::readData | ( | unsigned long * | data, |
int | max | ||
) |
int SimpleSocket::readData | ( | unsigned int * | data, |
int | max | ||
) |
int SimpleSocket::readMsg | ( | char * | msg, |
int | max | ||
) |
int SimpleSocket::readPacket | ( | unsigned long * | data, |
int | max | ||
) |
Read a packet of raw data.
Each packet consist of header, raw data and trailer. Header and trailer have the format 0xfff | length of raw data.
int SimpleSocket::remoteCall | ( | short | cmdid, |
unsigned long * | args, | ||
short | argc = 0 , |
||
unsigned long * | data = NULL , |
||
short | ndata = 0 , |
||
unsigned long * | ackn = NULL , |
||
short | len = 0 |
||
) |
Make a call to the connected server.
The command implements a simple protokoll to exchange command id, arguments and results. The command also considers possible error messages.
cmdid | Command id; has to be implemented by higher level protokolls |
args | List of arguments |
argc | Number of arguments in lists args |
data | List of data |
ndata | Number of data |
ackn | List of acknowledge parameter |
len | Number acknowledge parameter |
int SimpleSocket::remoteCall | ( | short | cmdid, |
uint32_t * | args = NULL , |
||
short | argc = 0 , |
||
uint32_t * | data = NULL , |
||
short | ndata = 0 , |
||
uint32_t * | ackn = NULL , |
||
short | len = 0 |
||
) |
void SimpleSocket::setTimeout | ( | unsigned long | timeout | ) |
Set timeout in miliseconds.
void SimpleSocket::setTimeout | ( | struct timeval | timeout | ) |
Set timeout.
int SimpleSocket::wait | ( | int | timeout | ) |
Wait for a certain time.
timeout | Time to wait in seconds |
int SimpleSocket::waitForReading | ( | ) |
Wait for reading socket.
int SimpleSocket::waitForWriting | ( | ) |
Wait for reading socket.
int SimpleSocket::writeData | ( | unsigned long * | data, |
int | n | ||
) |
int SimpleSocket::writeData | ( | unsigned int * | data, |
int | n | ||
) |
int SimpleSocket::writeMsg | ( | char * | msg, |
int | n = 0 |
||
) |
int SimpleSocket::writePacket | ( | unsigned long * | data, |
int | n | ||
) |
Write a packet of raw data.
Each packet consist of header, raw data and trailer. Header and trailer have the format 0xfff | length of raw data.
bool SimpleSocket::nonblock [private] |
Flag to indicate nonblocking sockets.
Definition at line 174 of file simplesocket.h.
int SimpleSocket::sock [private] |
Definition at line 171 of file simplesocket.h.
struct timeval SimpleSocket::timeout [private] |
Timeout for connection, reading and writing.
Definition at line 177 of file simplesocket.h.