$Revision: 1.62 $
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
#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_whois_sock
int SV_config_sock
int SV_mirror_sock
int SV_update_sock[100]
int SV_shutdown_send_fd
int SV_shutdown_recv_fd
Server starting time
time_t SV_starttime
char* SV_pidfile
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
int SV_start ( char* pidfile )
Prototyped in:
| /home/shane/code/RIP/include/server.h
|
Calls:
| AC_acc_load() | ac/access_control.c
|
| AC_build() | ac/access_control.c
|
| ER_inf_va() | er/er.c
|
| ER_perror() | er/er.c
|
| PW_init() | pw/protocol_whois.c
|
| SK_getsock() | sk/sk_socket.c
|
| SK_init() | sk/cd_watchdog.c
|
| SQ_close_connection() | sq/mysql_driver.c
|
| SQ_get_connection() | sq/mysql_driver.c
|
| SV_concurrent_server() | sv/server.c
|
| ca_get_SourceHandleByPosition() | ca/ca_configFns.c
|
| ca_get_int() | ca/ca_configFns.c
|
| ca_srchandle2Intelement() | ca/ca_configFns.c
|
| ca_srchandle2Strelement() | ca/ca_configFns.c
|
| ctime_r() | aa/aa.c
|
| radix_init() | sv/server.c
|
| radix_load() | sv/server.c
|
| TH_create(), TR_recover(), UT_free_real(), ___errno(), fdwrap_close(), fprintf(), getpid(), gettimeofday(), open(), pipe(), printf(), pthread_exit(), sprintf(), strerror(), strlen(), write()
|
References Functions:
| AC_decay() | ac/access_control.c
|
| PC_interact() | pc/protocol_config.c
|
| PM_interact() | pm/protocol_mirror.c
|
| PW_interact() | pw/protocol_whois.c
|
| UD_do_nrtm(), UD_do_updates()
|
References Variables:
| SV_config_sock | sv/server.c
|
| SV_mirror_sock | sv/server.c
|
| SV_pidfile | sv/server.c
|
| SV_shutdown_recv_fd | sv/server.c
|
| SV_shutdown_send_fd | sv/server.c
|
| SV_starttime | sv/server.c
|
| SV_update_sock | sv/server.c
|
| SV_whois_sock | sv/server.c
|
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;
static char* asctime_r ( const struct tm* __tm, char* __buf )
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 char* ctime_r ( const time_t* __time, char* __buf )
static int getlogin_r ( char* __name, int __len )
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.
Calls:
| CO_get_do_server() | co/constants.c
|
| ER_dbg_va() | er/er.c
|
| ER_perror() | er/er.c
|
| SK_accept_connection() | sk/sk_socket.c
|
| counter_add() | sv/server.c
|
| counter_wait() | sv/server.c
|
| TA_add(), TA_delete(), TA_increment(), TA_setactivity(), TH_create(), UT_malloc_real(), ___errno(), memcpy(), poll(), snprintf(), strerror()
|
Used in:
| SV_concurrent_server() | sv/server.c
|
References Functions:
| SV_do_child() | sv/server.c
|
References Variables:
| SV_shutdown_recv_fd | sv/server.c
|
Initialize the radix tree - all trees are added to the forest in
a locked state. As each tree finishes loading (from radix_load()),
it is unlocked.
static void radix_init ( void )
Load the radix tree - all trees are initialized from the appropriate
SQL tables. As each tree finishes loading (from radix_load()), it is
unlocked. They must be created by the radix_init() function.
static void radix_load ( void )
static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
static int sigwait ( const sigset_t* __setp, int* __signo )
static int ttyname_r ( int __fildes, char* __buf, size_t __size )