fdhwlib  2.0.25
SimpleSocket Class Reference

#include <simplesocket.h>

Inheritance diagram for SimpleSocket:
IRhandlerSock

List of all members.

Public Member Functions

Private Member Functions

Private Attributes


Detailed Description

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:

  • Added timeout (8-2-2006 ak)

Definition at line 56 of file simplesocket.h.


Constructor & Destructor Documentation

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.

Parameters:
serverhostname of the server application
portport 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.

Parameters:
serverhostname of the server application
portport number of the server application
timeoutgiven 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.

Parameters:
serverhostname of the server application
portport number of the server application
timeout
SimpleSocket::~SimpleSocket ( )

Destructor of class SimpleSocket.


Member Function Documentation

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.

Parameters:
cmdidCommand id; has to be implemented by higher level protokolls
argsList of arguments
argcNumber of arguments in lists args
dataList of data
ndataNumber of data
acknList of acknowledge parameter
lenNumber acknowledge parameter
Returns:
error status: 0 no error, 1+ error while exectution of the command, -1 socket communication closed by foreign host.
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.

Parameters:
timeoutTime to wait in seconds
int SimpleSocket::waitForReading ( )

Wait for reading socket.

Returns:
-1 error, 0 timeout, 1 ok
int SimpleSocket::waitForWriting ( )

Wait for reading socket.

Returns:
-1 error, 0 timeout, 1 ok
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.


Member Data Documentation

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.


The documentation for this class was generated from the following file: