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