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)
Various small stuff 0c551268be734dd68a59426315abfc6ef776c60a Catalin(ux) M. BOIE 2018-04-02 21:40:49
More debugging for websocket parsing 66ccde632b280f1aa450610e6b671464b7e56451 Catalin(ux) M. BOIE 2018-04-02 21:39:23
Raise to 4096 to buffer for logging a59dee1fdfe087ff13e4c7012fe29f8da99ad75c Catalin(ux) M. BOIE 2018-04-02 21:38:11
Bump version 9b635cebfffdd6971eefef0ebad395e21684bb8a Catalin(ux) M. BOIE 2018-01-13 18:07:12
Added some more compile flags and websocket1 helper files. fce47295946106956fb70da77244d77ffca09423 Catalin(ux) M. BOIE 2018-01-13 18:03:46
Lots of changes everywhere 91b9113e8f92db07c079c005273683f2e868910c Catalin(ux) M. BOIE 2018-01-12 19:06:04
Require openssl (for websocket) b4b34eb88f38bfd421187da76611cc54476d7309 Catalin(ux) M. BOIE 2017-12-30 23:44:50
Very important fixes 01e33f06a5cdc52fb3795158fd838fcca7055dda Catalin(ux) M. BOIE 2017-12-30 23:39:17
Bump version to 1.0.37 54e8f3bcaf7f7e096c454563039a545a4abb1bf0 Catalin(ux) M. BOIE 2017-12-30 22:13:12
Lots of small fixes 4894de0472e571b8c78294de527bf70089096545 Catalin(ux) M. BOIE 2017-12-30 22:11:09
Checkpoint b6bf45330f046da40d762b6fd10d1bb97bc40036 Catalin(ux) M. BOIE 2017-12-28 00:13:09
Fixed libConn*.so instalation. df1bef9190d30dd11fcd150b41810ce18278b74f Catalin(ux) M. BOIE 2015-04-25 14:43:37
libConn1.so was not included in spec file. dd99625a7fb70d66fa5a91371fb4d2eaf7a4f23d Catalin(ux) M. BOIE 2015-04-25 14:39:32
Small fixes for build system. ab12cbbe149933cbf1b9a9900be1a45d63ee0b29 Catalin(ux) M. BOIE 2015-04-25 14:17:14
Build fixes e7521468199d4da53461fb0c1ffa08e1913c1e9f Catalin(ux) M. BOIE 2015-04-24 19:18:42
Checkpoint before switching to processes not threads de43b387557dde215ab1210838d396e7e7b22c4f Catalin(ux) M. BOIE 2015-01-14 04:13:00
Wpools work now\! f875d6bea1777c3a290bf9bb1aa047f26c935a63 Catalin(ux) M. BOIE 2013-11-13 20:51:13
WIP 1d246f2130d4acf8c267e82051b250a623da6870 Catalin(ux) M. BOIE 2013-10-16 19:57:04
WIP 6387026db3ce7983e610887565a282f4124d4092 Catalin(ux) M. BOIE 2013-10-14 20:06:49
WIP 15f063f9d34d3f7b7ae9d9e83f59b4077515122b Catalin(ux) M. BOIE 2010-09-30 22:01:30
Commit 0c551268be734dd68a59426315abfc6ef776c60a - Various small stuff
Author: Catalin(ux) M. BOIE
Author date (UTC): 2018-04-02 21:40
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2018-04-02 21:40
Parent(s): 66ccde632b280f1aa450610e6b671464b7e56451
Signing key:
Tree: 244e46d22b988aac201e51a9928a189cad778849
File Lines added Lines deleted
Conn.c 16 8
Makefile.in 1 1
examples/Makefile 1 1
examples/websocket1.c 2 0
examples/websocket1.data/main.js 13 11
examples/websocket1.sh 1 1
File Conn.c changed (mode: 100644) (index 32e40dd..2309f5e)
... ... static int Conn_ignore(struct Conn *C)
1709 1709 return 0; return 0;
1710 1710 } }
1711 1711
1712 #if 0
1713 1712 /* /*
1714 1713 * Close a connection if it exceeded maximum idle time or got a timeout * Close a connection if it exceeded maximum idle time or got a timeout
1715 1714 */ */
 
... ... static void Conn_expire(struct Conn *C)
1746 1745 } }
1747 1746 } }
1748 1747 } }
1749 #endif
1750 1748
1751 1749 /* /*
1752 1750 * Set NODELAY on socket * Set NODELAY on socket
 
... ... __hot static struct Conn *Conn_alloc_prepare(struct Conn *C)
2115 2113 C->web = NULL; C->web = NULL;
2116 2114 C->web_req = NULL; C->web_req = NULL;
2117 2115
2116 C->wp = NULL;
2117
2118 2118 Conn_no++; Conn_no++;
2119 2119 /* Conn_work_to_do will not be incremented here, only in commit! */ /* Conn_work_to_do will not be incremented here, only in commit! */
2120 2120
 
... ... static inline int Conn_dispatch_events(struct Conn_wpool_worker *w,
2460 2460 if (unlikely(e[i].data.fd == 1)) { if (unlikely(e[i].data.fd == 1)) {
2461 2461 /* TODO: we may have another message type! */ /* TODO: we may have another message type! */
2462 2462 Log(0, "We have a master signaling. TODO!\n"); Log(0, "We have a master signaling. TODO!\n");
2463 exit(0);
2463 2464 continue; continue;
2464 2465 } }
2465 2466
 
... ... struct Conn *Conn_connect(const int domain, const int type, const char *addr,
3489 3490 return X; return X;
3490 3491 } }
3491 3492
3492 #if 0
3493 3493 /* /*
3494 3494 * Add tokens to connection * Add tokens to connection
3495 3495 */ */
 
... ... int Conn_band(struct Conn *C, const unsigned int width,
3546 3546
3547 3547 return 0; return 0;
3548 3548 } }
3549 #endif
3550 3549
3551 3550 #if 0 #if 0
3552 3551 TODO TODO
 
... ... int Conn_poll(const int timeout)
3683 3682 { {
3684 3683 int ret; int ret;
3685 3684 int timeout2; int timeout2;
3685 unsigned int slot, last;
3686 struct Conn *C;
3686 3687
3687 3688 Log(9, "%s timeout=%d Conn_no=%d Conn_work_to_do=%u\n", Log(9, "%s timeout=%d Conn_no=%d Conn_work_to_do=%u\n",
3688 3689 __func__, timeout, Conn_no, Conn_work_to_do); __func__, timeout, Conn_no, Conn_work_to_do);
 
... ... int Conn_poll(const int timeout)
3715 3716 if (unlikely(ret < 0)) if (unlikely(ret < 0))
3716 3717 return -1; return -1;
3717 3718
3718 #if 0
3719 #if 1
3719 3720 Log(9, "Do compacting, expiration and band stuff...\n"); Log(9, "Do compacting, expiration and band stuff...\n");
3720 TODO
3721 3721 slot = 0; slot = 0;
3722 3722 while (slot < Conn_no) { while (slot < Conn_no) {
3723 3723 /* /*
 
... ... int Conn_poll(const int timeout)
3726 3726 */ */
3727 3727 last = Conn_no - 1; last = Conn_no - 1;
3728 3728
3729 C = &Conns[slot];
3730 if (!C) {
3731 slot++;
3732 continue;
3733 }
3734
3735 #if 0
3729 3736 /* Closing connection if it is in error state. */ /* Closing connection if it is in error state. */
3730 3737 if (C->error_state > 0) { if (C->error_state > 0) {
3731 3738 Log(11, "\tSlot=%u in error [%s], move and free it.\n", Log(11, "\tSlot=%u in error [%s], move and free it.\n",
 
... ... int Conn_poll(const int timeout)
3734 3741 Conn_free_intern(last); Conn_free_intern(last);
3735 3742 continue; continue;
3736 3743 } }
3744 #endif
3737 3745
3738 3746 /* No commit done yet */ /* No commit done yet */
3739 3747 if (C->state == CONN_STATE_EMPTY) { if (C->state == CONN_STATE_EMPTY) {
 
... ... int Conn_poll(const int timeout)
3749 3757 } }
3750 3758
3751 3759 /* test if it expired/timeout */ /* test if it expired/timeout */
3752 Conn_expire(slot);
3760 Conn_expire(C);
3753 3761
3754 3762 /* add tokens */ /* add tokens */
3755 Conn_band_update(slot);
3763 Conn_band_update(C);
3756 3764
3757 3765 slot++; slot++;
3758 3766 } }
File Makefile.in changed (mode: 100644) (index 0518f7d..19522a9)
... ... clean:
52 52
53 53 install: all install: all
54 54 @mkdir -p $(I_USR_LIB) @mkdir -p $(I_USR_LIB)
55 @cp -vd libConn.so* $(I_USR_LIB)
55 @cp -vd libConn.so libConn.so.1 libConn.so.$(VER) $(I_USR_LIB)
56 56 @mkdir -p $(I_USR_INC) @mkdir -p $(I_USR_INC)
57 57 @cp -vd Conn.h Conn_config.h $(I_USR_INC) @cp -vd Conn.h Conn_config.h $(I_USR_INC)
File examples/Makefile changed (mode: 100644) (index 165bab4..4863db2)
... ... INCS += -I..
12 12 LIBS += -L.. -lConn LIBS += -L.. -lConn
13 13 OBJS := OBJS :=
14 14 DEPS := ../Conn.h $(OBJS) DEPS := ../Conn.h $(OBJS)
15 CFLAGS := $(CC_SWITCHES) $(CFLAGS)
15 CFLAGS := -Wall -Wextra -pipe -g $(CC_SWITCHES) $(CFLAGS)
16 16
17 17 s: s.c $(DEPS) s: s.c $(DEPS)
18 18 gcc $(CFLAGS) $(INCS) s.c -o s $(LIBS) gcc $(CFLAGS) $(INCS) s.c -o s $(LIBS)
File examples/websocket1.c changed (mode: 100644) (index 38bdb13..8a1f5b5)
... ... static void ws1(struct Conn *C)
234 234 } }
235 235
236 236 Log(5, "\tWe already have an established ws connection\n"); Log(5, "\tWe already have an established ws connection\n");
237 again:
237 238 r = Conn_web_ws_parse(&w, C); r = Conn_web_ws_parse(&w, C);
238 239 if (r == -1) { if (r == -1) {
239 240 Log(0, "\tProtocol error: %s!\n", Conn_strerror()); Log(0, "\tProtocol error: %s!\n", Conn_strerror());
 
... ... static void ws1(struct Conn *C)
262 263 json_object_put(json); json_object_put(json);
263 264
264 265 Conn_eat(C, w.len); Conn_eat(C, w.len);
266 goto again;
265 267 } }
266 268
267 269 int main(void) int main(void)
File examples/websocket1.data/main.js changed (mode: 100644) (index c5b8629..5c6ea44)
3 3 // License: LGPLv3+ // License: LGPLv3+
4 4 // Copyright: Catalin(ux) M. BOIE // Copyright: Catalin(ux) M. BOIE
5 5
6 // TODO: escape html to avoid injecting scrpts in chat
6 // TODO: escape html to avoid injecting scripts in chat
7 7 // TODO: Will the keepalive do its job? Or should I check if I got an answer for // TODO: Will the keepalive do its job? Or should I check if I got an answer for
8 8 // the keepalive message and re-connect if not received? // the keepalive message and re-connect if not received?
9 9
 
... ... function reconnect()
74 74 ws.send(JSON.stringify(data)); ws.send(JSON.stringify(data));
75 75
76 76 // Arm keep-alive timer // Arm keep-alive timer
77 clearInterval(ka);
78 77 ka = setInterval(keep_alive, keep_alive_time_ms); ka = setInterval(keep_alive, keep_alive_time_ms);
79 78
80 79 div_status.innerHTML = 'Connected'; div_status.innerHTML = 'Connected';
 
... ... function reconnect()
86 85 div_status.innerHTML = 'Error: ' + ev.reason + '!'; div_status.innerHTML = 'Error: ' + ev.reason + '!';
87 86 } }
88 87
88 // This is called also when an error occurs
89 ws.onclose = function(ev)
90 {
91 clearInterval(ka);
92
93 console.log('onclose: [' + ev.reason + '] ' + ev.code);
94 timer = setInterval(reconnect, reconnect_time_ms);
95
96 div_status.innerHTML = 'Connection closed: ['
97 + ev.reason + '] ' + ev.code + '!';
98 }
99
89 100 ws.onmessage = function(ev) ws.onmessage = function(ev)
90 101 { {
91 102 var j; var j;
 
... ... function reconnect()
118 129 ka = setInterval(keep_alive, keep_alive_time_ms); ka = setInterval(keep_alive, keep_alive_time_ms);
119 130 } }
120 131
121 ws.onclose = function(ev)
122 {
123 console.log('onclose: [' + ev.reason + '] ' + ev.code);
124 timer = setInterval(reconnect, reconnect_time_ms);
125
126 div_status.innerHTML = 'Connection closed: ['
127 + ev.reason + '] ' + ev.code + '!';
128 }
129
130 132 //console.log('ws.readyState=' + ws.readyState); //console.log('ws.readyState=' + ws.readyState);
131 133 } }
132 134
File examples/websocket1.sh changed (mode: 100755) (index ad8c726..b7a134a)
... ... systemctl restart websocket1
13 13 mkdir -p /usr/share/websocket1/root mkdir -p /usr/share/websocket1/root
14 14 cp -av websocket1.data/* /usr/share/websocket1/root/ cp -av websocket1.data/* /usr/share/websocket1/root/
15 15
16 cp websocket1.data websocket1.nginx /etc/nginx/conf.d/websocket1.conf
16 cp websocket1.data/websocket1.nginx /etc/nginx/conf.d/websocket1.conf
17 17 service nginx restart service nginx restart
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