Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

poslib/server/serverthread.h File Reference

server thread functions More...

Go to the source code of this file.


Classes

class   ServerSocket
  server socket type More...


Enumerations

enum   sstype { ss_udp, ss_tcp, ss_client }

Functions

void  udpsock_handledata (int sockid)
  Handles data from an UDP server socket.

void  tcpsock_handledata (int sockid)
  Handles data from a TCP server socket.

void  clientsock_handledata (int sockid)
  Handles data from an UDP client socket.

  stl_slist (ServerSocket) servers
  stl_slist (PendingAnswerUDP) pending_answers
int  getclientsockid (_addr *a)
void *  serverthread (void *arg)
void  posserver_init_srvresolver ()
  Initialize server resolver system.

void  posserver_startback ()
  Start server in the background.

void  posserver_run ()
  Start server in the foreground.

void  posserver_stop ()
  Stop the Posadis server.


Variables

pthread_mutex_t  m_servers
pthread_mutex_t  m_pending_answers
pthread_cond_t  c_data_received
int  udp_client_socket
int  udp_client_socket_6
bool(*  allow_tcp_connection )(_addr *a, int ntcp)
  check whether to allow TCP connections

int  n_threads
  Current number of threads.

void(*  user_cleanup_function )(void)
  cleanup function


Detailed Description

server thread functions

Properties for server sockets.

Definition in file serverthread.h.


Enumeration Type Documentation

enum sstype
 

Socket type

Enumeration values:
ss_udp  UDP server socket.
ss_tcp  TCP server socket.
ss_client  UDP client socket.

Definition at line 39 of file serverthread.h.


Function Documentation

int getclientsockid _addr a  ) 
 

Gets UDP client socket appropriate for the given address.

void posserver_init_srvresolver  ) 
 

Initialize server resolver system.

This initializes the server resolver system used by pos_srvresolver. This might become obsolete in future Poslib releases.

void posserver_run  ) 
 

Start server in the foreground.

Starts the Posadis server in the foreground. This function does not return until posserver_stop() is called.

See also:
posserver_startback(), posserver_stop()

void posserver_startback  ) 
 

Start server in the background.

Starts the Posadis server thread in the background, returning immediately.

See also:
posserver_run(), posserver_stop()

void posserver_stop  ) 
 

Stop the Posadis server.

Stops the Posadis server. This might take some time because it has to wait until all threads are stopped. This will also close down all sockets Poslib listens to, and clear the servers list.

See also:
posserver_startback, posserver_run()

void* serverthread void *  arg  ) 
 

The main server thread function.

stl_slist PendingAnswerUDP   ) 
 

List of pending answers. Internal - no need to edit.

stl_slist ServerSocket   ) 
 

List of sockets the server should listen on. Protected by m_servers.


Variable Documentation

bool(* allow_tcp_connection)(_addr *a, int ntcp)
 

check whether to allow TCP connections

Every time a TCP connection is opened, this function is run to check whether we are willing to provide TCP connectivity to the given client, given the number of TCP processes already active. If the function returns true, the connection is allowed and a new thread is created to handle it. If, on the other hand, it returns false, the connection is closed down directly. The defalt implementation is to allow a TCP connection if n_threads is smaller than max_threads. This function is run with the m_servers mutex locked.

Parameters:
a  Client trying to connect
ntcp  Current number of TCP connections

Definition at line 114 of file serverthread.h.

pthread_cond_t c_data_received
 

Condition for receiving data on a UDP client socket.

Definition at line 92 of file serverthread.h.

pthread_mutex_t m_pending_answers
 

Mutex for the #pending_answers list.

Definition at line 87 of file serverthread.h.

pthread_mutex_t m_servers
 

Mutex for the #server list.

Definition at line 78 of file serverthread.h.

int n_threads
 

Current number of threads.

The number of currently active threads. Locked by the m_servers mutex.

Definition at line 121 of file serverthread.h.

int udp_client_socket
 

UDP client socket.

Definition at line 94 of file serverthread.h.

int udp_client_socket_6
 

UDP client socket (IPv6);

Definition at line 95 of file serverthread.h.

void(* user_cleanup_function)(void)
 

cleanup function

This is a function to a user function that will be called every once in a while (currently every 5 minutes), that can perform cleanup tasks that take very little time, so that you won't need a separate thread for that. Poslib itself executes a function which cleans up request IDs at this interval, and you can add your own user function to make that be called as well.

And I'm going to repeat this: make sure your cleanup function uses very little time because it is executed in the main server thread. This means that while your function is running, new queries will not be answered.

Definition at line 137 of file serverthread.h.


Generated on Fri Dec 24 19:55:15 2004 for Poslib by doxygen 1.3.7