ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/send.C
Revision: 1.6
Committed: Wed Aug 29 21:01:19 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +3 -1 lines
Log Message:
- reduced ifdefs by moving __GNUC__ and friends to svsconfig.h
- #define to enum { } in tools.h
- corrected log levels a bit
- made timersub an inline function instead of a macro
- added a simple garbage collection mechanism for postponed freeing of lost
  memory chunks
- enhanced type_traits
- merged inspircd1.2 support with upstream
- reformatting
- renamed TTP to a more "standard" PRItime and STP to PRIsize

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * send.C: Socket I/O.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 pippijn 1.1 */
7    
8 pippijn 1.6 static char const rcsid[] = "$Id: send.C,v 1.5 2007-08-28 17:08:12 pippijn Exp $";
9 pippijn 1.1
10     #include "atheme.h"
11     #include "uplink.h"
12     #include "datastream.h"
13    
14     /* send a line to the server, append the \r\n */
15     int
16 pippijn 1.5 sts (char const * const fmt, ...)
17 pippijn 1.1 {
18     va_list ap;
19     char buf[513];
20     int len;
21    
22     return_val_if_fail (fmt != NULL, 1);
23    
24     va_start (ap, fmt);
25     vsnprintf (buf, 511, fmt, ap); /* leave two bytes for \r\n */
26     va_end (ap);
27    
28     slog (LG_RAWDATA, "<- %s", buf);
29    
30     len = strlen (buf);
31     buf[len++] = '\r';
32     buf[len++] = '\n';
33     buf[len] = '\0';
34    
35     cnt.bout += len;
36    
37     sendq_add (curr_uplink->conn, buf, len);
38    
39     return 0;
40     }
41    
42     void
43     reconn (void *arg)
44     {
45     if (me.connected)
46     return;
47    
48     uplink_connect ();
49     }
50    
51     /*
52     * io_loop()
53     *
54     * inputs:
55     * none
56     *
57     * outputs:
58     * none
59     *
60     * side effects:
61     * everything happens inside this loop.
62     */
63     void
64     io_loop (void)
65     {
66     time_t delay;
67    
68     while (!(runflags & (RF_SHUTDOWN | RF_RESTART)))
69     {
70     /* update the current time */
71 pippijn 1.5 NOW = time_t (now ());
72 pippijn 1.1
73     /* check for events */
74     delay = event_next_time ();
75    
76     if (delay <= NOW)
77     event_run ();
78    
79     connection_select (25000);
80 pippijn 1.6
81     gc.collect ();
82 pippijn 1.1 }
83     }