Deleted Added
full compact
common.c (131823) common.c (135923)
1/*
2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
5 *
6 * Author: Harti Brandt <harti@freebsd.org>
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 30 unchanged lines hidden (view full) ---

39#include <string.h>
40#include <errno.h>
41#include <unistd.h>
42#include <time.h>
43#include <signal.h>
44#include <assert.h>
45#include <fcntl.h>
46#include <err.h>
1/*
2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
5 *
6 * Author: Harti Brandt <harti@freebsd.org>
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 30 unchanged lines hidden (view full) ---

39#include <string.h>
40#include <errno.h>
41#include <unistd.h>
42#include <time.h>
43#include <signal.h>
44#include <assert.h>
45#include <fcntl.h>
46#include <err.h>
47#include <isc/eventlib.h>
48
49#include <netnatm/unimsg.h>
50#include <netnatm/saal/sscop.h>
51#include "common.h"
52
53struct timer {
54 evTimerID id;
55 struct sscop *sscop;
56 void (*func)(void *);
57};
58
59int useframe;
60int sscopframe;
61u_int sscop_vflag;
62int sscop_fd;
63int user_fd;
64int loose;
65int user_out_fd;
66u_int verbose;
47
48#include <netnatm/unimsg.h>
49#include <netnatm/saal/sscop.h>
50#include "common.h"
51
52struct timer {
53 evTimerID id;
54 struct sscop *sscop;
55 void (*func)(void *);
56};
57
58int useframe;
59int sscopframe;
60u_int sscop_vflag;
61int sscop_fd;
62int user_fd;
63int loose;
64int user_out_fd;
65u_int verbose;
66#ifndef USE_LIBBEGEMOT
67evContext evctx;
67evContext evctx;
68#endif
68evFileID sscop_h;
69evFileID user_h;
70
71/*
72 * This function get's called from sscop to put out verbose messages
73 */
74void
75sscop_verbose(struct sscop *sscop __unused, void *u __unused,

--- 72 unchanged lines hidden (view full) ---

148 err(1, NULL);
149 if ((size = read(sscop_fd, m->b_rptr, MAXMSG)) == -1)
150 err(1, "error reading message");
151 got = size;
152 }
153
154 if (got == 0) {
155 eof:
69evFileID sscop_h;
70evFileID user_h;
71
72/*
73 * This function get's called from sscop to put out verbose messages
74 */
75void
76sscop_verbose(struct sscop *sscop __unused, void *u __unused,

--- 72 unchanged lines hidden (view full) ---

149 err(1, NULL);
150 if ((size = read(sscop_fd, m->b_rptr, MAXMSG)) == -1)
151 err(1, "error reading message");
152 got = size;
153 }
154
155 if (got == 0) {
156 eof:
157#ifdef USE_LIBBEGEMOT
158 poll_unregister(sscop_h);
159#else
156 evDeselectFD(evctx, sscop_h);
160 evDeselectFD(evctx, sscop_h);
161#endif
157 (void)close(sscop_fd);
158 sscop_fd = -1;
159 if (m != NULL)
160 uni_msg_destroy(m);
161 VERBOSE(("EOF on sscop file descriptor"));
162 return (NULL);
163 }
164 m->b_wptr = m->b_rptr + got;

--- 42 unchanged lines hidden (view full) ---

207 err(1, NULL);
208 if ((size = read(user_fd, m->b_rptr, MAXMSG)) == -1)
209 err(1, "error reading message");
210 got = size;
211 }
212
213 if (size == 0) {
214 eof:
162 (void)close(sscop_fd);
163 sscop_fd = -1;
164 if (m != NULL)
165 uni_msg_destroy(m);
166 VERBOSE(("EOF on sscop file descriptor"));
167 return (NULL);
168 }
169 m->b_wptr = m->b_rptr + got;

--- 42 unchanged lines hidden (view full) ---

212 err(1, NULL);
213 if ((size = read(user_fd, m->b_rptr, MAXMSG)) == -1)
214 err(1, "error reading message");
215 got = size;
216 }
217
218 if (size == 0) {
219 eof:
220#ifdef USE_LIBBEGEMOT
221 poll_unregister(user_h);
222#else
215 evDeselectFD(evctx, user_h);
223 evDeselectFD(evctx, user_h);
224#endif
216 if (m != NULL)
217 uni_msg_destroy(m);
218 VERBOSE(("EOF on user connection"));
219 return (NULL);
220 }
221 m->b_wptr = m->b_rptr + size;
222
223 return (m);

--- 155 unchanged lines hidden (view full) ---

379 errx(1, "bad parameter '%s'", arg);
380 return;
381 }
382
383 verb("bad flag");
384 abort();
385}
386
225 if (m != NULL)
226 uni_msg_destroy(m);
227 VERBOSE(("EOF on user connection"));
228 return (NULL);
229 }
230 m->b_wptr = m->b_rptr + size;
231
232 return (m);

--- 155 unchanged lines hidden (view full) ---

388 errx(1, "bad parameter '%s'", arg);
389 return;
390 }
391
392 verb("bad flag");
393 abort();
394}
395
396#ifdef USE_LIBBEGEMOT
387static void
397static void
398tfunc(int tid __unused, void *uap)
399#else
400static void
388tfunc(evContext ctx __unused, void *uap, struct timespec due __unused,
389 struct timespec inter __unused)
401tfunc(evContext ctx __unused, void *uap, struct timespec due __unused,
402 struct timespec inter __unused)
403#endif
390{
391 struct timer *t = uap;
392
393 t->func(t->sscop);
394 free(t);
395}
396
397/*
398 * Start a timer
399 */
400void *
401sscop_start_timer(struct sscop *sscop, void *arg __unused, u_int msec,
402 void (*func)(void *))
403{
404 struct timer *t;
404{
405 struct timer *t = uap;
406
407 t->func(t->sscop);
408 free(t);
409}
410
411/*
412 * Start a timer
413 */
414void *
415sscop_start_timer(struct sscop *sscop, void *arg __unused, u_int msec,
416 void (*func)(void *))
417{
418 struct timer *t;
419#ifndef USE_LIBBEGEMOT
405 struct timespec due;
420 struct timespec due;
421#endif
406
407 if ((t = malloc(sizeof(*t))) == NULL)
408 err(1, NULL);
409 t->sscop = sscop;
410 t->func = func;
411
422
423 if ((t = malloc(sizeof(*t))) == NULL)
424 err(1, NULL);
425 t->sscop = sscop;
426 t->func = func;
427
428#ifdef USE_LIBBEGEMOT
429 if ((t->id = poll_start_timer(msec, 0, tfunc, t)) == -1)
430 err(1, "cannot start timer");
431#else
412 due = evAddTime(evNowTime(),
413 evConsTime((time_t)msec/1000, (long)(msec%1000)*1000));
414
415 if (evSetTimer(evctx, tfunc, t, due, evConsTime(0, 0), &t->id))
416 err(1, "cannot start timer");
432 due = evAddTime(evNowTime(),
433 evConsTime((time_t)msec/1000, (long)(msec%1000)*1000));
434
435 if (evSetTimer(evctx, tfunc, t, due, evConsTime(0, 0), &t->id))
436 err(1, "cannot start timer");
437#endif
417
418 return (t);
419}
420
421/*
422 * Stop a timer
423 */
424void
425sscop_stop_timer(struct sscop *sscop __unused, void *arg __unused, void *tp)
426{
427 struct timer *t = tp;
428
438
439 return (t);
440}
441
442/*
443 * Stop a timer
444 */
445void
446sscop_stop_timer(struct sscop *sscop __unused, void *arg __unused, void *tp)
447{
448 struct timer *t = tp;
449
450#ifdef USE_LIBBEGEMOT
451 poll_stop_timer(t->id);
452#else
429 evClearTimer(evctx, t->id);
453 evClearTimer(evctx, t->id);
454#endif
430 free(t);
431}
455 free(t);
456}