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)
Constify a lot of parameters and added more consistent logging. 8b15034895c7e63be9b9ca68e4b41c9a52618d10 Catalin(ux) M. BOIE 2009-02-26 10:46:05
Stuff in/out. 074bc88cec80384ade2f4309840a7d2c6f15a700 Catalin(ux) M. BOIE 2009-02-26 10:41:16
Remove 'slot' concept from anywhere I could. It was confusing. eacc7a0b5355ffa8f71dc07631209e2f805edd03 Catalin(ux) M. BOIE 2009-02-23 15:21:53
Use valgrind in examples to catch errors. 3520092ef3e946840bc13fd1891b22645cf085a5 Catalin(ux) M. BOIE 2009-02-23 15:21:23
Some cosmetic changes for examples. 2fc9e92d9fb24568a13355db191e5bf64d601ee8 Catalin(ux) M. BOIE 2009-02-23 15:21:02
More TODO entries added/removed. eb5a15672c8adf3c3da2425582b1e842c6127b13 Catalin(ux) M. BOIE 2009-02-23 15:20:04
Minor cosmetic changes. 5955b574710254e771bbf9d81a8712033c9f1464 Catalin(ux) M. BOIE 2009-02-23 11:32:20
Added support for multiple polling engines and added epoll engine. ecf8b9c40ddae857b9d7dd72dee6596c1689db3e Catalin(ux) M. BOIE 2009-02-23 10:02:39
Duilder updates. db4999d6737f84d17c3b9aa5863483c91d6ed1a7 Catalin(ux) M. BOIE 2008-12-08 14:17:02
Bump up the version to 1.0.11. c623ba1f66e79d758d88407b6224c3574d9fd730 Catalin(ux) M. BOIE 2008-07-16 06:38:33
Added Conn_for_every_line. e7b9ae7009aa9a5cafa1f0f4e3916729f69dbb6b Catalin(ux) M. BOIE 2008-07-15 14:38:29
Bump version to 1.0.10. 4919629756fe6236e2ff75e646e612ed534353e8 Catalin(ux) M. BOIE 2008-07-04 09:23:00
Updated duilder. a20257fddc85103b43978c64d9cd4a5d4c1451ea Catalin(ux) M. BOIE 2008-07-04 09:14:18
Added SRPM_POST_RUN duilder config variable. f7c007d745d147f285ad8bc0a9bdfea3a7d832c0 Catalin(ux) M. BOIE 2008-07-04 09:13:47
Changed my e-mail address and URL. 9353a5fd0cad934232e41b23ee10872f33df2da1 Catalin(ux) M. BOIE 2008-07-04 09:13:10
Updated .gitignore. c40b1c4bf37a2b43804e39444571110eb79be466 Catalin(ux) M. BOIE 2008-07-04 09:07:56
Added .gitignore for examples directory. fc20d411e784066c30e3abe3d77989168fca1ee9 Catalin(ux) M. BOIE 2008-07-04 09:07:33
Added Conn_get_line. 5916ac4c9544d242a21ac50178efae893dff4806 Catalin(ux) M. BOIE 2008-07-04 08:59:27
Prepared to use duilder (my custom builder). 058d181795e64c0d1a82d587e7b1d858b7af87b2 Catalin(ux) M. BOIE 2008-03-21 13:37:19
Populated .gitignore file. e549ac0271ac654f039d5a04a0708d25030b0ed6 Catalin(ux) M. BOIE 2008-03-21 13:12:49
Commit 8b15034895c7e63be9b9ca68e4b41c9a52618d10 - Constify a lot of parameters and added more consistent logging.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-02-26 10:46
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-03-05 15:31
Parent(s): 074bc88cec80384ade2f4309840a7d2c6f15a700
Signing key:
Tree: 40d853c233f4cc6d6ee0155baec5693ec8942d56
File Lines added Lines deleted
Conn.c 29 28
Conn.h 13 12
Conn_engine_core.c 1 1
Conn_engine_core.h 1 1
Makefile.in 6 3
examples/c.c 8 13
examples/s.c 1 1
File Conn.c changed (mode: 100644) (index a8aa5b7..05261cd)
... ... int Conn_engine_set(const unsigned int engine)
102 102 return 0; return 0;
103 103 } }
104 104
105 int Conn_init(unsigned int max)
105 int Conn_init(const unsigned int max)
106 106 { {
107 107 unsigned int ret; unsigned int ret;
108 108 unsigned int engine; unsigned int engine;
 
... ... static struct Conn *Conn_alloc(void)
389 389 return &Conns[slot]; return &Conns[slot];
390 390 } }
391 391
392 struct Conn *Conn_socket(int domain, int type, int port)
392 struct Conn *Conn_socket(const int domain, const int type, const int port)
393 393 { {
394 394 struct Conn *C; struct Conn *C;
395 395 int i, ret; int i, ret;
 
... ... struct Conn *Conn_socket(int domain, int type, int port)
530 530 return NULL; return NULL;
531 531 } }
532 532
533 struct Conn *Conn_connect(int domain, int type, char *addr, int port)
533 struct Conn *Conn_connect(const int domain, const int type, const char *addr,
534 const int port)
534 535 { {
535 536 struct Conn *X; struct Conn *X;
536 unsigned int Xslot;
537 537
538 538 Log(8, "%s(%s, %d)\n", Log(8, "%s(%s, %d)\n",
539 539 __FUNCTION__, addr, port); __FUNCTION__, addr, port);
 
... ... static void Conn_band_update(struct Conn *C)
717 717 if (C->band_tokens > C->band_factor * C->band_width) if (C->band_tokens > C->band_factor * C->band_width)
718 718 C->band_tokens = C->band_factor * C->band_width; C->band_tokens = C->band_factor * C->band_width;
719 719
720 slot = C->slot;
721 Conns[slot].events |= CONN_POLLOUT;
722 Conn_engine_chg_obj(&Conns[slot]);
720 C->events |= CONN_POLLOUT;
721 Conn_engine_chg_obj(C);
723 722
724 Log(debug_band, "\t\tBAND: Added tokens -> %u.\n",
725 C->band_tokens);
723 Log(debug_band, "\t\tBAND: slot=%u, id=%llu, added tokens -> %u.\n",
724 C->slot, C->id, C->band_tokens);
726 725 } }
727 726
728 727 /* /*
729 728 * Set the bandwidth for a connection * Set the bandwidth for a connection
730 729 * width is in 1b increments * width is in 1b increments
731 730 */ */
732 int Conn_band(struct Conn *C, unsigned int width, unsigned int factor)
731 int Conn_band(struct Conn *C, const unsigned int width,
732 const unsigned int factor)
733 733 { {
734 Log(11, "\tConn_band(C, width=%u, factor=%u)\n",
735 width, factor);
734 Log(11, "\tConn_band: slot=%u, id=%llu, width=%u, factor=%u.\n",
735 C->slot, C->id, width, factor);
736 736
737 737 C->band_lasttime = Conn_now; C->band_lasttime = Conn_now;
738 738 C->band_width = width; C->band_width = width;
 
... ... static void Conn_trytoconnect(void)
768 768 if (Conns[i].state != CONN_STATE_CONNECT_a) if (Conns[i].state != CONN_STATE_CONNECT_a)
769 769 continue; continue;
770 770
771 Log(9, "\tTry to connect to %s/%d...\n",
772 Conns[i].addr, Conns[i].port);
771 Log(9, "\tTry to connect slot=%u, id=%llu, to %s/%d...\n",
772 Conns[i].slot, Conns[i].id, Conns[i].addr, Conns[i].port);
773 773
774 774 memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
775 775 if (Conns[i].sock_domain == 0) if (Conns[i].sock_domain == 0)
 
... ... static void Conn_trytoconnect(void)
829 829 } }
830 830
831 831 Conns[i].state = CONN_STATE_CONNECT_b; Conns[i].state = CONN_STATE_CONNECT_b;
832
832 833 Conn_pending--; Conn_pending--;
833 834 Conn_total++; Conn_total++;
834 835
 
... ... static void Conn_send_cb_i(struct Conn *C)
846 847 int xerrno; int xerrno;
847 848 char *dump; char *dump;
848 849
849 Log(10, "Conn_send_cb_i id=%llu, slot=%u...\n",
850 C->id, C->slot);
850 Log(10, "Conn_send_cb_i slot=%u, id=%llu, head=%u, tail=%u, size=%u...\n",
851 C->slot, C->id, C->obuf_head, C->obuf_tail, C->obuf_size);
851 852
852 853 slot = C->slot; slot = C->slot;
853 854
 
... ... static void Conn_send_cb_i(struct Conn *C)
875 876 } }
876 877
877 878 again: again:
878 Log(10, "\tsend(fd%d, buf (head=%u, tail=%u), max=%d (count=%d), 0)...\n",
879 Log(10, "\tsend(fd=%d, buf (head=%u, tail=%u), max=%d (count=%d), 0)...\n",
879 880 Conns[slot].fd, Conns[slot].obuf_head, Conns[slot].fd, Conns[slot].obuf_head,
880 881 Conns[slot].obuf_tail, max, count); Conns[slot].obuf_tail, max, count);
881 882 n = send(Conns[slot].fd, buf, max, 0); n = send(Conns[slot].fd, buf, max, 0);
 
... ... static void Conn_send_cb_i(struct Conn *C)
886 887 if ((n == -1) && (errno == EAGAIN)) if ((n == -1) && (errno == EAGAIN))
887 888 return; return;
888 889
889 Log(10, "%s: Slot %u: FD%d Sent %d bytes [head=%d tail=%d]\n",
890 __FUNCTION__, slot, Conns[slot].fd,
890 Log(10, "%s: slot=%u, id=%llu: fd=%d Sent %d bytes [head=%d tail=%d]\n",
891 __FUNCTION__, slot, Conns[slot].id, Conns[slot].fd,
891 892 n, Conns[slot].obuf_head, Conns[slot].obuf_tail); n, Conns[slot].obuf_head, Conns[slot].obuf_tail);
892 893 if (Conn_level >= 10) { if (Conn_level >= 10) {
893 894 dump = Conn_dump(buf, n); dump = Conn_dump(buf, n);
 
... ... static void Conn_send_cb_i(struct Conn *C)
912 913 n, Conns[slot].band_tokens); n, Conns[slot].band_tokens);
913 914 } }
914 915 } else { } else {
915 Log(0, "%s: Error in send [id %llu] [slot %u] [%s]\n",
916 Log(0, "%s: Error in send (slot=%u, id=%llu) [%s]\n",
916 917 __FUNCTION__, __FUNCTION__,
917 Conns[slot].id, slot, strerror(errno));
918 slot, Conns[slot].id, strerror(errno));
918 919 Conns[slot].error_state = CONN_ERROR_SEND; Conns[slot].error_state = CONN_ERROR_SEND;
919 920 Conns[slot].xerrno = xerrno; Conns[slot].xerrno = xerrno;
920 921 } }
 
... ... static void Conn_send_cb_i(struct Conn *C)
922 923
923 924 static void Conn_recv_cb_i(struct Conn *C) static void Conn_recv_cb_i(struct Conn *C)
924 925 { {
925 ssize_t n;
926 ssize_t n;
926 927 unsigned int max; unsigned int max;
927 928 unsigned int slot; unsigned int slot;
928 929 int r, xerrno; int r, xerrno;
929 930 char *dump; char *dump;
930 931
931 Log(10, "Conn_recv_cb_i id=%llu, slot=%u...\n",
932 C->id, C->slot);
932 Log(10, "Conn_recv_cb_i slot=%u, id=%llu, head=%u, tail=%u, size=%u...\n",
933 C->slot, C->id, C->ibuf_head, C->ibuf_tail, C->ibuf_size);
933 934
934 935 slot = C->slot; slot = C->slot;
935 936
 
... ... static void Conn_recv_cb_i(struct Conn *C)
955 956 break; break;
956 957 } }
957 958
958 Log(10, "%s: Slot %u: FD%d Received %d bytes.\n",
959 __FUNCTION__, slot, Conns[slot].fd, n);
959 Log(10, "%s: slot=%u, id=%llu: fd=%d Received %d bytes.\n",
960 __FUNCTION__, slot, Conns[slot].id, Conns[slot].fd, n);
960 961
961 962 if (n > 0) { if (n > 0) {
962 963 if (Conn_level >= 10) { if (Conn_level >= 10) {
 
... ... static void Conn_recv_cb_i(struct Conn *C)
978 979 } else if (n == 0) { } else if (n == 0) {
979 980 Conns[slot].error_state = CONN_ERROR_HANGUP; Conns[slot].error_state = CONN_ERROR_HANGUP;
980 981 } else { } else {
981 Log(4, "Error in recv id %llu slot %u [%s]\n",
982 Conns[slot].id, slot, strerror(errno));
982 Log(4, "Error in recv (slot=%u, id=%llu) [%s]\n",
983 slot, Conns[slot].id, strerror(errno));
983 984 Conns[slot].error_state = CONN_ERROR_RECV; Conns[slot].error_state = CONN_ERROR_RECV;
984 985 Conns[slot].xerrno = xerrno; Conns[slot].xerrno = xerrno;
985 986 } }
File Conn.h changed (mode: 100644) (index 6a4f651..677f5d8)
3 3
4 4 #include <Conn_engine_core.h> #include <Conn_engine_core.h>
5 5
6 extern int Conn_init(unsigned int max);
7 extern ssize_t Conn_send(struct Conn *C, void *buf, size_t count);
8 extern ssize_t Conn_recv(struct Conn *C, void *buf, size_t count);
9 extern struct Conn *Conn_socket(int domain, int type, int port);
10 extern int Conn_poll(int timeout);
11 extern int Conn_enqueue(struct Conn *C, void *buf, size_t count);
12 /*
13 extern void Conn_debug(FILE *f, unsigned short debug);
14 */
15 extern struct Conn *Conn_connect(int domain, int type, char *addr, int port);
16 extern int Conn_band(struct Conn *C, unsigned int width, unsigned int factor);
17
6 extern int Conn_init(const unsigned int max);
7 extern int Conn_shutdown(void);
8 extern ssize_t Conn_send(struct Conn *C, void *buf, const size_t count);
9 extern ssize_t Conn_recv(struct Conn *C, void *buf, const size_t count);
10 extern struct Conn *Conn_socket(const int domain, const int type,
11 const int port);
12 extern int Conn_poll(const int timeout);
13 extern int Conn_enqueue(struct Conn *C, void *buf,
14 const size_t count);
15 extern struct Conn *Conn_connect(const int domain, const int type,
16 const char *addr, const int port);
17 extern int Conn_band(struct Conn *C, const unsigned int width,
18 const unsigned int factor);
18 19
19 20 #endif #endif
File Conn_engine_core.c changed (mode: 100644) (index 791e972..a3891b4)
... ... unsigned int Conn_qlen(const struct Conn *C)
565 565 /* /*
566 566 * Returns 1 if we can ignore this connection * Returns 1 if we can ignore this connection
567 567 */ */
568 int Conn_ignore(struct Conn *C)
568 int Conn_ignore(const struct Conn *C)
569 569 { {
570 570 if (C->error_state > 0) if (C->error_state > 0)
571 571 return 1; return 1;
File Conn_engine_core.h changed (mode: 100644) (index 93ae938..6923c78)
... ... extern void Conn_debug(FILE *f, const unsigned short debug);
235 235
236 236 extern void Conn_close(struct Conn *C); extern void Conn_close(struct Conn *C);
237 237
238 extern int Conn_ignore(struct Conn *C);
238 extern int Conn_ignore(const struct Conn *C);
239 239
240 240 extern void Conn_expire(struct Conn *C); extern void Conn_expire(struct Conn *C);
241 241
File Makefile.in changed (mode: 100644) (index be2b8cb..976d5d7)
... ... all: libConn.so.@VER@ libConn.a examples
9 9
10 10
11 11 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
12 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_core.c -o $@
12 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_core.c
13 13
14 14 Conn_engine_poll.o: Conn_engine_poll.c Conn_config.h Conn_engine_core.h Conn_engine_poll.o: Conn_engine_poll.c Conn_config.h Conn_engine_core.h
15 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_poll.c -o $@
15 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_poll.c
16 16
17 17 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 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c -o $@
18 $(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c
19
20 Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o
21 $(CC) $(CFLAGS) $(INCS) -c Conn.c
19 22
20 23 %.o: %.c %.o: %.c
21 24 gcc $(CFLAGS) $(INCS) $< -c gcc $(CFLAGS) $(INCS) $< -c
File examples/c.c changed (mode: 100644) (index 79d49f4..66da5c8)
20 20 #include <Conn.h> #include <Conn.h>
21 21
22 22 /* Global variables */ /* Global variables */
23 static unsigned short debug = 9;
23 static unsigned short debug = 20;
24 static unsigned int ipv4conns = 500, ipv6conns = 500;
24 25
25 26 static FILE *Logf = NULL; static FILE *Logf = NULL;
26 27 static char *log_file = "c.log"; static char *log_file = "c.log";
 
... ... static void c_connected(struct Conn *C)
52 53
53 54 static void c_close(struct Conn *C) static void c_close(struct Conn *C)
54 55 { {
55 Log(5, "%s(Slot %d will close)\n",
56 __FUNCTION__, C->slot);
56 Log(5, "%s: id=%llu will close...\n",
57 __FUNCTION__, Conn_getid(C));
57 58 free(C->private); free(C->private);
58 59 } }
59 60
 
... ... int main(void)
95 96 int ret; int ret;
96 97 struct timeval start, end; struct timeval start, end;
97 98 unsigned int elap; unsigned int elap;
98 unsigned int i, ipv4conns = 5000, ipv6conns = 5000;
99 unsigned int i;
99 100 struct Conn *C4, *C6; struct Conn *C4, *C6;
100 101
101 102 Logf = fopen(log_file, "a+"); Logf = fopen(log_file, "a+");
 
... ... int main(void)
107 108 if (debug > 0) if (debug > 0)
108 109 setlinebuf(Logf); setlinebuf(Logf);
109 110
111 Conn_debug(Logf, debug);
112
110 113 Log(0, "Starting...\n"); Log(0, "Starting...\n");
111 114 Log(0, "\tPort=%d\n", port); Log(0, "\tPort=%d\n", port);
112 115 Log(0, "\tLogFile=%s Debug=%d\n", log_file, debug); Log(0, "\tLogFile=%s Debug=%d\n", log_file, debug);
113 116
114 Conn_debug(Logf, debug);
115
116 117 ret = Conn_init(0); ret = Conn_init(0);
117 118 if (ret == -1) { if (ret == -1) {
118 119 Log(0, "%s", Conn_strerror()); Log(0, "%s", Conn_strerror());
 
... ... int main(void)
156 157 break; break;
157 158 } }
158 159
159 if (ret == 0) {
160 Log(0, "Finish work!\n");
161 break;
162 }
163
164 if (answers % 10 == 0)
165 printf(".");
160 printf("%u answer(s)\n", answers);
166 161
167 162 if (answers == ipv4conns + ipv6conns) if (answers == ipv4conns + ipv6conns)
168 163 break; break;
File examples/s.c changed (mode: 100644) (index 8b9cb42..780c1ea)
20 20 #include <Conn.h> #include <Conn.h>
21 21
22 22 /* Global variables */ /* Global variables */
23 static unsigned short debug = 9;
23 static unsigned short debug = 20;
24 24
25 25 static FILE *Logf = NULL; static FILE *Logf = NULL;
26 26 static char *log_file = "s.log"; static char *log_file = "s.log";
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