$Revision: 1.36 $
Example code: A server for a client to connect to.
Status: NOT REVUED, NOT TESTED
Authors: Chris Ottrey, Joao Damas
- Online References:
-
Included Files
- #include "include/rxroutines.h"
- #include <glib.h>
- #include <pthread.h>
- #include <include/stubs.h>
- #include <include/memwrap.h>
- #include <stdio.h>
- #include <include/iproutines.h>
- #include <erroutines.h>
- #include "include/socket.h"
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <netdb.h>
- #include <signal.h>
- #include <stdio.h>
- #include <iproutines.h>
- #include "include/thread.h"
- #include "include/ta.h"
- #include <glib.h>
- #include <pthread.h>
- #include <stubs.h>
- #include <memwrap.h>
- #include <stdio.h>
- #include <include/socket.h>
- #include <include/timediff.h>
Preprocessor definitions
#define RIPE_REG 17
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
pthread_mutex_t Lock
char newPort[16]
int sv_lockfd[4]
int SV_whois_sock
int SV_config_sock
int SV_mirror_sock
int SV_update_sock[100]
Mutex lock. Used for synchronizing changes.
pthread_mutex_t Whois_thread_count_lock
pthread_mutex_t Config_thread_count_lock
pthread_mutex_t Mirror_thread_count_lock
The number of threads.
int Whois_thread_count
int Config_thread_count
int Mirror_thread_count
Server starting time
time_t SV_starttime
This is the routine that creates the main threads.
More:
Author:
ottrey
joao
void SV_concurrent_server ( int sock, void* do_function(void*) )
- int sock
- The socket to connect to.
void * do_function The function to call for each type of service
- void* do_function(void*)
- &nbs;
Handle config connections.
More:
Author:
joao
void* SV_do_config ( void* arg )
- void* arg
- The socket to connect to. (It has to be passed in this way for this
thread routine.)
Handle NRTM connections.
More:
Author:
joao
void* SV_do_mirror ( void* arg )
- void* arg
- The socket to connect to. (It has to be passed in this way for this thread routine.)
Handle whois connections.
More:
Author:
joao
void* SV_do_whois ( void* arg )
- void* arg
- The socket to connect to. (It has to be passed in this way for this thread routine.)
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 )
Sleep and wake up on special events.
More:
Authors:
andrei
Sleeps timeout but wakes up when an envent occures.
int SV_sleep ( int lock, int sleeptime )
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 )
This is the routine that creates a watchdog thread.
The watchdog will cancel (pthread_cancel()) the calling thread in case the
socket is closed by the client (its read-half is closed). The calling
thread should make necessaruy preparations when calling the watchdog:
- the socket should be connected
- cancellation points and cleanup routines should be defined
In case the connection is closed by the calling thread itself, the
watchdog just exits and no action against the calling thread is performed.
wd_args - a pointer to wd_args_t structure containing
data about socket and thread ID
More:
Author:
ottrey
joao
andrei
void SV_watchdog ( wd_args_t* wd_args )
void radix_init ( void )
The watchdog thread itself
The watchdog thread makes select() on the connected socket waiting until it
becomes readable. If this happens as a result of some input, it'll simply
dump it. Otherwise, this indicates that the client has closed the
connection. In this case watchdog will cancel (pthread_cancel()) the whois
thread (which in its turn will kill (mysql_kill()) mysql thread as part of
its cleanup routine).
More:
Author:
andrei
static void do_watchdog ( void* arg )
static void log_print ( const char* arg )
Waits for an incoming connection on the and spawns a new thread to handle it.
More:
Author:
ottrey
joao
andrei (do_server)
static void* main_loop ( void* arg )
- void* arg
- Pointer to a struct containing the socket to talk to the client and
the function to call depending on the incoming connection.