]>
jfr.im git - irc/rqf/shadowircd.git/blob - libratbox/src/ports.c
2 * ircd-ratbox: A slightly useful ircd.
3 * ports.c: Solaris ports compatible network routines.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2001 Adrian Chadd <adrian@creative.net.au>
8 * Copyright (C) 2002-2004 ircd-ratbox development team
9 * Copyright (C) 2005 Edward Brocklesby.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
26 * $Id: ports.c 25038 2008-01-23 16:03:08Z androsyn $
29 #include <libratbox_config.h>
30 #include <ratbox_lib.h>
31 #include <commio-int.h>
33 #if defined(HAVE_PORT_H) && (HAVE_PORT_CREATE)
40 static void pe_update_events(rb_fde_t
*, short, PF
*);
42 static struct timespec zero_timespec
;
44 static port_event_t
*pelst
; /* port buffer */
45 static int pemax
; /* max structs to buffer */
48 rb_setup_fd_ports(int fd
)
55 pe_update_events(rb_fde_t
* F
, short filter
, PF
* handler
)
57 PF
*cur_handler
= NULL
;
59 if (filter
== POLLRDNORM
)
60 cur_handler
= F
->read_handler
;
61 else if (filter
== POLLWRNORM
)
62 cur_handler
= F
->write_handler
;
64 if (!cur_handler
&& handler
)
65 port_associate(pe
, PORT_SOURCE_FD
, F
->fd
, filter
, F
);
66 else if (cur_handler
&& !handler
)
67 port_dissociate(pe
, PORT_SOURCE_FD
, F
->fd
);
70 /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
71 /* Public functions */
77 * This is a needed exported function which will be called to initialise
78 * the network loop code.
81 rb_init_netio_ports(void)
83 if((pe
= port_create()) < 0) {
86 pemax
= getdtablesize();
87 pelst
= rb_malloc(sizeof(port_event_t
) * pemax
);
88 zero_timespec
.tv_sec
= 0;
89 zero_timespec
.tv_nsec
= 0;
95 * This is a needed exported function which will be called to register
96 * and deregister interest in a pending IO state for a given FD.
99 rb_setselect_ports(rb_fde_t
*F
, unsigned int type
, PF
* handler
,
102 lrb_assert(IsFDOpen(F
));
104 /* Update the list, even though we're not using it .. */
105 if(type
& RB_SELECT_READ
) {
106 pe_update_events(F
, POLLRDNORM
, handler
);
107 F
->read_handler
= handler
;
108 F
->read_data
= client_data
;
110 if(type
& RB_SELECT_WRITE
) {
111 pe_update_events(F
, POLLWRNORM
, handler
);
112 F
->write_handler
= handler
;
113 F
->write_data
= client_data
;
120 * Called to do the new-style IO, courtesy of squid (like most of this
121 * new IO code). This routine handles the stuff we've hidden in
122 * rb_setselect and fd_table[] and calls callbacks for IO ready
127 rb_select_ports(long delay
)
131 struct timespec poll_time
;
132 struct timer_data
*tdata
;
134 poll_time
.tv_sec
= delay
/ 1000;
135 poll_time
.tv_nsec
= (delay
% 1000) * 1000000;
137 i
= port_getn(pe
, pelst
, pemax
, &nget
, &poll_time
);
143 for (i
= 0; i
< nget
; i
++) {
144 switch(pelst
[i
].portev_source
) {
146 fd
= pelst
[i
].portev_object
;
148 rb_fde_t
*F
= rb_find_fd(fd
);
150 if ((pelst
[i
].portev_events
& POLLRDNORM
) && (hdl
= F
->read_handler
)) {
151 F
->read_handler
= NULL
;
152 hdl(F
, F
->read_data
);
154 if ((pelst
[i
].portev_events
& POLLWRNORM
) && (hdl
= F
->write_handler
)) {
155 F
->write_handler
= NULL
;
156 hdl(F
, F
->write_data
);
164 #else /* ports not supported */
166 rb_init_netio_ports(void)
172 rb_setselect_ports(rb_fde_t
*F
, unsigned int type
, PF
* handler
, void *client_data
)
179 rb_select_ports(long delay
)
186 rb_setup_fd_ports(rb_fde_t
*F
)