Replaced SELECT_CALLBACK with an API that supports multiple select callbacks
This commit is contained in:
parent
c67954c773
commit
aceb36c66b
5 changed files with 138 additions and 94 deletions
|
@ -50,7 +50,7 @@
|
|||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC border_router_rdc_driver
|
||||
|
||||
#define SELECT_CALLBACK (&tun_select_callback)
|
||||
extern struct select_callback tun_select_callback;
|
||||
/* used by wpcap (see /cpu/native/net/wpcap-drv.c) */
|
||||
#define SELECT_CALLBACK 1
|
||||
|
||||
#endif /* __PROJECT_ROUTER_CONF_H__ */
|
||||
|
|
|
@ -368,6 +368,31 @@ stty_telos(int fd)
|
|||
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
set_fd(fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(!slip_empty()) { /* Anything to flush? */
|
||||
FD_SET(slipfd, wset);
|
||||
}
|
||||
|
||||
FD_SET(slipfd, rset); /* Read from slip ASAP! */
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
handle_fd(fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(FD_ISSET(slipfd, rset)) {
|
||||
serial_input(inslip);
|
||||
}
|
||||
|
||||
if(FD_ISSET(slipfd, wset)) {
|
||||
slip_flushbuf(slipfd);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct select_callback slip_callback = { set_fd, handle_fd };
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_init(void)
|
||||
{
|
||||
|
@ -395,6 +420,8 @@ slip_init(void)
|
|||
}
|
||||
}
|
||||
|
||||
select_set_callback(slipfd, &slip_callback);
|
||||
|
||||
fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
|
||||
stty_telos(slipfd);
|
||||
|
||||
|
@ -402,28 +429,3 @@ slip_init(void)
|
|||
inslip = fdopen(slipfd, "r");
|
||||
if(inslip == NULL) err(1, "main: fdopen");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
slip_set_fd(int maxfd, fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(!slip_empty()) { /* Anything to flush? */
|
||||
FD_SET(slipfd, wset);
|
||||
}
|
||||
|
||||
FD_SET(slipfd, rset); /* Read from slip ASAP! */
|
||||
if(slipfd > maxfd) maxfd = slipfd;
|
||||
|
||||
return maxfd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_handle_fd(fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(FD_ISSET(slipfd, rset)) {
|
||||
serial_input(inslip);
|
||||
}
|
||||
|
||||
if(FD_ISSET(slipfd, wset)) {
|
||||
slip_flushbuf(slipfd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#ifdef linux
|
||||
|
@ -65,14 +65,20 @@
|
|||
#include "cmd.h"
|
||||
#include "border-router.h"
|
||||
|
||||
extern int slip_config_verbose;
|
||||
extern const char *slip_config_ipaddr;
|
||||
extern int slip_config_flowcontrol;
|
||||
extern char slip_config_tundev[32];
|
||||
extern uint16_t slip_config_basedelay;
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
static int tunfd;
|
||||
static int initialized = 0;
|
||||
|
||||
static int set_fd(fd_set *rset, fd_set *wset);
|
||||
static void handle_fd(fd_set *rset, fd_set *wset);
|
||||
static const struct select_callback tun_select_callback = {
|
||||
set_fd,
|
||||
handle_fd
|
||||
};
|
||||
#endif /* __CYGWIN__ */
|
||||
|
||||
int ssystem(const char *fmt, ...)
|
||||
__attribute__((__format__ (__printf__, 1, 2)));
|
||||
|
@ -181,8 +187,6 @@ tun_init()
|
|||
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
|
||||
|
||||
slip_init();
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -200,6 +204,9 @@ tun_init()
|
|||
|
||||
tunfd = tun_alloc(slip_config_tundev);
|
||||
if(tunfd == -1) err(1, "main: open");
|
||||
|
||||
select_set_callback(tunfd, &tun_select_callback);
|
||||
|
||||
fprintf(stderr, "opened %s device ``/dev/%s''\n",
|
||||
"tun", slip_config_tundev);
|
||||
|
||||
|
@ -208,8 +215,6 @@ tun_init()
|
|||
signal(SIGTERM, sigcleanup);
|
||||
signal(SIGINT, sigcleanup);
|
||||
ifconf(slip_config_tundev, slip_config_ipaddr);
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -251,22 +256,14 @@ const struct uip_fallback_interface rpl_interface = {
|
|||
init, output
|
||||
};
|
||||
|
||||
#endif /* __CYGWIN_ */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* tun and slip select callback */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
set_fd(int maxfd, fd_set *rset, fd_set *wset)
|
||||
set_fd(fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(!initialized) return maxfd;
|
||||
|
||||
maxfd = slip_set_fd(maxfd, rset, wset);
|
||||
|
||||
FD_SET(tunfd, rset);
|
||||
if(tunfd > maxfd) maxfd = tunfd;
|
||||
|
||||
return maxfd;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -274,14 +271,6 @@ set_fd(int maxfd, fd_set *rset, fd_set *wset)
|
|||
static void
|
||||
handle_fd(fd_set *rset, fd_set *wset)
|
||||
{
|
||||
if(!initialized) return;
|
||||
|
||||
slip_handle_fd(rset, wset);
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
/* Packets from host interface are handled by wpcap process */
|
||||
#else
|
||||
|
||||
/* Optional delay between outgoing packets */
|
||||
/* Base delay times number of 6lowpan fragments to be sent */
|
||||
/* delaymsec = 10; */
|
||||
|
@ -312,12 +301,7 @@ handle_fd(fd_set *rset, fd_set *wset)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif /* __CYGWIN__ */
|
||||
}
|
||||
#endif /* __CYGWIN_ */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
struct select_callback tun_select_callback = {
|
||||
set_fd,
|
||||
handle_fd
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue