--- l2_ch_buffer.c 2001/10/05 14:25:57 1.23
+++ l2_ch_buffer.c 2001/10/12 14:46:17 1.24
@@ -28,11 +28,13 @@
*/
#include "l2.h"
-#include "l2_p.h" /* for TRACE() */
+#include "l2_p.h" /* for TRACE() */
#include <string.h>
-#include <unistd.h> /* has setitime() in standard unix functions */
-#include <signal.h> /* for use of sigaction() and SIGALRM */
+#include <unistd.h> /* for alarm() and setitime() */
+#include <signal.h> /* for use of sigaction() and SIGALRM */
+
+#define L2_BUFFER_TIMER ITIMER_REAL /* calls to [s|g]etitimer() and alarm() */
/* declare private channel configuration */
typedef struct {
@@ -41,7 +43,9 @@
int bufsize;
int bufinterval;
struct sigaction sigalrm;
+#ifdef HAVE_SETITIMER
struct itimerval valprev;
+#endif
int levelflush;
l2_level_t level;
} l2_ch_buffer_t;
@@ -79,7 +83,9 @@
cfg->levelflush = 0;
cfg->level = L2_LEVEL_NONE;
memset(&cfg->sigalrm, 0, sizeof(cfg->sigalrm));
+#ifdef HAVE_SETITIMER
memset(&cfg->valprev, 0, sizeof(cfg->valprev));
+#endif
/* link private channel configuration into channel context */
ctx->vp = cfg;
@@ -112,6 +118,7 @@
************************************************************/
static int set_alarm(l2_ch_buffer_t *cfg)
{
+#ifdef HAVE_INET_SETITIMER
struct itimerval valnew;
/* initialize auto vars before using them */
@@ -121,7 +128,10 @@
valnew.it_interval.tv_usec = 0;
valnew.it_value.tv_sec = cfg->bufinterval;
valnew.it_value.tv_usec = 0;
- return setitimer(ITIMER_REAL, &valnew, &cfg->valprev); /* set flush timer */
+ return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev);
+#else
+ return 0;
+#endif
}
/************************************************************
@@ -130,6 +140,7 @@
************************************************************/
static int reset_alarm(l2_ch_buffer_t *cfg)
{
+#ifdef HAVE_INET_SETITIMER
struct itimerval valnew;
/* initialize auto vars before using them */
@@ -139,7 +150,10 @@
valnew.it_interval.tv_usec = 0;
valnew.it_value.tv_sec = cfg->bufinterval;
valnew.it_value.tv_usec = 0;
- return setitimer(ITIMER_REAL, &valnew, 0); /* reset flush timer */
+ return setitimer(L2_BUFFER_TIMER, &valnew, 0);
+#else
+ return 0;
+#endif
}
/* open channel */
@@ -256,8 +270,13 @@
l2_result_t rv;
if (cfg->bufinterval != 0) {
- setitimer(ITIMER_REAL, &cfg->valprev, 0); /* restore timer values */
- /* restore previous signal context if previously saved & replaced */
+#ifdef HAVE_INET_SETITIMER
+ if (setitimer(L2_BUFFER_TIMER, &cfg->valprev, 0)) /* restore timer */
+ return L2_ERR_SYS;
+#else
+ alarm(0);
+#endif
+ /* restore previous signal context if previously saved & replaced */
if (&cfg->sigalrm.sa_handler)
if (sigaction(SIGALRM, &cfg->sigalrm, 0) < 0)
rv = L2_ERR_SYS;
|