Place files back on the vendor branch.

Prodded by:	ru
This commit is contained in:
Tom Rhodes 2004-09-29 06:22:38 +00:00
parent e42ab7cde1
commit 24dc798a69
3 changed files with 80 additions and 2 deletions

View File

@ -44,7 +44,6 @@
#include <assert.h>
#include <fcntl.h>
#include <err.h>
#include <isc/eventlib.h>
#include <netnatm/unimsg.h>
#include <netnatm/saal/sscop.h>
@ -64,7 +63,9 @@ int user_fd;
int loose;
int user_out_fd;
u_int verbose;
#ifndef USE_LIBBEGEMOT
evContext evctx;
#endif
evFileID sscop_h;
evFileID user_h;
@ -153,7 +154,11 @@ proto_msgin(int fd __unused)
if (got == 0) {
eof:
#ifdef USE_LIBBEGEMOT
poll_unregister(sscop_h);
#else
evDeselectFD(evctx, sscop_h);
#endif
(void)close(sscop_fd);
sscop_fd = -1;
if (m != NULL)
@ -212,7 +217,11 @@ user_msgin(int fd __unused)
if (size == 0) {
eof:
#ifdef USE_LIBBEGEMOT
poll_unregister(user_h);
#else
evDeselectFD(evctx, user_h);
#endif
if (m != NULL)
uni_msg_destroy(m);
VERBOSE(("EOF on user connection"));
@ -384,9 +393,14 @@ parse_param(struct sscop_param *param, u_int *pmask, int opt, char *arg)
abort();
}
#ifdef USE_LIBBEGEMOT
static void
tfunc(int tid __unused, void *uap)
#else
static void
tfunc(evContext ctx __unused, void *uap, struct timespec due __unused,
struct timespec inter __unused)
#endif
{
struct timer *t = uap;
@ -402,18 +416,25 @@ sscop_start_timer(struct sscop *sscop, void *arg __unused, u_int msec,
void (*func)(void *))
{
struct timer *t;
#ifndef USE_LIBBEGEMOT
struct timespec due;
#endif
if ((t = malloc(sizeof(*t))) == NULL)
err(1, NULL);
t->sscop = sscop;
t->func = func;
#ifdef USE_LIBBEGEMOT
if ((t->id = poll_start_timer(msec, 0, tfunc, t)) == -1)
err(1, "cannot start timer");
#else
due = evAddTime(evNowTime(),
evConsTime((time_t)msec/1000, (long)(msec%1000)*1000));
if (evSetTimer(evctx, tfunc, t, due, evConsTime(0, 0), &t->id))
err(1, "cannot start timer");
#endif
return (t);
}
@ -426,6 +447,10 @@ sscop_stop_timer(struct sscop *sscop __unused, void *arg __unused, void *tp)
{
struct timer *t = tp;
#ifdef USE_LIBBEGEMOT
poll_stop_timer(t->id);
#else
evClearTimer(evctx, t->id);
#endif
free(t);
}

View File

@ -33,6 +33,14 @@
#ifndef _SAAL_COMMON_H_
#define _SAAL_COMMON_H_
#ifdef USE_LIBBEGEMOT
#include <rpoll.h>
#define evFileID int
#define evTimerID int
#else
#include <isc/eventlib.h>
#endif
/*
* Writes to a pipe must be in messages (if we don't use framing).
* It is not clear, what is the maximum message size for this. It seems
@ -49,7 +57,9 @@ extern int user_fd; /* file descriptor for USER */
extern int loose; /* loose messages */
extern int user_out_fd; /* file descriptor for output to user */
extern u_int verbose; /* talk to me */
#ifndef USE_LIBBEGEMOT
extern evContext evctx;
#endif
extern evFileID sscop_h;
extern evFileID user_h;

View File

@ -41,7 +41,6 @@
#include <signal.h>
#include <assert.h>
#include <err.h>
#include <isc/eventlib.h>
#include <netnatm/unimsg.h>
#include <netnatm/saal/sscop.h>
@ -95,8 +94,13 @@ static const struct sscop_funcs sscop_funcs = {
* SSCOP file descriptor is ready. Allocate and read one message
* and dispatch a signal.
*/
#ifdef USE_LIBBEGEMOT
static void
proto_infunc(int fd, int mask __unused, void *uap)
#else
static void
proto_infunc(evContext ctx __unused, void *uap, int fd, int mask __unused)
#endif
{
struct uni_msg *m;
@ -107,8 +111,13 @@ proto_infunc(evContext ctx __unused, void *uap, int fd, int mask __unused)
/*
* User input. Allocate and read message and dispatch signal.
*/
#ifdef USE_LIBBEGEMOT
static void
user_infunc(int fd, int mask __unused, void *uap)
#else
static void
user_infunc(evContext ctx __unused, void *uap, int fd, int mask __unused)
#endif
{
struct uni_msg *m;
@ -134,7 +143,9 @@ main(int argc, char *argv[])
struct sigaction sa;
int wait = 0;
u_int mask;
#ifndef USE_LIBBEGEMOT
evEvent ev;
#endif
/*
* Default is to have the USER on stdin and SSCOP on stdout
@ -209,8 +220,10 @@ main(int argc, char *argv[])
if(user_out_fd < 0)
user_out_fd = user_fd;
#ifndef USE_LIBBEGEMOT
if (evCreate(&evctx))
err(1, "evCreate");
#endif
/*
* Catch USR1
@ -233,8 +246,14 @@ main(int argc, char *argv[])
/*
* Register sscop fd
*/
#ifdef USE_LIBBEGEMOT
if ((sscop_h = poll_register(sscop_fd, proto_infunc,
sscop, POLL_IN)) == -1)
err(1, "can't select on sscop fd");
#else
if (evSelectFD(evctx, sscop_fd, EV_READ, proto_infunc, sscop, &sscop_h))
err(1, "can't select on sscop fd");
#endif
/*
* if we are active - send establish request
@ -246,11 +265,15 @@ main(int argc, char *argv[])
* Run protocol until it get's ready
*/
while (sscop_fd >= 0 && !ready) {
#ifdef USE_LIBBEGEMOT
poll_dispatch(1);
#else
if (evGetNext(evctx, &ev, EV_WAIT) == 0) {
if (evDispatch(evctx, ev))
err(1, "dispatch event");
} else if (errno != EINTR)
err(1, "get event");
#endif
}
/*
@ -265,15 +288,23 @@ main(int argc, char *argv[])
VERBOSE(("READY - starting data transfer"));
if (!unidir &&
#ifdef USE_LIBBEGEMOT
((user_h = poll_register(user_fd, user_infunc, sscop, POLL_IN)) == -1))
#else
evSelectFD(evctx, user_fd, EV_READ, user_infunc, sscop, &user_h))
#endif
err(1, "can't select on sscop fd");
while (!sigusr1 && sscop_fd >= 0) {
#ifdef USE_LIBBEGEMOT
poll_dispatch(1);
#else
if (evGetNext(evctx, &ev, EV_WAIT) == 0) {
if (evDispatch(evctx, ev))
err(1, "dispatch event");
} else if (errno != EINTR)
err(1, "get event");
#endif
}
if (sigusr1 && sscop_fd >= 0) {
@ -282,11 +313,15 @@ main(int argc, char *argv[])
*/
sscop_aasig(sscop, SSCOP_RELEASE_request, NULL, 0);
while (!finished && sscop_fd >= 0) {
#ifdef USE_LIBBEGEMOT
poll_dispatch(1);
#else
if (evGetNext(evctx, &ev, EV_WAIT) == 0) {
if (evDispatch(evctx, ev))
err(1, "dispatch event");
} else if (errno != EINTR)
err(1, "get event");
#endif
}
}
@ -333,7 +368,11 @@ sscop_send_upper(struct sscop *sscop, void *arg __unused, enum sscop_aasig sig,
case SSCOP_RELEASE_indication:
if (end_at_eof) {
VERBOSE((" ... exiting"));
#ifdef USE_LIBBEGEMOT
poll_unregister(sscop_h);
#else
evDeselectFD(evctx, sscop_h);
#endif
(void)close(sscop_fd);
sscop_fd = -1;
}
@ -345,7 +384,11 @@ sscop_send_upper(struct sscop *sscop, void *arg __unused, enum sscop_aasig sig,
case SSCOP_RELEASE_confirm:
if (end_at_eof) {
VERBOSE((" ... exiting"));
#ifdef USE_LIBBEGEMOT
poll_unregister(sscop_h);
#else
evDeselectFD(evctx, sscop_h);
#endif
(void)close(sscop_fd);
sscop_fd = -1;
}