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 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
Wrong cache consulted! 6d018b014156ada0bf1a138ac2178386f6bb90ab Catalin(ux) M. BOIE 2010-06-08 15:03:34
Commit 15f063f9d34d3f7b7ae9d9e83f59b4077515122b - WIP
Author: Catalin(ux) M. BOIE
Author date (UTC): 2010-09-30 22:01
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2013-09-24 19:36
Parent(s): d3b1c4ccd591627e7faa0eeaaa3b2bc1ee20709e
Signing key:
Tree: 6c760af56a8e6535063e8c0edb3c02795df5def6
File Lines added Lines deleted
Conn.c 47 11
Conn.h 5 0
Conn_engine_core.h 4 0
Conn_engine_epoll.c 14 7
Conn_engine_epoll.h 5 2
Makefile.in 7 3
TODO 3 0
examples/.gitignore 1 0
examples/Makefile 5 1
File Conn.c changed (mode: 100644) (index bee2aa8..db74d46)
... ... static void Conn_accept(const unsigned int slot)
863 863
864 864 X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY; X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY;
865 865
866 err = Conn_engine_add_obj(X);
867 if (err != 0) {
868 Conn_error_raise(slot, err);
869 Conn_free_intern(X->slot);
870 return;
871 }
866 if (Conns[slot].wp != NULL) {
867 struct Conn_wpool *wp = Conns[slot].wp;
868 struct Conn_wpool_worker *w = &wp->wi[0];
869 struct epoll_event ev;
870
871 memset(&ev, 0, sizeof(struct epoll_event));
872 ev.events = X->events;
873 ev.data.u32 = X->slot;
874 err = epoll_ctl(w->epoll_fd, EPOLL_CTL_ADD, X->fd, &ev);
875 if (err != 0) {
876 Conn_error_raise(slot, err);
877 Conn_free_intern(X->slot);
878 return;
879 }
880 /* TODO: send signaling to thread to call accept callback */
881 /* TODO: maybe we want to pass the fd also by signaling channel */
882 } else {
883 err = Conn_engine_add_obj(X);
884 if (err != 0) {
885 Conn_error_raise(slot, err);
886 Conn_free_intern(X->slot);
887 return;
888 }
872 889
873 if (Conns[slot].cb_accept)
874 Conns[slot].cb_accept(X);
875 else if (Conn_accept_cb != NULL)
876 Conn_accept_cb(X);
890 if (Conns[slot].cb_accept)
891 Conns[slot].cb_accept(X);
892 else if (Conn_accept_cb != NULL)
893 Conn_accept_cb(X);
894 }
877 895
878 896 Conn_work_to_do++; Conn_work_to_do++;
879 897
 
... ... static void Conn_accept_allow(void)
897 915
898 916 if (Conn_accept_is_allowed == 0) if (Conn_accept_is_allowed == 0)
899 917 Conns[slot].events &= ~CONN_POLLIN; Conns[slot].events &= ~CONN_POLLIN;
900 else
918 else
901 919 Conns[slot].events |= CONN_POLLIN; Conns[slot].events |= CONN_POLLIN;
902 920
903 921 Conn_engine_chg_obj(&Conns[slot]); Conn_engine_chg_obj(&Conns[slot]);
 
... ... unsigned long long Conn_lifetime(struct Conn *C)
1440 1458
1441 1459 return Conn_time_diff(&Conn_now, &Conns[slot].time_open); return Conn_time_diff(&Conn_now, &Conns[slot].time_open);
1442 1460 } }
1461
1462 /*
1463 * Associate a Conn with a workers pool
1464 */
1465 void Conn_add_wp(struct Conn *C, struct Conn_wpool *wp)
1466 {
1467 wp->users++;
1468 C->wp = wp;
1469 }
1470
1471 /*
1472 * Disassociate a Conn with a workers pool
1473 */
1474 void Conn_del_wp(struct Conn *C, struct Conn_wpool *wp)
1475 {
1476 Conn_wpool_destroy(wp);
1477 C->wp = NULL;
1478 }
File Conn.h changed (mode: 100644) (index e10421b..9823f64)
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>
5 6
6 7 extern int Conn_engine_set(const unsigned int engine); extern int Conn_engine_set(const unsigned int engine);
7 8 extern int Conn_init(const unsigned int max); extern int Conn_init(const unsigned int max);
 
... ... extern struct Conn *Conn_alloc(void);
30 31 extern int Conn_commit(struct Conn *C); extern int Conn_commit(struct Conn *C);
31 32 extern char *Conn_sys(void); extern char *Conn_sys(void);
32 33 extern unsigned long long Conn_lifetime(struct Conn *C); extern unsigned long long Conn_lifetime(struct Conn *C);
34
35 /* wpool */
36 extern void Conn_add_wp(struct Conn *C, struct Conn_wpool *wp);
37 extern void Conn_del_wp(struct Conn *C, struct Conn_wpool *wp);
33 38 #endif #endif
File Conn_engine_core.h changed (mode: 100644) (index 1b67b22..18977aa)
... ... enum CONN_ERROR {
70 70 #define CONN_FLAGS_CLOSE_AFTER_SEND 1 << 1 #define CONN_FLAGS_CLOSE_AFTER_SEND 1 << 1
71 71 #define CONN_ADDR_LOCAL_DIRTY 1 << 2 #define CONN_ADDR_LOCAL_DIRTY 1 << 2
72 72 #define CONN_ADDR_REMOTE_DIRTY 1 << 3 #define CONN_ADDR_REMOTE_DIRTY 1 << 3
73 #define CONN_ACCEPT_PENDING 1 << 4
73 74
74 75 /* Parameters */ /* Parameters */
75 76 enum CONN_PARA { enum CONN_PARA {
 
... ... struct Conn
182 183 void (*cb_accept_error)(struct Conn *C); void (*cb_accept_error)(struct Conn *C);
183 184
184 185 struct timeval time_open; /* When a connect succeded */ struct timeval time_open; /* When a connect succeded */
186
187 /* wpool */
188 struct Conn_wpool *wp;
185 189 }; };
186 190
187 191 struct Conn_queue_entry struct Conn_queue_entry
File Conn_engine_epoll.c changed (mode: 100644) (index 51e1c11..114f691)
... ... int Conn_epoll_chg_obj(struct Conn *C)
154 154 * Returns: -1 on error, 0 nothing to do, n (>0) if some work was done * Returns: -1 on error, 0 nothing to do, n (>0) if some work was done
155 155 * timeout is in 1/1000 seconds increments. * timeout is in 1/1000 seconds increments.
156 156 */ */
157 int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot,
158 const int revents))
157 int Conn_epoll_poll_core(int fd, struct epoll_event *ee,
158 const unsigned int max, const int timeout2,
159 void (*cb)(const unsigned int slot, const unsigned int revents))
159 160 { {
160 161 int i, events; int i, events;
161 162 unsigned int slot; unsigned int slot;
162 163
163 164 Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2); Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2);
164 165 again: again:
165 events = epoll_wait(Conn_epoll_fd, Conn_epoll_events, Conn_no, timeout2);
166 events = epoll_wait(fd, ee, max, timeout2);
166 167 if ((events == -1) && (errno == EINTR)) if ((events == -1) && (errno == EINTR))
167 168 goto again; goto again;
168 169
169 170 if (events < 0) { if (events < 0) {
170 171 snprintf(Conn_error, sizeof(Conn_error), snprintf(Conn_error, sizeof(Conn_error),
171 "%s: Conn_no=%d [%s]",
172 __FUNCTION__, Conn_no, strerror(errno));
172 "%s: max=%d [%s]",
173 __FUNCTION__, max, strerror(errno));
173 174 return -1; return -1;
174 175 } }
175 176
 
... ... int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot,
181 182 Log(11, "\tProcessing %d event(s)...\n", events); Log(11, "\tProcessing %d event(s)...\n", events);
182 183 i = events - 1; i = events - 1;
183 184 do { do {
184 slot = Conn_epoll_events[i].data.u32;
185 cb(slot, Conn_epoll_events[i].events);
185 slot = ee[i].data.u32;
186 cb(slot, ee[i].events);
186 187
187 188 i--; i--;
188 189 } while (i >= 0); } while (i >= 0);
 
... ... int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot,
190 191 return events; return events;
191 192 } }
192 193
194 int Conn_epoll_poll(const int timeout2,
195 void (*cb)(const unsigned int slot, const unsigned int events))
196 {
197 return Conn_epoll_poll_core(Conn_epoll_fd, Conn_epoll_events, Conn_no, timeout2, cb);
198 }
199
193 200 /* /*
194 201 * Move a slot over an other. * Move a slot over an other.
195 202 */ */
File Conn_engine_epoll.h changed (mode: 100644) (index b8597ef..5922a4e)
... ... extern int Conn_epoll_grow(unsigned int alloc);
13 13 extern int Conn_epoll_add_obj(struct Conn *C); extern int Conn_epoll_add_obj(struct Conn *C);
14 14 extern int Conn_epoll_del_obj(struct Conn *C); extern int Conn_epoll_del_obj(struct Conn *C);
15 15 extern int Conn_epoll_chg_obj(struct Conn *C); extern int Conn_epoll_chg_obj(struct Conn *C);
16 extern int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot,
17 const int revents));
16 extern int Conn_epoll_poll_core(const int fd, struct epoll_event *ee,
17 const unsigned int max, const int timeout2,
18 void (*cb)(const unsigned int slot, const unsigned int revents));
19 extern int Conn_epoll_poll(const int timeout2,
20 void (*cb)(const unsigned int slot, const unsigned int revents));
18 21 extern int Conn_epoll_move_slot(const unsigned int dst, extern int Conn_epoll_move_slot(const unsigned int dst,
19 22 const unsigned int src); const unsigned int src);
20 23
File Makefile.in changed (mode: 100644) (index 3dca4a4..7c701fd)
1 1 export CC := gcc export CC := gcc
2 2 export INCS += -I. export INCS += -I.
3 export LIBS +=
3 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_poll.o Conn_engine_epoll.o Conn.o \
6 Conn_wpool.o
6 7
7 8 .PHONY: all .PHONY: all
8 9 all: libConn.so.@VER@ all: libConn.so.@VER@
 
... ... Conn_engine_poll.o: Conn_engine_poll.c Conn_config.h Conn_engine_core.h
17 18 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
18 19 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c
19 20
20 Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o
21 Conn_wpool.o: Conn_wpool.c Conn_wpool.h Conn_engine_core.o Conn_config.h
22 $(CC) $(CFLAGS) $(INCS) -c Conn_wpool.c
23
24 Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn_wpool.o
21 25 $(CC) $(CFLAGS) $(INCS) -c Conn.c $(CC) $(CFLAGS) $(INCS) -c Conn.c
22 26
23 27 %.o: %.c %.o: %.c
File TODO changed (mode: 100644) (index 21c1e62..00f1837)
19 19 [ ] Add a function to set the maximum number of connections. [ ] Add a function to set the maximum number of connections.
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 [ ] wpool: When we free a Conn structure, we have to Conn_del_wp!
23
22 24 [ ] Check if we are swapping and warn. [ ] Check if we are swapping and warn.
23 25 [ ] Log faults and io. [ ] Log faults and io.
24 26 [ ] We must have a single set of pointers to callback, not many. At Conn creation, [ ] We must have a single set of pointers to callback, not many. At Conn creation,
 
29 31 Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6 Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6
30 32 Conn_ac_add(C, CONN_AC_ALLOW, "192.168.0.0/25"); - for ipv4 Conn_ac_add(C, CONN_AC_ALLOW, "192.168.0.0/25"); - for ipv4
31 33 [ ] A la redir stuff [ ] A la redir stuff
34
32 35 [ ] Bridge 2 connections together for proxy stuff. [ ] Bridge 2 connections together for proxy stuff.
33 36 [ ] Check PACKET: can we send with "send" without knowing the MAC? [ ] Check PACKET: can we send with "send" without knowing the MAC?
34 37 [ ] UDP [ ] UDP
File examples/.gitignore changed (mode: 100644) (index c07283d..40a4de7)
... ... blackhole_c
13 13 rund rund
14 14 ntime ntime
15 15 xbind1 xbind1
16 wpool1
File examples/Makefile changed (mode: 100644) (index 50ff55e..5a96c10)
1 1 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 xbind
2 xbind \
3 wpool1
3 4
4 5 all: $(TARGETS) all: $(TARGETS)
5 6
 
... ... test1: test1.c $(DEPS)
47 48 xbind: xbind.c $(DEPS) xbind: xbind.c $(DEPS)
48 49 gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS)
49 50
51 wpool1: wpool1.c $(DEPS)
52 gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS)
53
50 54 %: %.c $(DEPS) %: %.c $(DEPS)
51 55 gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS)
52 56
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