Index: ossp-pkg/l2/l2_ch_buffer.c RCS File: /v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/l2/l2_ch_buffer.c,v' 2>/dev/null --- l2_ch_buffer.c 2001/10/23 10:05:53 1.26 +++ l2_ch_buffer.c 2001/10/26 11:02:01 1.27 @@ -50,6 +50,60 @@ l2_level_t level; } l2_ch_buffer_t; +/* Sets the VIRTUAL timer to preconfigured value in cfg */ +static int set_alarm(l2_ch_buffer_t *cfg) +{ +#ifdef HAVE_INET_SETITIMER + struct itimerval valtest, valnew; + + /* initialize auto vars before using them */ + memset(&valnew, 0, sizeof(valnew)); + + valnew.it_interval.tv_sec = cfg->bufinterval; + valnew.it_interval.tv_usec = 0; + valnew.it_value.tv_sec = cfg->bufinterval; + valnew.it_value.tv_usec = 0; + if ((getitimer(L2_BUFFER_TIMER, &testval) == 0) && + ((testval.it_value.tv_sec | testval.it_value.tv_usec | + testval.it_interval.tv_sec | testval.it_interval.tv_usec) == 0)) + return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev); + else { + cfg->bufinterval = -1L; /* mark this timer as broken */ + assert(FALSE); + } +#else + unsigned int uiAlarmed = 0; + + uiAlarmed = alarm(cfg->bufinterval); + if (uiAlarmed) { /* check if SIGALRM is occupied */ + alarm(uiAlarmed); /* ...if so, then hack in the old value */ + cfg->bufinterval = -1L; /* ...mark this timer as broken */ + assert(FALSE); /* ...and warn the user about problems */ + } + return 0; +#endif +} + +/* Resets the VIRTUAL timer to preconfigured value in cfg */ +static int reset_alarm(l2_ch_buffer_t *cfg) +{ +#ifdef HAVE_INET_SETITIMER + struct itimerval valnew; + + /* initialize auto vars before using them */ + memset(&valnew, 0, sizeof(valnew)); + + valnew.it_interval.tv_sec = cfg->bufinterval; + valnew.it_interval.tv_usec = 0; + valnew.it_value.tv_sec = cfg->bufinterval; + valnew.it_value.tv_usec = 0; + return setitimer(L2_BUFFER_TIMER, &valnew, 0); +#else + alarm(cfg->bufinterval); + return 0; +#endif +} + static void catchsignal(int sig, ...) { va_list ap; @@ -120,66 +174,6 @@ return rv; } -/************************************************************ - * set_alarm: Helper method to hook_open * - * Sets the VIRTUAL timer to preconfigured value in cfg * - ************************************************************/ -static int set_alarm(l2_ch_buffer_t *cfg) -{ -#ifdef HAVE_INET_SETITIMER - struct itimerval valtest, valnew; - - /* initialize auto vars before using them */ - memset(&valnew, 0, sizeof(valnew)); - - valnew.it_interval.tv_sec = cfg->bufinterval; - valnew.it_interval.tv_usec = 0; - valnew.it_value.tv_sec = cfg->bufinterval; - valnew.it_value.tv_usec = 0; - if ((getitimer(L2_BUFFER_TIMER, &testval) == 0) && - ((testval.it_value.tv_sec | testval.it_value.tv_usec | - testval.it_interval.tv_sec | testval.it_interval.tv_usec) == 0)) - return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev); - else { - cfg->bufinterval = -1L; /* mark this timer as broken */ - assert(FALSE); - } -#else - unsigned int uiAlarmed = 0; - - uiAlarmed = alarm(cfg->bufinterval); - if (uiAlarmed) { /* check if SIGALRM is occupied */ - alarm(uiAlarmed); /* ...if so, then hack in the old value */ - cfg->bufinterval = -1L; /* ...mark this timer as broken */ - assert(FALSE); /* ...and warn the user about problems */ - } - return 0; -#endif -} - -/************************************************************ - * reset_alarm: Helper method to hook_flush * - * Resets the VIRTUAL timer to preconfigured value in cfg * - ************************************************************/ -static int reset_alarm(l2_ch_buffer_t *cfg) -{ -#ifdef HAVE_INET_SETITIMER - struct itimerval valnew; - - /* initialize auto vars before using them */ - memset(&valnew, 0, sizeof(valnew)); - - valnew.it_interval.tv_sec = cfg->bufinterval; - valnew.it_interval.tv_usec = 0; - valnew.it_value.tv_sec = cfg->bufinterval; - valnew.it_value.tv_usec = 0; - return setitimer(L2_BUFFER_TIMER, &valnew, 0); -#else - alarm(cfg->bufinterval); - return 0; -#endif -} - /* open channel */ static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch) {