fdhwlib
2.0.25
|
#include <baseserver.h>
Implements a simple IP server.
The server waits for connections. The communication with the client is defined in the protected function read_from_client. Overload this function for a specific application.
The server allows to communicate with clients that use different bytes order. The list change_byteorder_fd_set contains all connections that do not operate with the same byte order. The server always tries to communicate with it's own native byte order. The protocoll does not exchange all data in network byte order. (Compile flag USE_DYN_BYTEORER). The disabled compile flag USE_BYTEORDER transvers all variables in network byte order.
Use a independant threads for all connections. If one connection hangs, the other won't be affected?!
Improve the Server managment. Loging, Shutdown via IP. For some other purpose a New class similar to Pbus/PbusProxy couble may be useful for maintenance and run control. Eg. shutdown + restart of the Server, Control of the IRdispatcher!!!
Changes:
Definition at line 96 of file baseserver.h.
BaseServer::BaseServer | ( | unsigned short | port | ) |
virtual BaseServer::~BaseServer | ( | ) | [virtual] |
void BaseServer::disableTimeout | ( | ) |
void BaseServer::display | ( | ) |
void BaseServer::displayActiveSockets | ( | ) |
Display all active sockets that are served.
The display format is somewhat similar to the output of the shell command "netstat --ip". IP number and port number of both sides of the connection are show.
void BaseServer::displayActiveSockets | ( | FILE * | fout | ) |
Display all active sockets, but use not the standard output stream defined in the initialization.
void BaseServer::displayMsg | ( | unsigned char * | msg, |
int | len | ||
) | [protected] |
Display a message byte by byte in hex format.
virtual void BaseServer::displayVersion | ( | ) | [protected, virtual] |
void BaseServer::enableTimeout | ( | struct timeval * | timeout = 0 | ) |
Enable period sampling.
void BaseServer::endian_prepare_short | ( | unsigned long & | x | ) | [inline, protected] |
Prepare transmission of short arrays In case of endian swap all short arrays are scrambled.
It is necessary to reorder the arrays before transmission.
Note: The function will only work if a even number of short values is transmitted.
Definition at line 276 of file baseserver.h.
{ x = (x>>16) | (x<<16); }
void BaseServer::endian_prepare_string | ( | unsigned long & | x | ) | [inline, protected] |
Prepare transmission of character strings In case of endian swap all charcter strings are scrambled.
It is necessary to reorder the strings before transmission.
Definition at line 261 of file baseserver.h.
{ x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); }
void BaseServer::endian_swap | ( | unsigned short & | x | ) | [inline, protected] |
Change byte order of a short variable.
Definition at line 223 of file baseserver.h.
Referenced by endian_swap().
{ x = (x>>8) | (x<<8); }
void BaseServer::endian_swap | ( | uint32_t & | x | ) | [inline, protected] |
Change byte order of a uint32_t variable.
Definition at line 228 of file baseserver.h.
{ x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); }
void BaseServer::endian_swap | ( | unsigned long & | x | ) | [inline, protected] |
Change byte order of a long variable.
Definition at line 236 of file baseserver.h.
{ x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); }
void BaseServer::endian_swap | ( | unsigned long long & | x | ) | [inline, protected] |
Change byte order for 64bit data types.
Definition at line 244 of file baseserver.h.
{ x = (x>>56) | ((x<<40) & 0x00FF000000000000ULL) | ((x<<24) & 0x0000FF0000000000ULL) | ((x<<8) & 0x000000FF00000000ULL) | ((x>>8) & 0x00000000FF000000ULL) | ((x>>24) & 0x0000000000FF0000ULL) | ((x>>40) & 0x000000000000FF00ULL) | (x<<56); }
void BaseServer::endian_swap | ( | unsigned int & | x | ) | [inline, protected] |
Swap endians for short long ints.
Definition at line 284 of file baseserver.h.
{ //printf("Swap: %d --> ", x); x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); //printf("%d \n", x); }
void BaseServer::endian_swap | ( | double & | x | ) | [inline, protected] |
Definition at line 294 of file baseserver.h.
References endian_swap().
{ endian_swap((unsigned long long &) x); }
void BaseServer::getNextTimeout | ( | int * | iSample, |
struct timeval * | timeout | ||
) | [protected] |
Calculate the time that is left until the next sampling time.
virtual int BaseServer::handle_timeout | ( | ) | [protected, virtual] |
void BaseServer::init | ( | FILE * | fout = stdout | ) |
Create the server socket.
void BaseServer::init_server | ( | int | fd1 = -1 , |
int | fd2 = -1 |
||
) |
Start server.
Additional file descriptors can be added to the select command.
void BaseServer::kill_server | ( | ) |
void BaseServer::monitor | ( | ) |
virtual int BaseServer::read_from_client | ( | int | filedes | ) | [protected, virtual] |
Defines the interface form the communication with the proxy process.
The protocol is define as follows:
Reimplemented in GpsServer, SimpleServer, and EventLoopClient.
virtual int BaseServer::read_from_keyboard | ( | ) | [protected, virtual] |
Server the keyboard in interactive mode.
Reimplemented in GpsServer, EventLoop, and EventLoopClient.
int BaseServer::readData | ( | int | client, |
unsigned long * | data, | ||
int | n | ||
) |
int BaseServer::readData | ( | int | client, |
unsigned int * | data, | ||
int | n | ||
) |
int BaseServer::readMsg | ( | int | client, |
char * | msg, | ||
int | n | ||
) |
int BaseServer::readPacket | ( | int | client, |
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.
void BaseServer::setConnectionLogging | ( | bool | logging = true | ) | [inline] |
Enable (default) or disable the connection logging.
Definition at line 105 of file baseserver.h.
References connLogging.
{ connLogging = logging; }
void BaseServer::setDebugLevel | ( | int | debug | ) |
void BaseServer::setPort | ( | unsigned short | port | ) | [protected] |
Set the port of the server.
This will only work before calling init().
void BaseServer::setTRef | ( | struct timeval * | time | ) |
Allows to set a common reference time, if more than one sampling tasks need to be synchronized.
virtual void BaseServer::show | ( | ) | [virtual] |
int BaseServer::writeData | ( | int | client, |
unsigned long * | data, | ||
int | n | ||
) |
int BaseServer::writeData | ( | int | client, |
unsigned int * | data, | ||
int | n | ||
) |
int BaseServer::writeMsg | ( | int | client, |
char * | msg, | ||
int | n = 0 |
||
) |
int BaseServer::writePacket | ( | int | client, |
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.
fd_set BaseServer::active_fd_set [protected] |
Set of the active sockets to be scanned by select.
Definition at line 216 of file baseserver.h.
fd_set BaseServer::change_byteorder_fd_set [protected] |
Set of all sockets where the byte order has to be switched.
Definition at line 220 of file baseserver.h.
bool BaseServer::connLogging [protected] |
Definition at line 332 of file baseserver.h.
Referenced by setConnectionLogging().
int BaseServer::debug [protected] |
Debug level, where 0 means less output and 1 or higher will produce more information.
Reimplemented in GpsServer, TsBackgroundLoop, KaEventLoop, and EventLoopClient.
Definition at line 178 of file baseserver.h.
FILE* BaseServer::fout [protected] |
File descriptor for the debug output and messages.
Reimplemented in TsBackgroundLoop.
Definition at line 209 of file baseserver.h.
int BaseServer::index [protected] |
Index of the actual sampling interval.
Definition at line 314 of file baseserver.h.
int BaseServer::lastIndex [protected] |
Index of the last handled sample.
Definition at line 320 of file baseserver.h.
int BaseServer::nSamples [protected] |
Number of timeouts (Counter)
Reimplemented in TsBackgroundLoop, and EventLoop.
Definition at line 317 of file baseserver.h.
unsigned short BaseServer::port [protected] |
Definition at line 301 of file baseserver.h.
bool BaseServer::shutdown [protected] |
Shutdown flag.
Can be set by any function and will terminate the server after the next loop.
Definition at line 213 of file baseserver.h.
SOCKET BaseServer::sock [protected] |
Definition at line 303 of file baseserver.h.
struct timeval BaseServer::tRef [protected] |
struct timeval BaseServer::tSample [protected] |
Time atom = sampling time.
Reimplemented in TsBackgroundLoop.
Definition at line 311 of file baseserver.h.
struct timeval BaseServer::ttimer [protected] |
Timeout value.
Contians the actal timeout time. The timer shows the remaining time until the timeout condition meets
Definition at line 328 of file baseserver.h.
struct timezone BaseServer::tZone [protected] |
Definition at line 308 of file baseserver.h.
bool BaseServer::useTimeout [protected] |
Definition at line 330 of file baseserver.h.