ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/connection.h
Revision: 1.4
Committed: Thu Aug 30 19:56:19 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +47 -41 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

# Content
1 /*
2 * Copyright © 2005 Atheme Development Group
3 * Rights to this code are as documented in doc/pod/license.pod.
4 *
5 * This contains the connection_t structure.
6 *
7 * $Id: connection.h,v 1.3 2007-08-28 17:08:06 pippijn Exp $
8 */
9
10 #ifndef CONNECTION_H
11 #define CONNECTION_H
12
13 #include <deque>
14
15 #include <common/util.h>
16 #include <ermyth/callback.h>
17
18 #define SENDQSIZE (4096 - 40)
19
20 /* packetqueue struct */
21 struct packetqueue : zero_initialised
22 {
23 node_t node;
24 int firstused; /* offset of first used byte */
25 int firstfree; /* 1 + offset of last used byte */
26 char buf[SENDQSIZE];
27
28 packetqueue ()
29 : firstused (0), firstfree (0)
30 {
31 }
32 };
33
34 class connection_t : public zero_initialised
35 {
36 void _destroy ()
37 {
38 delete this;
39 }
40
41 struct callbacks
42 {
43 functor::callback1<connection_t *> connected;
44 };
45
46 public:
47 enum flag
48 {
49 CF_UPLINK = 1 << 0,
50 CF_DCCOUT = 1 << 1,
51 CF_DCCIN = 1 << 2,
52
53 CF_CONNECTING = 1 << 3,
54 CF_LISTENING = 1 << 4,
55 CF_CONNECTED = 1 << 5,
56 CF_DEAD = 1 << 6,
57
58 CF_NONEWLINE = 1 << 7,
59 CF_SEND_EOF = 1 << 8, /* shutdown(2) write end if sendque empty */
60 CF_SEND_DEAD = 1 << 9 /* write end shut down */
61 };
62
63 bool is_uplink () { return flags & CF_UPLINK; }
64 bool is_dcc () { return flags & (CF_DCCOUT | CF_DCCIN); }
65 bool is_dccout () { return flags & CF_DCCOUT; }
66 bool is_dccin () { return flags & CF_DCCIN; }
67 bool is_dead () { return flags & CF_DEAD; }
68 bool is_connecting () { return flags & CF_CONNECTING; }
69 bool is_listening () { return flags & CF_LISTENING; }
70
71 public:
72 int index;
73
74 typedef std::deque<packetqueue *> queue;
75
76 char name[HOSTLEN];
77 char hbuf[BUFSIZE + 1];
78
79 queue recvq;
80 queue sendq;
81
82 int fd;
83 int pollslot;
84
85 time_t first_recv;
86 time_t last_recv;
87
88 struct sockaddr_in *sa;
89 struct sockaddr saddr;
90 unsigned int saddr_size;
91
92 void (*read_handler) (connection_t *);
93 void (*write_handler) (connection_t *);
94
95 unsigned flags;
96
97 void (*recvq_handler) (connection_t *);
98 void (*close_handler) (connection_t *);
99 connection_t *listener;
100 void *userdata;
101
102 static callbacks callback;
103
104 public:
105 static connection_t *create (char const * const name, int fd, unsigned int flags,
106 void (*read_handler) (connection_t *), void (*write_handler) (connection_t *));
107 static connection_t *open_tcp (char const * const host, char const * const vhost, unsigned int port,
108 void (*read_handler) (connection_t *), void (*write_handler) (connection_t *));
109 static connection_t *open_listener_tcp (char const * const host, unsigned int port, void (*read_handler) (connection_t *));
110 static connection_t *accept_tcp (connection_t *, void (*)(connection_t *), void (*)(connection_t *));
111
112 void setselect (connection_t *cptr, void (*)(connection_t *), void (*)(connection_t *));
113 void close ();
114 void close_soon ();
115 void close_soon_children ();
116 static void close_all (void);
117 static void stats (void (*)(char const *, void *), void *);
118 void write (char *format, ...);
119 void write_raw (char *data);
120 static connection_t *find (int);
121 static void select (time_t delay);
122 static int count (void);
123 };
124
125 typedef indexing_vector<connection_t> connection_vector;
126 E connection_vector connlist;
127
128 #endif