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 a69db41578de7ded49d656b7ea7cfae76c6695d9 Catalin(ux) M. BOIE 2010-09-30 22:01:30
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
If slot is in FREE state and we get events, do not abort, but log an error. 52301f684bb4a49fd74556f8b15fee643c4bfb06 Catalin(ux) M. BOIE 2010-06-07 20:25:21
More verbose logging and added some TODOs. a27014689701b1dd3d0e3c02629d3c7dd0edc77e Catalin(ux) M. BOIE 2010-06-07 20:24:43
Added Conn_[io]qlen and obsoleted Conn_qlen (ambiguous). be3822589afe052fade15fd81afee3549217131a Catalin(ux) M. BOIE 2010-06-07 20:23:39
Use u32 field of epoll. ptr on 64bit gave an warning. 37c86810ceaadd0c8139f11e3737577efea4cabd Catalin(ux) M. BOIE 2010-06-07 19:46:15
Export CONN_VERSION in Conn_config.h d34d7a1da235b00c3aa1c8e0494310c4dd100886 Catalin(ux) M. BOIE 2010-06-07 19:45:53
In Conn_poll_cb, show human readable events. a3e305582e9bf1185254f8feeab90c51af626443 Catalin(ux) M. BOIE 2010-06-07 17:22:49
Commit a69db41578de7ded49d656b7ea7cfae76c6695d9 - WIP
Author: Catalin(ux) M. BOIE
Author date (UTC): 2010-09-30 22:01
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2010-09-30 22:01
Parent(s): 089b68cf9fc5c16ee7d8136b28a52ec4dd139c78
Signing key:
Tree: e83f490ef30d39d56a3a7b0e79e47ced9cf4742d
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 1 0
examples/.gitignore 1 0
examples/Makefile 5 1
File Conn.c changed (mode: 100644) (index ab4bea8..3fc5876)
... ... static void Conn_accept(const unsigned int slot)
858 858
859 859 X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY; X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY;
860 860
861 err = Conn_engine_add_obj(X);
862 if (err != 0) {
863 Conn_error_raise(slot, err);
864 Conn_free_intern(X->slot);
865 return;
866 }
861 if (Conns[slot].wp != NULL) {
862 struct Conn_wpool *wp = Conns[slot].wp;
863 struct Conn_wpool_worker *w = &wp->wi[0];
864 struct epoll_event ev;
865
866 memset(&ev, 0, sizeof(struct epoll_event));
867 ev.events = X->events;
868 ev.data.u32 = X->slot;
869 err = epoll_ctl(w->epoll_fd, EPOLL_CTL_ADD, X->fd, &ev);
870 if (err != 0) {
871 Conn_error_raise(slot, err);
872 Conn_free_intern(X->slot);
873 return;
874 }
875 /* TODO: send signaling to thread to call accept callback */
876 /* TODO: maybe we want to pass the fd also by signaling channel */
877 } else {
878 err = Conn_engine_add_obj(X);
879 if (err != 0) {
880 Conn_error_raise(slot, err);
881 Conn_free_intern(X->slot);
882 return;
883 }
867 884
868 if (Conns[slot].cb_accept)
869 Conns[slot].cb_accept(X);
870 else if (Conn_accept_cb != NULL)
871 Conn_accept_cb(X);
885 if (Conns[slot].cb_accept)
886 Conns[slot].cb_accept(X);
887 else if (Conn_accept_cb != NULL)
888 Conn_accept_cb(X);
889 }
872 890
873 891 Conn_work_to_do++; Conn_work_to_do++;
874 892
 
... ... static void Conn_accept_allow(void)
892 910
893 911 if (Conn_accept_is_allowed == 0) if (Conn_accept_is_allowed == 0)
894 912 Conns[slot].events &= ~CONN_POLLIN; Conns[slot].events &= ~CONN_POLLIN;
895 else
913 else
896 914 Conns[slot].events |= CONN_POLLIN; Conns[slot].events |= CONN_POLLIN;
897 915
898 916 Conn_engine_chg_obj(&Conns[slot]); Conn_engine_chg_obj(&Conns[slot]);
 
... ... unsigned long long Conn_lifetime(struct Conn *C)
1435 1453
1436 1454 return Conn_time_diff(&Conn_now, &Conns[slot].time_open); return Conn_time_diff(&Conn_now, &Conns[slot].time_open);
1437 1455 } }
1456
1457 /*
1458 * Associate a Conn with a workers pool
1459 */
1460 void Conn_add_wp(struct Conn *C, struct Conn_wpool *wp)
1461 {
1462 wp->users++;
1463 C->wp = wp;
1464 }
1465
1466 /*
1467 * Disassociate a Conn with a workers pool
1468 */
1469 void Conn_del_wp(struct Conn *C, struct Conn_wpool *wp)
1470 {
1471 Conn_wpool_destroy(wp);
1472 C->wp = NULL;
1473 }
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 3c820df..cf2a007)
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 -O0 export CFLAGS += -ggdb3 -Wall -Wextra -pedantic -Wno-long-long -pipe -fpic -O0
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@ libConn.a all: libConn.so.@VER@ libConn.a
 
... ... 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 56c4068..ec136e5)
14 14 [ ] Add a function to set the maximum number of connections. [ ] Add a function to set the maximum number of connections.
15 15 [ ] Fix the whole list scanning for expiration, band and closing. [ ] Fix the whole list scanning for expiration, band and closing.
16 16 [ ] Put callbacks in a structure to free some space from struct Conn. [ ] Put callbacks in a structure to free some space from struct Conn.
17 [ ] wpool: When we free a Conn structure, we have to Conn_del_wp!
17 18
18 19 [ ] Add access control [ ] Add access control
19 20 Conn_ac_set_default(C, CONN_AC_DENY) - default deny (or CONN_AC_ALLOW) Conn_ac_set_default(C, CONN_AC_DENY) - default deny (or CONN_AC_ALLOW)
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