ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/connection.h
(Generate patch)

Comparing ermyth/include/connection.h (file contents):
Revision 1.3 by pippijn, Tue Aug 28 17:08:06 2007 UTC vs.
Revision 1.4 by pippijn, Thu Aug 30 19:56:19 2007 UTC

2 * Copyright © 2005 Atheme Development Group 2 * Copyright © 2005 Atheme Development Group
3 * Rights to this code are as documented in doc/pod/license.pod. 3 * Rights to this code are as documented in doc/pod/license.pod.
4 * 4 *
5 * This contains the connection_t structure. 5 * This contains the connection_t structure.
6 * 6 *
7 * $Id: connection.h,v 1.3 2007/08/28 17:08:06 pippijn Exp $ 7 * $Id: connection.h,v 1.4 2007/08/30 19:56:19 pippijn Exp $
8 */ 8 */
9 9
10#ifndef CONNECTION_H 10#ifndef CONNECTION_H
11#define CONNECTION_H 11#define CONNECTION_H
12 12
42 { 42 {
43 functor::callback1<connection_t *> connected; 43 functor::callback1<connection_t *> connected;
44 }; 44 };
45 45
46public: 46public:
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
71public:
47 int index; 72 int index;
48 73
49 typedef std::deque<packetqueue *> queue; 74 typedef std::deque<packetqueue *> queue;
50 75
51 char name[HOSTLEN]; 76 char name[HOSTLEN];
65 unsigned int saddr_size; 90 unsigned int saddr_size;
66 91
67 void (*read_handler) (connection_t *); 92 void (*read_handler) (connection_t *);
68 void (*write_handler) (connection_t *); 93 void (*write_handler) (connection_t *);
69 94
70 unsigned int flags; 95 unsigned flags;
71 96
72 void (*recvq_handler) (connection_t *); 97 void (*recvq_handler) (connection_t *);
73 void (*close_handler) (connection_t *); 98 void (*close_handler) (connection_t *);
74 connection_t *listener; 99 connection_t *listener;
75 void *userdata; 100 void *userdata;
76 101
77 static callbacks callback; 102 static callbacks callback;
103
104public:
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);
78}; 123};
79 124
80typedef indexing_vector<connection_t> connection_vector; 125typedef indexing_vector<connection_t> connection_vector;
81E connection_vector connlist; 126E connection_vector connlist;
82 127
83#define CF_UPLINK 0x00000001
84#define CF_DCCOUT 0x00000002
85#define CF_DCCIN 0x00000004
86
87#define CF_CONNECTING 0x00000008
88#define CF_LISTENING 0x00000010
89#define CF_CONNECTED 0x00000020
90#define CF_DEAD 0x00000040
91
92#define CF_NONEWLINE 0x00000080
93#define CF_SEND_EOF 0x00000100 /* shutdown(2) write end if sendque empty */
94#define CF_SEND_DEAD 0x00000200 /* write end shut down */
95
96#define CF_IS_UPLINK(x) ((x)->flags & CF_UPLINK)
97#define CF_IS_DCC(x) ((x)->flags & (CF_DCCOUT | CF_DCCIN))
98#define CF_IS_DCCOUT(x) ((x)->flags & CF_DCCOUT)
99#define CF_IS_DCCIN(x) ((x)->flags & CF_DCCIN)
100#define CF_IS_DEAD(x) ((x)->flags & CF_DEAD)
101#define CF_IS_CONNECTING(x) ((x)->flags & CF_CONNECTING)
102#define CF_IS_LISTENING(x) ((x)->flags & CF_LISTENING)
103
104E connection_t *connection_add (char const * const name, int fd, unsigned int flags,
105 void (*read_handler) (connection_t *), void (*write_handler) (connection_t *));
106E connection_t *connection_open_tcp (char const * const host, char const * const vhost, unsigned int port,
107 void (*read_handler) (connection_t *), void (*write_handler) (connection_t *));
108E connection_t *connection_open_listener_tcp (char const * const host, unsigned int port, void (*read_handler) (connection_t *));
109E connection_t *connection_accept_tcp (connection_t *, void (*)(connection_t *), void (*)(connection_t *));
110E void connection_setselect (connection_t *, void (*)(connection_t *), void (*)(connection_t *));
111E void connection_close (connection_t *);
112E void connection_close_soon (connection_t *);
113E void connection_close_soon_children (connection_t *);
114E void connection_close_all (void);
115E void connection_stats (void (*)(char const *, void *), void *);
116E void connection_write (connection_t *to, char *format, ...);
117E void connection_write_raw (connection_t *to, char *data);
118E connection_t *connection_find (int);
119E void connection_select (time_t delay);
120E int connection_count (void);
121
122#endif 128#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines