catalinux / Conn (public) (License: LGPLv2) (since 2016-03-01) (hash sha1)
Net library for easy building ipv4/ipv6 network daemons/clients
List of commits:
Subject Hash Author Date (UTC)
WIP 6387026db3ce7983e610887565a282f4124d4092 Catalin(ux) M. BOIE 2013-10-14 20:06:49
WIP 15f063f9d34d3f7b7ae9d9e83f59b4077515122b Catalin(ux) M. BOIE 2010-09-30 22:01:30
Switch licence to LGPLv3+; Do not stupidly close master socket. d3b1c4ccd591627e7faa0eeaaa3b2bc1ee20709e Catalin(ux) M. BOIE 2013-08-14 04:09:36
Duilder fixes. Removed -O0. Fixed spec file. d8a03dced52e918b6f66a05dfd64a3c75c07c91b Catalin(ux) M. BOIE 2011-12-14 09:12:55
Fixed a stupid logging bug (invalid number of parameters). e7d4c38d0130a142ac6c409c63d63201d2af08e2 Catalin(ux) M. BOIE 2010-12-22 16:46:47
Ignore all Changelog files. fa45b63d3db958228f44bcb3d6431d60f94d1147 Catalin(ux) M. BOIE 2010-12-22 16:46:16
Added mailmap file. a57dcfd6bdf6c8c86161cf7ce3fff942a714a2b9 Catalin(ux) M. BOIE 2010-12-22 16:46:04
Be more verbose in try_expand_buf and error out connection when cannot expand. e95ac8d7e5015958d3594862c6183b63bab80d4a Catalin(ux) M. BOIE 2010-09-30 20:58:08
Ignore xbind1 compiled example. 089b68cf9fc5c16ee7d8136b28a52ec4dd139c78 Catalin(ux) M. BOIE 2010-08-23 19:42:01
Removed direct access to Conn structure in s.c example. f6215273602571ef2c98479bdba930ebe312cbc9 Catalin(ux) M. BOIE 2010-08-23 19:38:33
Bumped the version to 1.0.32. f158fca2cf9f3285ae761cd4ce30b01911b84385 Catalin(ux) M. BOIE 2010-06-23 21:30:47
The cache for epoll_ctl, has to take also the slot in consideration. ed378c16927c707feee481b2cd0ea7fbdf257d9d Catalin(ux) M. BOIE 2010-06-09 19:18:03
After calling getsockname, set cache as clean. 199f0fd96b064fd1e63f5773b1e7ab58e7d91303 Catalin(ux) M. BOIE 2010-06-08 18:30:20
Do not try to call getsockname if connection is not opened. e9853b5b5a01df3c5e07f6fe4607a68fd7181b39 Catalin(ux) M. BOIE 2010-06-08 18:28:49
Supports kernels below 2.6.9 (epoll_ctl). 97919a022fae39bdefc3f7e4c50526fb473dfd34 Catalin(ux) M. BOIE 2010-06-08 18:06:35
Cosmetic logging. ad806920255f8ca5f9281b6b6a3a53edf2d5088f Catalin(ux) M. BOIE 2010-06-08 17:35:45
When generating one line of slot status, do not append \n. 20ed77b4bf5909ded12cd225753a8858d8941792 Catalin(ux) M. BOIE 2010-06-08 15:57:16
Indented Conn_poll_cb to better watch logs. 58d734a8895b03eb17724eefe37e862c9665fb2c Catalin(ux) M. BOIE 2010-06-08 15:52:44
If we have POLLOUT set and the queue is empty, do not call recv function. 2f3b266eea11dea7c28f1c24b615f667585a215e Catalin(ux) M. BOIE 2010-06-08 15:27:40
Conn_{addr,port}_{local,remote} functions added. 47643b30ea900240e821983c89eb1f806f91c6ea Catalin(ux) M. BOIE 2010-06-08 15:03:52
Commit 6387026db3ce7983e610887565a282f4124d4092 - WIP
Author: Catalin(ux) M. BOIE
Author date (UTC): 2013-10-14 20:06
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2013-10-14 20:06
Parent(s): 15f063f9d34d3f7b7ae9d9e83f59b4077515122b
Signing key:
Tree: 827c228c07fa60ccf3f484889a7f18b170ca1046
File Lines added Lines deleted
Conn.c 2 88
Conn.h 0 1
Conn_config.h.in 2 0
Conn_engine_core.c 22 28
Conn_engine_core.h 0 17
Conn_engine_epoll.c 0 4
Conn_engine_epoll.h 0 4
Conn_engine_poll.c 0 159
Conn_engine_poll.h 0 22
Makefile.in 2 5
TODO 7 0
examples/Makefile 5 0
examples/raw.c 0 1
examples/raw2.c 0 1
examples/s.c 0 1
examples/trigger.c 0 1
examples/udp_s.c 0 1
examples/xbind.c 0 1
File Conn.c changed (mode: 100644) (index db74d46..02dd3f5)
7 7 */ */
8 8
9 9 #include "Conn.h" #include "Conn.h"
10 #include "Conn_engine_poll.h"
11 10 #include "Conn_engine_epoll.h" #include "Conn_engine_epoll.h"
12 11
13 12
14 13 /* Internal variables */ /* Internal variables */
15 /* Engine */
16 static unsigned int Conn_engine;
17 static unsigned int Conn_engine_poll_found;
18 static unsigned int Conn_engine_epoll_found;
19 14
20 15 /* Engine functions */ /* Engine functions */
21 16 static int (*Conn_engine_init)(void); static int (*Conn_engine_init)(void);
 
... ... static int (*Conn_engine_move_slot)(const unsigned int dst,
31 26
32 27 /* Functions */ /* Functions */
33 28
34 /*
35 * Set prefered engine
36 */
37 int Conn_engine_set(const unsigned int engine)
38 {
39 if (engine == Conn_engine)
40 return 0;
41
42 if (engine == CONN_ENGINE_POLL) {
43 if (Conn_engine_poll_found == 0) {
44 snprintf(Conn_error, sizeof(Conn_error),
45 "Cannot use engine POLL. Probably not supported.");
46 return -1;
47 }
48
49 #ifdef POLL_FOUND
50 /* Set variables */
51 CONN_POLLIN = POLLIN;
52 CONN_POLLOUT = POLLOUT;
53 CONN_POLLPRI = POLLPRI;
54 CONN_POLLERR = POLLERR;
55 CONN_POLLHUP = POLLHUP;
56 CONN_POLLNVAL = POLLNVAL;
57 CONN_POLLRDNORM = POLLRDNORM;
58 CONN_POLLRDBAND = POLLRDBAND;
59 /* Set functions */
60 Conn_engine_init = Conn_poll_init;
61 Conn_engine_shutdown = Conn_poll_shutdown;
62 Conn_engine_grow = Conn_poll_grow;
63 Conn_engine_add_obj = Conn_poll_add_obj;
64 Conn_engine_del_obj = Conn_poll_del_obj;
65 Conn_engine_chg_obj = Conn_poll_chg_obj;
66 Conn_engine_poll = Conn_poll_poll;
67 Conn_engine_move_slot = Conn_poll_move_slot;
68 #endif
69 } else if (engine == CONN_ENGINE_EPOLL) {
70 if (Conn_engine_epoll_found == 0) {
71 snprintf(Conn_error, sizeof(Conn_error),
72 "Cannot use engine EPOLL. Probably not supported.");
73 return -1;
74 }
75
76 #ifdef EPOLL_FOUND
77 /* Set variables */
78 CONN_POLLIN = EPOLLIN;
79 CONN_POLLOUT = EPOLLOUT;
80 CONN_POLLPRI = EPOLLPRI;
81 CONN_POLLERR = EPOLLERR;
82 CONN_POLLHUP = EPOLLHUP;
83 CONN_POLLNVAL = 0; /* not defined for epoll */
84 CONN_POLLRDNORM = 0; /* not defined for epoll */
85 CONN_POLLRDBAND = 0; /* not defined for epoll */
86 /* Set functions */
87 Conn_engine_init = Conn_epoll_init;
88 Conn_engine_shutdown = Conn_epoll_shutdown;
89 Conn_engine_grow = Conn_epoll_grow;
90 Conn_engine_add_obj = Conn_epoll_add_obj;
91 Conn_engine_del_obj = Conn_epoll_del_obj;
92 Conn_engine_chg_obj = Conn_epoll_chg_obj;
93 Conn_engine_poll = Conn_epoll_poll;
94 Conn_engine_move_slot = Conn_epoll_move_slot;
95 #endif
96 } else {
97 snprintf(Conn_error, sizeof(Conn_error),
98 "Cannot use engine %u because is not supported.", engine);
99 return -1;
100 }
101
102 return 0;
103 }
104
105 29 /* /*
106 30 * Reads a value from proc * Reads a value from proc
107 31 */ */
 
... ... int Conn_init(const unsigned int max)
185 109 Conn_queue_init(&Conn_queue_free); Conn_queue_init(&Conn_queue_free);
186 110 */ */
187 111
188 #ifdef POLL_FOUND
189 engine = CONN_ENGINE_POLL;
190 Conn_engine_poll_found = 1;
191 #endif
192
193 #ifdef EPOLL_FOUND
194 engine = CONN_ENGINE_EPOLL;
195 Conn_engine_epoll_found = 1;
196 #endif
197
198 112 ret = Conn_engine_set(engine); ret = Conn_engine_set(engine);
199 113 if (ret != 0) if (ret != 0)
200 114 return -1; return -1;
201 115
202 ret = Conn_engine_init();
116 ret = Conn_engine_epoll_init();
203 117 if (ret != 0) if (ret != 0)
204 118 return -1; return -1;
205 119
 
... ... int Conn_poll(const int timeout)
1387 1301 if (Conn_pending > 0) if (Conn_pending > 0)
1388 1302 Conn_trytoconnect(); Conn_trytoconnect();
1389 1303
1390 ret = Conn_engine_poll(timeout2, Conn_poll_cb);
1304 ret = Conn_engine_epoll_poll(timeout2, Conn_poll_cb);
1391 1305 if (ret < 0) if (ret < 0)
1392 1306 return -1; return -1;
1393 1307
File Conn.h changed (mode: 100644) (index 9823f64..f3cc133)
2 2 #define _Conn_h 1 #define _Conn_h 1
3 3
4 4 #include <Conn_engine_core.h> #include <Conn_engine_core.h>
5 #include <Conn_wpool.h>
6 5
7 6 extern int Conn_engine_set(const unsigned int engine); extern int Conn_engine_set(const unsigned int engine);
8 7 extern int Conn_init(const unsigned int max); extern int Conn_init(const unsigned int max);
File Conn_config.h.in changed (mode: 100644) (index 709b9e6..ff7ee33)
1 1 #define CONN_VERSION "@VER@" #define CONN_VERSION "@VER@"
2 2 #define POLL_FOUND @POLL_FOUND@ #define POLL_FOUND @POLL_FOUND@
3 3 #define EPOLL_FOUND @EPOLL_FOUND@ #define EPOLL_FOUND @EPOLL_FOUND@
4
5 #define _GNU_SOURCE
File Conn_engine_core.c changed (mode: 100644) (index 1ef5a31..f8c3b9f)
1 1 /* /*
2 2 * Author: Catalin(ux) M BOIE <catab at embedromix.ro> * Author: Catalin(ux) M BOIE <catab at embedromix.ro>
3 * Date: 2004-2008
3 * Date: 2004
4 4 * Description: Some functions to help writing network servers and clients, * Description: Some functions to help writing network servers and clients,
5 5 * both ipv4 and ipv6. * both ipv4 and ipv6.
6 6 * Licence: LGPL * Licence: LGPL
 
8 8
9 9 #include "Conn_engine_core.h" #include "Conn_engine_core.h"
10 10
11 #include <sys/epoll.h>
11 12
12 13 /* Visible variables */ /* Visible variables */
13 14 void (*Conn_accept_cb)(struct Conn *C) = NULL; void (*Conn_accept_cb)(struct Conn *C) = NULL;
 
... ... unsigned int Conn_default_obuf = 128;
30 31 unsigned int Conn_max_ibuf = 4096000; unsigned int Conn_max_ibuf = 4096000;
31 32 unsigned int Conn_max_obuf = 4096000; unsigned int Conn_max_obuf = 4096000;
32 33
33 /* Max bytes enqueued on one send/recv call */
34 /* Max bytes to enqueue on one send/recv call */
34 35 unsigned int Conn_max_send = 32 * 1024; unsigned int Conn_max_send = 32 * 1024;
35 36 unsigned int Conn_max_recv = 32 * 1024; unsigned int Conn_max_recv = 32 * 1024;
36 37
 
... ... char Conn_error[512];
60 61 FILE *Conn_Log = NULL; FILE *Conn_Log = NULL;
61 62 int debug_band = 11; int debug_band = 11;
62 63
63 /* Flags */
64 unsigned int CONN_POLLIN;
65 unsigned int CONN_POLLOUT;
66 unsigned int CONN_POLLPRI;
67 unsigned int CONN_POLLERR;
68 unsigned int CONN_POLLHUP;
69 unsigned int CONN_POLLNVAL;
70 unsigned int CONN_POLLRDNORM;
71 unsigned int CONN_POLLRDBAND;
72
73 64 /* queues */ /* queues */
74 65 struct Conn_queue Conn_queue_free; struct Conn_queue Conn_queue_free;
75 66
 
... ... int Conn_try_expand_buf(const unsigned int slot, const int what,
272 263 char *p; char *p;
273 264 unsigned int hm; unsigned int hm;
274 265 unsigned int old_size, amount, head, tail; unsigned int old_size, amount, head, tail;
275 unsigned int default_buf, buf_size, max_buf;
266 unsigned int buf_size, max_buf;
276 267 char *pbuf; char *pbuf;
277 268
278 269 if (what == 0) { if (what == 0) {
279 270 head = Conns[slot].obuf_head; head = Conns[slot].obuf_head;
280 271 tail = Conns[slot].obuf_tail; tail = Conns[slot].obuf_tail;
281 default_buf = Conn_default_obuf;
282 272 old_size = Conns[slot].obuf_size; old_size = Conns[slot].obuf_size;
283 273 buf_size = Conns[slot].obuf_size; buf_size = Conns[slot].obuf_size;
284 274 max_buf = Conn_max_obuf; max_buf = Conn_max_obuf;
 
... ... int Conn_try_expand_buf(const unsigned int slot, const int what,
286 276 } else { } else {
287 277 head = Conns[slot].ibuf_head; head = Conns[slot].ibuf_head;
288 278 tail = Conns[slot].ibuf_tail; tail = Conns[slot].ibuf_tail;
289 default_buf = Conn_default_ibuf;
290 279 old_size = Conns[slot].ibuf_size; old_size = Conns[slot].ibuf_size;
291 280 buf_size = Conns[slot].ibuf_size; buf_size = Conns[slot].ibuf_size;
292 281 max_buf = Conn_max_ibuf; max_buf = Conn_max_ibuf;
 
... ... void Conn_poll_status(const short ev, char *ret)
350 339
351 340 strcpy(ret, ""); strcpy(ret, "");
352 341
353 if (ev & CONN_POLLIN) ret[i++] = 'I';
354 if (ev & CONN_POLLPRI) ret[i++] = 'P';
355 if (ev & CONN_POLLOUT) ret[i++] = 'O';
356 if (ev & CONN_POLLERR) ret[i++] = 'E';
357 if (ev & CONN_POLLHUP) ret[i++] = 'H';
358 if (ev & CONN_POLLNVAL) ret[i++] = 'V';
359 if (ev & CONN_POLLRDNORM) ret[i++] = 'r';
360 if (ev & CONN_POLLRDBAND) ret[i++] = 'R';
342 if (ev & EPOLLIN) ret[i++] = 'I';
343 if (ev & EPOLLPRI) ret[i++] = 'P';
344 if (ev & EPOLLOUT) ret[i++] = 'O';
345 if (ev & EPOLLERR) ret[i++] = 'E';
346 if (ev & EPOLLHUP) ret[i++] = 'H';
347 if (ev & EPOLLNVAL) ret[i++] = 'V';
348 if (ev & EPOLLRDNORM) ret[i++] = 'N';
349 if (ev & EPOLLRDBAND) ret[i++] = 'B';
350 if (ev & EPOLLWRNORM) ret[i++] = 'n';
351 if (ev & EPOLLWRBAND) ret[i++] = 'b';
352 if (ev & EPOLLRDHUP) ret[i++] = 'h';
361 353 ret[i++] = '\0'; ret[i++] = '\0';
362 354 } }
363 355
 
... ... int Conn_set_cb(struct Conn *C, const unsigned int cb_type, void (*f)(struct Con
881 873
882 874 /* /*
883 875 * Search for str in active buffer from a given offset * Search for str in active buffer from a given offset
884 * Returns pointer to string if match or NUll if doesn't.
876 * Returns pointer to string if match or NULL if doesn't.
885 877 * @flags: bit 0 == 1 => case insensitive * @flags: bit 0 == 1 => case insensitive
886 878 */ */
887 879 char *Conn_ostrstr(struct Conn *C, const unsigned int off, const char *str, char *Conn_ostrstr(struct Conn *C, const unsigned int off, const char *str,
 
... ... void Conn_eat(struct Conn *C, const unsigned int bytes)
1010 1002 */ */
1011 1003 void Conn_eatall(struct Conn *C) void Conn_eatall(struct Conn *C)
1012 1004 { {
1013 Conn_eat(C, Conn_qlen(C));
1005 unsigned int slot;
1006
1007 slot = C->slot;
1008
1009 Conns[slot].ibuf_head = 0;
1010 Conns[slot].ibuf_tail = 0;
1014 1011 } }
1015 1012
1016 1013 /* /*
 
... ... struct Conn_split *Conn_split(const char *line0)
1346 1343 char *p; char *p;
1347 1344 struct Conn_split *ret = NULL; struct Conn_split *ret = NULL;
1348 1345 struct Conn_split_cell *q; struct Conn_split_cell *q;
1349 unsigned int i;
1350 1346 char search_for; char search_for;
1351 1347 char *left, *right; char *left, *right;
1352 1348 unsigned int right_len; unsigned int right_len;
 
... ... struct Conn_split *Conn_split(const char *line0)
1383 1379
1384 1380 /* Building left */ /* Building left */
1385 1381 left = p; left = p;
1386 i = 0;
1387 1382 while ((*p != '\0') && (*p != '=')) while ((*p != '\0') && (*p != '='))
1388 1383 p++; p++;
1389 1384 if (*p != '\0') { if (*p != '\0') {
 
... ... struct Conn_split *Conn_split(const char *line0)
1401 1396 p++; p++;
1402 1397 } }
1403 1398
1404 i = 0;
1405 1399 while ((*p != '\0') && (*p != search_for)) { while ((*p != '\0') && (*p != search_for)) {
1406 1400 right_len++; right_len++;
1407 1401 p++; p++;
File Conn_engine_core.h changed (mode: 100644) (index 18977aa..f91828e)
3 3
4 4 #include <Conn_config.h> #include <Conn_config.h>
5 5
6 #define _GNU_SOURCE
7
8 6 #include <stdarg.h> #include <stdarg.h>
9 7 #include <resolv.h> #include <resolv.h>
10 8 #include <errno.h> #include <errno.h>
 
... ... enum CONN_CB {
97 95 CONN_CB_ACCEPT_ERROR CONN_CB_ACCEPT_ERROR
98 96 }; };
99 97
100 /* Engine type */
101 enum CONN_ENGINE {
102 CONN_ENGINE_POLL = 1,
103 CONN_ENGINE_EPOLL
104 };
105
106 extern unsigned int CONN_POLLIN;
107 extern unsigned int CONN_POLLOUT;
108 extern unsigned int CONN_POLLPRI;
109 extern unsigned int CONN_POLLERR;
110 extern unsigned int CONN_POLLHUP;
111 extern unsigned int CONN_POLLNVAL;
112 extern unsigned int CONN_POLLRDNORM;
113 extern unsigned int CONN_POLLRDBAND;
114
115 98 struct Conn struct Conn
116 99 { {
117 100 int fd; int fd;
File Conn_engine_epoll.c changed (mode: 100644) (index 114f691..183b8d4)
1 1 #include <Conn_config.h> #include <Conn_config.h>
2 2
3 #ifdef EPOLL_FOUND
4
5 3 #include <Conn_engine_epoll.h> #include <Conn_engine_epoll.h>
6 4
7 5 /* /*
 
... ... int Conn_epoll_move_slot(const unsigned int dst, const unsigned int src)
211 209
212 210 return 0; return 0;
213 211 } }
214
215 #endif
File Conn_engine_epoll.h changed (mode: 100644) (index 5922a4e..2a42b3a)
1 1 #ifndef CONN_ENGINE_EPOLL_H #ifndef CONN_ENGINE_EPOLL_H
2 2 #define CONN_ENGINE_EPOLL_H #define CONN_ENGINE_EPOLL_H
3 3
4 #ifdef EPOLL_FOUND
5
6 4 #include <sys/epoll.h> #include <sys/epoll.h>
7 5
8 6 #include <Conn_engine_core.h> #include <Conn_engine_core.h>
 
... ... extern int Conn_epoll_move_slot(const unsigned int dst,
22 20 const unsigned int src); const unsigned int src);
23 21
24 22 #endif #endif
25
26 #endif
File Conn_engine_poll.c deleted (index 8a866db..0000000)
1 #include <Conn_config.h>
2
3 #ifdef POLL_FOUND
4
5 #include <Conn_engine_poll.h>
6
7 /*
8 * Variables
9 */
10 static unsigned long Conn_poll_allocated_slots = 0;
11 static struct pollfd *Conn_poll_pfds = NULL;
12
13 /*
14 * Functions
15 */
16
17 /*
18 * Init the engine
19 */
20 int Conn_poll_init(void)
21 {
22 return 0;
23 }
24
25 int Conn_poll_shutdown(void)
26 {
27 free(Conn_poll_pfds);
28
29 return 0;
30 }
31
32 /*
33 * Grow the number of slots needed for poll
34 */
35 int Conn_poll_grow(unsigned int alloc)
36 {
37 struct pollfd *p, *set;
38 unsigned int diff, mem;
39
40 Log(10, "%s: Trying to grow pollfds from %d to %d.\n",
41 __FUNCTION__,
42 Conn_poll_allocated_slots, alloc);
43
44 if (alloc <= Conn_poll_allocated_slots)
45 return 0;
46
47 diff = alloc - Conn_poll_allocated_slots;
48
49 mem = alloc * sizeof(struct pollfd);
50 p = (struct pollfd *) realloc(Conn_poll_pfds, mem);
51 if (p == NULL) {
52 snprintf(Conn_error, sizeof(Conn_error),
53 "Cannot alloc %u bytes for pollfds.", mem);
54 return -1;
55 }
56
57 set = p + Conn_poll_allocated_slots;
58 memset(set, 0, diff * sizeof(struct pollfd));
59 Conn_poll_pfds = p;
60
61 return 0;
62 }
63
64 /*
65 * Add a target to the list
66 */
67 int Conn_poll_add_obj(struct Conn *C)
68 {
69 Conn_poll_pfds[C->slot].fd = C->fd;
70 Conn_poll_pfds[C->slot].events = C->events;
71
72 return 0;
73 }
74
75 /*
76 * Remove a target from the list
77 */
78 int Conn_poll_del_obj(struct Conn *C)
79 {
80 Conn_poll_pfds[C->slot].fd = -1;
81 Conn_poll_pfds[C->slot].events = 0;
82
83 return 0;
84 }
85
86 /*
87 * Change event mask
88 */
89 int Conn_poll_chg_obj(struct Conn *C)
90 {
91 Conn_poll_pfds[C->slot].events = C->events;
92
93 return 0;
94 }
95
96
97 /*
98 * Calls a callback for fds with activity
99 * Returns: -1 on error, 0 nothing to do, n (>0) if some work was done
100 * timeout is in 1/1000 seconds increments.
101 */
102 int Conn_poll_poll(const int timeout2, void (*cb)(const unsigned int slot,
103 const int revents))
104 {
105 int slot, events;
106
107 Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2);
108 again:
109 events = poll(&Conn_poll_pfds[0], Conn_no, timeout2);
110 if ((events == -1) && (errno == EINTR))
111 goto again;
112
113 if (events < 0) {
114 snprintf(Conn_error, sizeof(Conn_error),
115 "%s: Conn_no=%d [%s]",
116 __FUNCTION__, Conn_no,
117 strerror(errno));
118 return -1;
119 }
120
121 gettimeofday(&Conn_now, NULL);
122
123 if (events == 0)
124 return 0;
125
126 /* We do revers scan because of moving Conn objects */
127 Log(11, "\tProcessing %d event(s)...\n",
128 events);
129 slot = Conn_no - 1;
130 do {
131 if (Conn_poll_pfds[slot].revents & POLLNVAL) {
132 Log(0, "BUG NVAL!\n");
133 exit(1);
134 }
135
136 cb(slot, Conn_poll_pfds[slot].revents);
137
138 slot--;
139 } while (slot >= 0);
140
141 return events;
142
143 }
144
145 /*
146 * Move a slot over an other.
147 */
148 int Conn_poll_move_slot(const unsigned int dst, const unsigned int src)
149 {
150 struct pollfd tmp;
151
152 tmp = Conn_poll_pfds[dst];
153 Conn_poll_pfds[dst] = Conn_poll_pfds[src];
154 Conn_poll_pfds[src] = tmp;
155
156 return 0;
157 }
158
159 #endif
File Conn_engine_poll.h deleted (index 183f7af..0000000)
1 #ifndef CONN_ENGINE_POLL_H
2 #define CONN_ENGINE_POLL_H
3
4 #ifdef POLL_FOUND
5
6 #include <sys/poll.h>
7
8 #include <Conn_engine_core.h>
9
10 extern int Conn_poll_init(void);
11 extern int Conn_poll_shutdown(void);
12 extern int Conn_poll_grow(unsigned int alloc);
13 extern int Conn_poll_add_obj(struct Conn *C);
14 extern int Conn_poll_del_obj(struct Conn *C);
15 extern int Conn_poll_chg_obj(struct Conn *C);
16 extern int Conn_poll_poll(const int timeout2, void (*cb)(const unsigned int slot,
17 const int revents));
18 extern int Conn_poll_move_slot(const unsigned int dst,
19 const unsigned int src);
20 #endif
21
22 #endif
File Makefile.in changed (mode: 100644) (index 7c701fd..c62a877)
... ... export CC := gcc
2 2 export INCS += -I. export INCS += -I.
3 3 export LIBS += -lpthread export LIBS += -lpthread
4 4 export CFLAGS += -ggdb3 -Wall -Wextra -pedantic -Wno-long-long -pipe -fpic export CFLAGS += -ggdb3 -Wall -Wextra -pedantic -Wno-long-long -pipe -fpic
5 export OBJS += Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn.o \
5 export OBJS += Conn_engine_core.o Conn_engine_epoll.o Conn.o \
6 6 Conn_wpool.o Conn_wpool.o
7 7
8 8 .PHONY: all .PHONY: all
 
... ... all: libConn.so.@VER@
12 12 Conn_engine_core.o: Conn_engine_core.c Conn_engine_core.h Conn_config.h Conn_engine_core.o: Conn_engine_core.c Conn_engine_core.h Conn_config.h
13 13 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_core.c $(CC) $(CFLAGS) $(INCS) -c Conn_engine_core.c
14 14
15 Conn_engine_poll.o: Conn_engine_poll.c Conn_config.h Conn_engine_core.h
16 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_poll.c
17
18 15 Conn_engine_epoll.o: Conn_engine_epoll.c Conn_config.h Conn_engine_core.h Conn_engine_epoll.o: Conn_engine_epoll.c Conn_config.h Conn_engine_core.h
19 16 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c
20 17
21 18 Conn_wpool.o: Conn_wpool.c Conn_wpool.h Conn_engine_core.o Conn_config.h Conn_wpool.o: Conn_wpool.c Conn_wpool.h Conn_engine_core.o Conn_config.h
22 19 $(CC) $(CFLAGS) $(INCS) -c Conn_wpool.c $(CC) $(CFLAGS) $(INCS) -c Conn_wpool.c
23 20
24 Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn_wpool.o
21 Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_epoll.o Conn_wpool.o
25 22 $(CC) $(CFLAGS) $(INCS) -c Conn.c $(CC) $(CFLAGS) $(INCS) -c Conn.c
26 23
27 24 %.o: %.c %.o: %.c
File TODO changed (mode: 100644) (index 00f1837..76d81cb)
20 20 [ ] Fix the whole list scanning for expiration, band and closing. [ ] Fix the whole list scanning for expiration, band and closing.
21 21 [ ] Put callbacks in a structure to free some space from struct Conn. [ ] Put callbacks in a structure to free some space from struct Conn.
22 22 [ ] wpool: When we free a Conn structure, we have to Conn_del_wp! [ ] wpool: When we free a Conn structure, we have to Conn_del_wp!
23 [ ] wpool: What if we add master sockets also to workers and do nothing in main
24 thread? Check ma.c example. Verified: accept waks in only one thread.
25 Still to check if epoll wakes in all threads! Seems it wakes all threads!
26 Not very good.
27 [ ] Investigate splice.
28 [ ] Investigate MSG_MORE as an alternative to CORK or writev.
29 [ ]
23 30
24 31 [ ] Check if we are swapping and warn. [ ] Check if we are swapping and warn.
25 32 [ ] Log faults and io. [ ] Log faults and io.
File examples/Makefile changed (mode: 100644) (index 5a96c10..5bcf908)
1 CFLAGS += -Wall -Wextra -g
2
1 3 TARGETS := s c raw udp_s timeout trigger reconnect ntime blackhole_s blackhole_c \ TARGETS := s c raw udp_s timeout trigger reconnect ntime blackhole_s blackhole_c \
2 4 xbind \ xbind \
3 5 wpool1 wpool1
 
... ... xbind: xbind.c $(DEPS)
51 53 wpool1: wpool1.c $(DEPS) wpool1: wpool1.c $(DEPS)
52 54 gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS)
53 55
56 ma: ma.c
57 gcc $(CFLAGS) $(INCS) $@.c -o $@ -lpthread
58
54 59 %: %.c $(DEPS) %: %.c $(DEPS)
55 60 gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS)
56 61
File examples/raw.c changed (mode: 100644) (index c4464ae..e5ac141)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
File examples/raw2.c changed (mode: 100644) (index 4145267..bf71e2b)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
File examples/s.c changed (mode: 100644) (index 020ab87..d060697)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
File examples/trigger.c changed (mode: 100644) (index cf898fd..43e6bc5)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
File examples/udp_s.c changed (mode: 100644) (index 4636c16..bd450e8)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
File examples/xbind.c changed (mode: 100644) (index e1aefc2..de66da2)
5 5 #include <strings.h> #include <strings.h>
6 6 #include <stdlib.h> #include <stdlib.h>
7 7 #include <unistd.h> #include <unistd.h>
8 #include <sys/poll.h>
9 8 #include <sys/types.h> #include <sys/types.h>
10 9 #include <sys/socket.h> #include <sys/socket.h>
11 10 #include <stdio.h> #include <stdio.h>
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/Conn

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/Conn

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main