File modules/th/thread.c

  $Revision: 1.3 $

Example code: A thread.
Status: NOT REVUED, NOT TESTED
Authors: Chris Ottrey Joao Damas
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


Typedef th_args

typedef struct th_args th_args
struct th_args 
   { 
     void* function; 
     int sock; 
   } 

Global Variable Whois_thread_count_lock

Mutex lock. Used for synchronizing changes.

pthread_mutex_t Whois_thread_count_lock
Visible in:  modules/th/thread.c
Used in: TH_do_whois()modules/th/thread.c


Global Variable Config_thread_count_lock

pthread_mutex_t Config_thread_count_lock
Visible in:  modules/th/thread.c

Global Variable Mirror_thread_count_lock

pthread_mutex_t Mirror_thread_count_lock
Visible in:  modules/th/thread.c

Global Variable Whois_thread_count

The number of threads.

int Whois_thread_count
Visible in:  modules/th/thread.c
Used in: TH_do_whois()modules/th/thread.c


Global Variable Config_thread_count

int Config_thread_count
Visible in:  modules/th/thread.c

Global Variable Mirror_thread_count

int Mirror_thread_count
Visible in:  modules/th/thread.c

Global Function TH_do_config()

  Handle config connections.

More:
  Author:
        joao
void TH_do_config ( void* arg )
void* arg
The socket to connect to. (It has to be passed in this way for this thread routine.)
Calls: PC_interact()modules/pc/protocol_config.c
  log_print()modules/sk/socket.c
  pthread_exit(), pthread_self(), sprintf(), strcpy()
Used in: SV_start()modules/sv/server.c

Global Function TH_do_whois()

  Handle whois connections.

More:
  Author:
        joao
void TH_do_whois ( void* arg )
void* arg
The socket to connect to. (It has to be passed in this way for this thread routine.)
Calls: PW_interact()modules/pw/protocol_whois.c
  log_print()modules/sk/socket.c
  pthread_exit(), pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self(), sprintf(), strcpy()
Used in: SV_start()modules/sv/server.c
References Variables: Whois_thread_countmodules/th/thread.c
  Whois_thread_count_lockmodules/th/thread.c

Global Function TH_get_id()

int TH_get_id ( void )
Calls: pthread_self()
Called by: log_config()modules/pc/protocol_config.c

Global Function TH_run()

  This is the routine that creates the main threads. 

More:
  Author:
        ottrey
	joao
void TH_run ( int sock, void* do_function )
int sock
The socket to connect to. void * do_function The function to call for each type of service
void* do_function
 
Calls: CO_get_max_threads()modules/co/constants.c
  PW_interact()modules/pw/protocol_whois.c
  SK_accept_connection()modules/sk/socket.c
  log_print()modules/sk/socket.c
  calloc(), pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create(), sprintf(), strcpy()
Called by: SV_start()modules/sv/server.c
References Functions: main_thread()modules/th/thread.c

Global Function TH_to_string()

char* TH_to_string ( void )
Calls: calloc(), pthread_self(), sprintf(), strcat(), strcpy(), strlen()
Called by: show_thread()modules/pc/protocol_config.c

Local Function log_print()

static void log_print ( const char* arg )
Calls: CO_get_thread_logfile()modules/co/constants.c
  CO_get_thread_logging()modules/co/constants.c
  fclose(), fopen(), fprintf(), printf(), strcmp()
Called by: TH_do_config()modules/th/thread.c
  TH_do_whois()modules/th/thread.c
  TH_run()modules/th/thread.c

Local Function main_thread()

  Waits for an incoming connection on the and spawns a new thread to handle it.

More:
  Author:
        ottrey
	joao
static void* main_thread ( 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.
Calls: SK_accept_connection()modules/sk/socket.c
  pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create()
Used in: TH_run()modules/th/thread.c