From 1b4cfad88d796e9f6c22e2918d0757cdc7ea4b1c Mon Sep 17 00:00:00 2001 From: nenolod Date: Tue, 3 Apr 2007 02:57:53 -0700 Subject: [PATCH] [svn] - river's ports.c from old charybdis trunk --- ChangeLog | 13 ++++ configure.ac | 19 ++++- include/serno.h | 2 +- libcharybdis/ports.c | 180 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 libcharybdis/ports.c diff --git a/ChangeLog b/ChangeLog index 0118432..cbdad36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +nenolod 2007/04/03 09:50:56 UTC (20070403-3364) + Log: + - remove broken ports stuff and devpoll stuff. + + + Changes: Modified: + +0 -307 trunk/configure (File Modified) + +0 -21 trunk/configure.ac (File Modified) + +0 -474 trunk/include/setup.h.in (File Modified) + + - trunk/libcharybdis/devpoll.c (File Deleted) + + - trunk/libcharybdis/ports.c (File Deleted) + + nenolod 2007/04/03 09:49:11 UTC (20070403-3362) Log: - regenerate files diff --git a/configure.ac b/configure.ac index 4c1b08a..e0d52bd 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -dnl $Id: configure.ac 3364 2007-04-03 09:50:56Z nenolod $ +dnl $Id: configure.ac 3366 2007-04-03 09:57:53Z nenolod $ dnl Process this file with autoconf to produce a configure script. dnl TODO: clean up all the OpenSSL and shared module checking stuff; @@ -8,7 +8,7 @@ dnl said functions need to be just about as complex as they already are. AC_PREREQ(2.57) dnl Sneaky way to get an Id tag into the configure script -AC_COPYRIGHT([$Id: configure.ac 3364 2007-04-03 09:50:56Z nenolod $]) +AC_COPYRIGHT([$Id: configure.ac 3366 2007-04-03 09:57:53Z nenolod $]) AC_INIT([charybdis],[2.2.0]) @@ -631,6 +631,14 @@ fi dnl IO Loop Selection dnl ================= +AC_ARG_ENABLE(ports, AC_HELP_STRING([--enable-ports],[Force solaris I/O ports subsystem usage.]), +[ if test $enableval = yes; then + SELECT_TYPE_EXPLICIT="ports" + else + use_ports=no + fi +],) + AC_ARG_ENABLE(poll, AC_HELP_STRING([--enable-poll],[Force poll() usage.]), [ if test $enableval = yes; then SELECT_TYPE_EXPLICIT="poll" @@ -741,6 +749,13 @@ if test ! -z "$SELECT_TYPE_EXPLICIT"; then echo "Forcing $SELECT_TYPE to be enabled" else +if test ! "x$use_ports" = "xno"; then + AC_CHECK_FUNCS(port_getn, [haveports=yes], [haveports=no]) + if test "x$haveports" = "xyes" ; then + SELECT_TYPE="ports" + fi +fi + if test ! "x$use_select" = "xno"; then AC_CHECK_FUNCS(select, [haveselect=yes], [haveselect=no]) if test "x$haveselect" = "xyes" ; then diff --git a/include/serno.h b/include/serno.h index 2bea1c5..24742c8 100644 --- a/include/serno.h +++ b/include/serno.h @@ -1 +1 @@ -#define SERNO "20070403-3362" +#define SERNO "20070403-3364" diff --git a/libcharybdis/ports.c b/libcharybdis/ports.c new file mode 100644 index 0000000..a0fdead --- /dev/null +++ b/libcharybdis/ports.c @@ -0,0 +1,180 @@ +/* + * charybdis: A slightly useful ircd. + * ports.c: Solaris ports compatible network routines. + * + * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center + * Copyright (C) 1996-2002 Hybrid Development Team + * Copyright (C) 2001 Adrian Chadd + * Copyright (C) 2002-2004 ircd-ratbox development team + * Copyright (C) 2005 Edward Brocklesby. + * Copyright (C) 2005 William Pitcock and Jilles Tjoelker + * Copyright (C) 2007 River Tarnell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id: ports.c 3366 2007-04-03 09:57:53Z nenolod $ + */ + +#include "stdinc.h" +#include +#include + +#include "stdinc.h" +#include "res.h" +#include "numeric.h" +#include "tools.h" +#include "memory.h" +#include "balloc.h" +#include "linebuf.h" +#include "sprintf_irc.h" +#include "commio.h" +#include "ircevent.h" +#include "modules.h" + +static int comm_init(void); +static void comm_deinit(void); + +static int comm_select_impl(unsigned long delay); +static void comm_setselect_impl(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout); + +static void pe_update_events(fde_t *, short, PF *); +static int pe; +static struct timespec zero_timespec; + +static port_event_t *pelst; /* port buffer */ +static int pemax; /* max structs to buffer */ + +static void +pe_update_events(fde_t * F, short filter, PF * handler) +{ + PF *cur_handler = NULL; + + if (filter == POLLRDNORM) + cur_handler = F->read_handler; + else if (filter == POLLWRNORM) + cur_handler = F->write_handler; + + if (!cur_handler && handler) + port_associate(pe, PORT_SOURCE_FD, F->fd, filter, F); + else if (cur_handler && !handler) + port_dissociate(pe, PORT_SOURCE_FD, F->fd); +} + +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ +/* Public functions */ + + +/* + * init_netio + * + * This is a needed exported function which will be called to initialise + * the network loop code. + */ +static int +init_netio(void) +{ + if((pe = port_create()) < 0) { + ilog(L_MAIN, "init_netio: Couldn't open port fd!\n"); + exit(115); /* Whee! */ + } + pemax = getdtablesize(); + pelst = MyMalloc(sizeof(port_event_t) * pemax); + zero_timespec.tv_sec = 0; + zero_timespec.tv_nsec = 0; + + return 0; +} + +/* + * ircd_setselect + * + * This is a needed exported function which will be called to register + * and deregister interest in a pending IO state for a given FD. + */ +void +comm_setselect(int fd, unsigned int type, PF * handler, + void *client_data, time_t timeout) +{ + fde_t *F = &fd_table[fd]; + s_assert(fd >= 0); + s_assert(F->flags.open); + + if (type & COMM_SELECT_READ) { + pe_update_events(F, POLLRDNORM, handler); + F->read_handler = handler; + F->read_data = client_data; + } + if (type & COMM_SELECT_WRITE) { + pe_update_events(F, POLLWRNORM, handler); + F->write_handler = handler; + F->write_data = client_data; + } +} + +/* + * ircd_select + * + * Called to do the new-style IO, courtesy of squid (like most of this + * new IO code). This routine handles the stuff we've hidden in + * ircd_setselect and fd_table[] and calls callbacks for IO ready + * events. + */ + +int +comm_select(unsigned long delay) +{ + int i, fd; + unsigned int nget = 1; + struct timespec poll_time; + + poll_time.tv_sec = delay / 1000; + poll_time.tv_nsec = (delay % 1000) * 1000000; + + i = port_getn(pe, pelst, pemax, &nget, &poll_time); + set_time(); + + if (i == -1) + return COMM_ERROR; + + for (i = 0; i < nget; i++) + { + PF *hdl = NULL; + fde_t *F; + + switch(pelst[i].portev_source) + { + case PORT_SOURCE_FD: + fd = pelst[i].portev_object; + F = &fd_table[fd]; + + if ((pelst[i].portev_events & POLLRDNORM) && (hdl = F->read_handler)) { + F->read_handler = NULL; + hdl(fd, F->read_data); + } + if (F->flags.open == 0) + continue; + + if ((pelst[i].portev_events & POLLWRNORM) && (hdl = F->write_handler)) { + F->write_handler = NULL; + hdl(fd, F->write_data); + } + break; + default: + break; + } + } + return COMM_OK; +}