$Revision: 1.4 $
Socket module - cd_watchdog.c - Socket watchdog - when activated, checks the
socket for new data and discards it. If the
socket is closed, it triggers predefined
functions - executes a function and/or
cancels a thread.
Status: NOT REVUED, TESTED
Design and implementation by Marek Bukowy.
Modification history:
marek (August 2000) Created the watchdog part
marek (December 2000) Modified watchdog deactivation -
replaced signals by pthread cancellation.
Included Files
- #include "modules/sk/sk.h"
- #include "include/stubs.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <pthread.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <stdio.h>
- #include "include/iproutines.h"
- #include <sys/types.h>
- #include <glib.h>
- #include <include/inet6def.h>
- #include <include/erroutines.h>
Preprocessor definitions
String sizes
#define STR_S 63
Local Variables
sk_init_once
Uncomment this to use watchdog deactivation by signal (may be risky)
#define WATCHDOG_BY_SIGNAL
static pthread_once_t sk_init_once
Initialisation function, should be called exactly once
(well, it ignores repeated calls). The actions depend on cancellation
mode (signal or pthread_cancel).
void SK_init ( void )
void SK_watch_setclear ( sk_conn_st* condat )
- sk_conn_st* condat
- pointer to the connection data structure.
void SK_watch_setexec ( sk_conn_st* condat, void* (*function)(void*), void* args )
- sk_conn_st* condat
- pointer to the connection data structure.
- void* (*function)(void*)
- function to be invoked
- void* args
- argument to be passed to the function.
void SK_watch_setkill ( sk_conn_st* condat, pthread_t killthis )
- sk_conn_st* condat
- pointer to the connection data structure.
- pthread_t killthis
- thread id of the thread to be cancelled, or 0.
void SK_watchexec ( sk_conn_st* condat )
- sk_conn_st* condat
- pointer to the connection data structure.
void SK_watchkill ( sk_conn_st* condat )
- sk_conn_st* condat
- pointer to the connection data structure.
starts sk_watchdog thread unless already started,
and registers its threadid in the condat structure
dies if watchdog already running
The structure may (and normally, should) contain the predefined actions
set by SK_watch_set... functions.
er_ret_t SK_watchstart ( sk_conn_st* condat )
- er_ret_t SK_watchstart
- Returns SK_OK on success.
- sk_conn_st* condat
- pointer to the connection data structure
stops running sk_watchdog thread.
If it is not running ( == not registered in the connection struct),
it does nothing.
er_ret_t SK_watchstop ( sk_conn_st* condat )
- er_ret_t SK_watchstop
- always succeeds (returns SK_OK)
- sk_conn_st* condat
- pointer to the connection data structure
void SK_watchtrigger ( sk_conn_st* condat )
- sk_conn_st* condat
- pointer to the connection data structure.
initialisation for the PTHREAD_CANCEL mode is not needed.
static void sk_real_init ( void )
watchdog (CANCEL VERSION) - started as a separate thread.
Selects on the given socket; discards all input.
whenever it sees end of file (socket closed), it
* sets a corresponding flag in the condat structure,
* triggers the predefined actions (by SK_watchtrigger).
static void* sk_watchdog ( void* arg )
- void* arg
- - pointer to the connection data structure