$Revision: 1.54 $
Example code: A server for a client to connect to.
Status: NOT REVUED, NOT TESTED
Authors: Chris Ottrey, Joao Damas,
heavy rewrite by Andrei Robachevsky, Marek Bukowy
- Online References:
-
Included Files
Preprocessor definitions
String sizes
#define STR_S 63
#define STR_M 255
#define STR_L 1023
#define STR_XL 4095
#define STR_XXL 16383
#define MAX_SOURCES 100
typedef struct {...} svr_counter_t
struct |
|
{ |
|
int count; |
|
pthread_mutex_t lock; | Mutex lock.Used for synchronizing changes.
|
pthread_cond_t cond; | condition variable
|
} |
|
typedef struct {...} svr_args
struct |
|
{ |
|
void (*function)(int); |
|
int conn_sock; |
|
int accept_sock; |
|
int limit; |
|
svr_counter_t* counter; |
|
char* name; |
|
} |
|
pthread_mutex_t Lock
int sv_lockfd[4]
int SV_whois_sock
int SV_config_sock
int SV_mirror_sock
int SV_update_sock[100]
Server starting time
time_t SV_starttime
Handle whois/config/mirror connections. Takes a pointer to the
service description structure, containing a connected socket, limit
of active threads, pointer to the counter of them. Does not stop to
obey the limits, assumes this to be checked and assumes that it is
already counted. Decrements the counter on exit.
Precondition: the counter must be incremented before this function is called.
Author:
marek
void* SV_do_child ( void* varg )
- void* SV_do_child
- Actually, does not return anything useful. Just NULL.
- void* varg
- service description structure.
Shutdown the server.
More:
Authors:
andrei
Stops the server.
- Close listening sockets (whois, config, mirror and updates)
- Stop all threads by triggering do_server variable.
.properties
void SV_shutdown ( void )
Handle signals.
Changes the flags:
do_nrtm
do_update
do_whoisd
More:
Author:
andrei
void* SV_signal_thread ( void )
int SV_sleep ( int delay )
Start the server.
More:
Authors:
ottrey
joao
Starts up the server.
- Create sockets on the necessary ports (whois, config and mirror)
- Start new threads for each service.
.properties
void SV_start ( void )
Prototyped in:
| modules/sv/server.h
|
Calls:
| AC_acc_load() | modules/ac/access_control.c
|
| AC_build() | modules/ac/access_control.c
|
| ER_inf_va() | modules/er/er.c
|
| SK_getsock() | modules/sk/sk_socket.c
|
| SK_init() | modules/sk/cd_watchdog.c
|
| SQ_close_connection() | modules/sq/mysql_driver.c
|
| SQ_get_connection() | modules/sq/mysql_driver.c
|
| SV_concurrent_server() | modules/sv/server.c
|
| ca_get_SourceHandleByPosition() | modules/ca/ca_configFns.c
|
| ca_get_int() | modules/ca/ca_configFns.c
|
| ca_srchandle2Intelement() | modules/ca/ca_configFns.c
|
| ca_srchandle2Strelement() | modules/ca/ca_configFns.c
|
| TH_create(), TR_recover(), ctime_r(), exit(), fprintf(), free(), gettimeofday(), pipe(), printf(), pthread_exit()
|
References Functions:
| AC_decay() | modules/ac/access_control.c
|
| PC_interact() | modules/pc/protocol_config.c
|
| PM_interact() | modules/pm/protocol_mirror.c
|
| PW_interact() | modules/pw/protocol_whois.c
|
| radix_init() | modules/sv/server.c
|
| UD_do_nrtm(), UD_do_updates()
|
References Variables:
| SV_config_sock | modules/sv/server.c
|
| SV_mirror_sock | modules/sv/server.c
|
| SV_starttime | modules/sv/server.c
|
| SV_update_sock | modules/sv/server.c
|
| SV_whois_sock | modules/sv/server.c
|
| sv_lockfd | modules/sv/server.c
|
Loading the radix tree. Started as a separate thread.
Author:
marek
void radix_init ( void )
This is the routine that creates the main threads.
void * do_function The function to call for each type of service
More:
Author:
ottrey
joao
marek
static void SV_concurrent_server ( int sock, int limit, char* name, void do_function(int) )
- int sock
- The socket to connect to.
- int limit
- Limit of active clients (0 == no limit)
- char* name
- &nbs;
- void do_function(int)
- &nbs;
function to operate on the counter structures -
takes the increment (can be negative), changes the value
using the locks and everything,
int
counter_add returns the new value.
Author:
marek
static int counter_add ( svr_counter_t* cst, int incval )
- svr_counter_t* cst
- counter structure
- int incval
- increment value (can be negative)
int
counter_state returns the current value of a counter
Author:
marek
static int counter_state ( svr_counter_t* cst )
- svr_counter_t* cst
- counter
waits until the counter is in the range [0-limit].
unless the limit is 0, in which case the check is disabled.
Author:
marek
static int counter_wait ( svr_counter_t* cst, int limit )
- int counter_wait
- returns the new value of the counter after wait
- svr_counter_t* cst
- counter
- int limit
- limit / range, or 0 to disable the check
static void log_print ( const char* arg )
Waits for an incoming connection on the and spawns a new thread to
handle it. Takes a pointer to the service description structure
containing the number of the listening socket, limit of active
threads, pointer to the counter of them, and the function to call
with a connected socket. Increments the counter before starting
a client thread to run SV_do_child().
More:
Author:
ottrey
joao
andrei (do_server)
marek (rewritten/simplified/added limits)
static void* main_loop ( void* arg )
- void* arg
- pointer to the service description structure.