ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/select.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +58 -52 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * select.C: select(2) socket engine.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 pippijn 1.1 */
7    
8 pippijn 1.4 static char const rcsid[] = "$Id: select.C,v 1.3 2007-07-21 13:23:22 pippijn Exp $";
9 pippijn 1.1
10     #include "atheme.h"
11     #include "internal.h"
12 pippijn 1.4 #include "datastream.h"
13 pippijn 1.1
14     fd_set readfds, writefds;
15    
16     /*
17     * init_socket_queues()
18     *
19     * inputs:
20     * none
21     *
22     * outputs:
23     * none
24     *
25     * side effects:
26     * when using select, we don't need to do anything here.
27     */
28     void
29     init_socket_queues (void)
30     {
31     return;
32     }
33    
34     /*
35     * update_select_sets()
36     *
37     * inputs:
38     * none
39     *
40     * outputs:
41     * none
42     *
43     * side effects:
44     * registered sockets are prepared for the select() loop.
45     */
46     static void
47     update_select_sets (void)
48     {
49 pippijn 1.4 connection_vector::iterator it = connlist.begin ();
50     connection_vector::iterator et = connlist.end ();
51 pippijn 1.1 connection_t *cptr;
52    
53     FD_ZERO (&readfds);
54     FD_ZERO (&writefds);
55    
56 pippijn 1.4 while (it != et)
57     {
58     cptr = *it;
59    
60     if (CF_IS_CONNECTING (cptr))
61     FD_SET (cptr->fd, &writefds);
62    
63     else if (CF_IS_LISTENING (cptr))
64     FD_SET (cptr->fd, &readfds);
65    
66     if (sendq_nonempty (cptr))
67     FD_SET (cptr->fd, &writefds);
68    
69     else
70     FD_SET (cptr->fd, &readfds);
71    
72     ++it;
73     }
74 pippijn 1.1 }
75    
76     /*
77     * connection_select()
78     *
79     * inputs:
80     * delay in nanoseconds
81     *
82     * outputs:
83     * none
84     *
85     * side effects:
86     * registered sockets and their associated handlers are acted on.
87     */
88     void
89     connection_select (time_t delay)
90     {
91     int sr;
92 pippijn 1.4 connection_vector::iterator it = connlist.begin ();
93     connection_vector::iterator et = connlist.end ();
94 pippijn 1.1 connection_t *cptr;
95 pippijn 1.4 timeval to;
96 pippijn 1.1
97     update_select_sets ();
98     to.tv_sec = 0;
99     to.tv_usec = delay;
100    
101 pippijn 1.4 if ((sr = select (system_state.maxfd + 1, &readfds, &writefds, NULL, &to)) > 0)
102 pippijn 1.1 {
103     /* Iterate twice, so we don't touch freed memory if
104     * a connection is closed.
105     * -- jilles */
106 pippijn 1.4 while (it != et)
107     {
108     cptr = *it;
109    
110     if (FD_ISSET (cptr->fd, &writefds))
111     {
112     if (CF_IS_CONNECTING (cptr))
113     cptr.callback.connected (cptr);
114     else
115     cptr->write_handler (cptr);
116     }
117    
118     ++it;
119     }
120    
121     for (it = connlist.begin (), et = connlist.end (); it != et; ++it)
122     {
123     cptr = *it;
124    
125     if (FD_ISSET (cptr->fd, &readfds))
126     {
127     cptr->read_handler (cptr);
128     }
129     }
130    
131     for (it = connlist.begin (), et = connlist.end (); it != et; ++it)
132     {
133     cptr = *it;
134     if (cptr->flags & CF_DEAD)
135     connection_close (cptr);
136     }
137 pippijn 1.1 }
138     else
139     {
140     if (sr == 0)
141     {
142     /* select() timed out */
143     }
144     else if ((sr == -1) && (errno == EINTR))
145     {
146     /* some signal interrupted us, restart select() */
147     }
148     else if (sr == -1)
149     {
150     return;
151     }
152     }
153     }
154    
155     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
156     * vim:ts=8
157     * vim:sw=8
158     * vim:noexpandtab
159     */