ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/connection.h
Revision: 1.6
Committed: Sun Sep 9 20:05:51 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +2 -2 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

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