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)
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
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
Commit fce47295946106956fb70da77244d77ffca09423 - Added some more compile flags and websocket1 helper files.
Author: Catalin(ux) M. BOIE
Author date (UTC): 2018-01-13 18:03
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2018-01-13 18:06
Parent(s): 91b9113e8f92db07c079c005273683f2e868910c
Signing key:
Tree: 29cbae1044fcf9ca07e5bba313e92711793d7596
File Lines added Lines deleted
.gitignore 1 0
Conn.c 1 3
Makefile.in 2 1
duilder.conf 4 2
examples/websocket1.data/index.html 45 0
examples/websocket1.data/main.css 26 0
examples/websocket1.data/main.js 164 0
examples/websocket1.data/websocket1.nginx 23 0
examples/websocket1.data/websocket1.service 12 0
examples/websocket1.sh 17 0
File .gitignore changed (mode: 100644) (index 807f4b3..f46bab4)
... ... duilder_release
14 14 *.strace *.strace
15 15 *.pcap *.pcap
16 16 *.ltrace *.ltrace
17 History.size
File Conn.c changed (mode: 100644) (index b435807..7ad881b)
... ... char *Conn_status(const unsigned int flags)
1647 1647 free(buf); free(buf);
1648 1648 return strdup("snprintf error"); return strdup("snprintf error");
1649 1649 } }
1650 if (len + (unsigned int) tmp_len < max) {
1650 if (len + (unsigned int) tmp_len < max)
1651 1651 strcat(buf, tmp); strcat(buf, tmp);
1652 len += (unsigned int) tmp_len;
1653 }
1654 1652
1655 1653 return buf; return buf;
1656 1654 } }
File Makefile.in changed (mode: 100644) (index 3ebb2ef..0518f7d)
... ... export INCS += -I.
5 5 export LIBS += -lcrypto -lssl #-lpthread export LIBS += -lcrypto -lssl #-lpthread
6 6 export OBJS += Conn.o Conn_web.o export OBJS += Conn.o Conn_web.o
7 7
8 export CFLAGS := -Wall -Wextra -pipe -O3 -g $(CC_SWITCHES) $(CFLAGS)
8 export CFLAGS := -Wall -Wextra -pipe -g $(CC_SWITCHES) $(CFLAGS)
9 9
10 10
11 11 .PHONY: all .PHONY: all
 
... ... libConn.so.@VER@: $(OBJS)
26 26 -o $@ $(OBJS) -lc $(LIBS) -o $@ $(OBJS) -lc $(LIBS)
27 27 ln -sf $@ libConn.so.1 ln -sf $@ libConn.so.1
28 28 ln -sf libConn.so.1 libConn.so ln -sf libConn.so.1 libConn.so
29 (date; echo $(CFLAGS); size libConn.so.@VER@; echo) >> History.size
29 30
30 31 libConn.a: $(OBJS) libConn.a: $(OBJS)
31 32 ar rcs libConn.a $(OBJS) ar rcs libConn.a $(OBJS)
File duilder.conf changed (mode: 100644) (index 199f3a1..c26f37a)
... ... CONFIG_H="Conn_config.h"
17 17 RELEASE_SCRIPT="./duilder_release" RELEASE_SCRIPT="./duilder_release"
18 18 RELEASE_SCRIPT="/usr/local/bin/duilder_release" RELEASE_SCRIPT="/usr/local/bin/duilder_release"
19 19
20 CC_SWITCHES="-fstack-reuse=all -flto -Wtrampolines -Wl,-z,noexecstack"
20 CC_SWITCHES="-O3 -fstack-reuse=all -flto -Wtrampolines -Wl,-z,noexecstack"
21 21 CC_SWITCHES="${CC_SWITCHES} -Wl,-z,now -Wl,-z,relro -Wl,-O1 -Wl,-z,noexecstack" CC_SWITCHES="${CC_SWITCHES} -Wl,-z,now -Wl,-z,relro -Wl,-O1 -Wl,-z,noexecstack"
22 22 CC_SWITCHES="${CC_SWITCHES} -fPIE -pie -fstack-protector-all" CC_SWITCHES="${CC_SWITCHES} -fPIE -pie -fstack-protector-all"
23 23 CC_SWITCHES="${CC_SWITCHES} -Wcast-align -Wformat=2" CC_SWITCHES="${CC_SWITCHES} -Wcast-align -Wformat=2"
 
... ... CC_SWITCHES="${CC_SWITCHES} -Wmissing-prototypes -Wmissing-declarations"
26 26 CC_SWITCHES="${CC_SWITCHES} -Wstrict-overflow -Wstrict-prototypes" CC_SWITCHES="${CC_SWITCHES} -Wstrict-overflow -Wstrict-prototypes"
27 27 CC_SWITCHES="${CC_SWITCHES} -D _FORTIFY_SOURCES=2" CC_SWITCHES="${CC_SWITCHES} -D _FORTIFY_SOURCES=2"
28 28 CC_SWITCHES="${CC_SWITCHES} -fno-guess-branch-probability -fbounds-check" CC_SWITCHES="${CC_SWITCHES} -fno-guess-branch-probability -fbounds-check"
29 CC_SWITCHES="${CC_SWITCHES} -Wl,-O2 -Wpadded"
29 CC_SWITCHES="${CC_SWITCHES} -Wl,-O3 -Wpadded"
30 CC_SWITCHES="${CC_SWITCHES} -ftree-loop-distribution -ftree-vectorize -ftree-loop-if-convert"
31 CC_SWITCHES="${CC_SWITCHES} -ftree-loop-im -ftree-parallelize-loops=4"
30 32
31 33 # TODO # TODO
32 34 #CC_SWITCHES="${CC_SWITCHES} -Wconversion" #CC_SWITCHES="${CC_SWITCHES} -Wconversion"
File examples/websocket1.data/index.html added (mode: 100644) (index 0000000..0468a14)
1 <!DOCTYPE html>
2 <html>
3
4 <head>
5 <title>Websocket demo</title>
6 <meta charset="utf-8" />
7 <meta name="viewport" content="width=device-width, initial-scale=1" />
8 <script type="text/javascript" src="main.js"></script>
9 <link rel="stylesheet" href="main.css">
10 </head>
11
12 <body onLoad="my_start()">
13
14 <!--
15 // This file is part of Conn project
16 // https://rocketgit.com/user/catalinux/Conn
17 // License: LGPLv3+
18 // Copyright: Catalin(ux) M. BOIE
19 -->
20
21 <div>Welcome to <a href="https://rocketgit.com/user/catalinux/Conn" target="_new">Conn</a> chat!</div>
22
23 <div class="block">
24 Name: <input type="text" id="name" value="Anonymous" />
25 <button onClick="set_name();">Set name</button>
26 </div>
27
28 <div class="block">
29 Status: <span id="my_status">Status</span>
30 </div>
31
32 <div class="block">
33 <div id="chat">
34 Chat will show here!<br />
35 </div>
36 </div>
37
38 <div class="block">
39 <textarea id="msg" rows="3" placeholder="Type your message (press Enter or the Send button to send the message, Shift+Enter for new line)"></textarea>
40 <button id="button_send" onClick="send_msg();">Send</button>
41 </div>
42
43 </body>
44
45 </html>
File examples/websocket1.data/main.css added (mode: 100644) (index 0000000..53d5471)
1 .block {
2 border: 1px solid black;
3 margin: 5px 0;
4 padding: 3px;
5 }
6
7 textarea {
8 box-sizing: border-box;
9 width: 100%;
10 }
11
12 #name {
13 }
14
15 #my_status {
16 }
17
18 #chat {
19 height: 300px;
20 xxoverflow: auto;
21 }
22
23 #msg {
24 white-space: pre;
25 }
26
File examples/websocket1.data/main.js added (mode: 100644) (index 0000000..c5b8629)
1 // This file is part of Conn project
2 // https://rocketgit.com/user/catalinux/Conn
3 // License: LGPLv3+
4 // Copyright: Catalin(ux) M. BOIE
5
6 // TODO: escape html to avoid injecting scrpts in chat
7 // TODO: Will the keepalive do its job? Or should I check if I got an answer for
8 // the keepalive message and re-connect if not received?
9
10 var my_ws_url = 'ws://' + window.location.host + '/ws';
11 var version = '1'; // version of the javascript code
12 var timer, ka;
13 var ws;
14 var div_status, div_chat, div_msg, div_name;
15 var reconnect_time_ms = 3000;
16 var keep_alive_time_ms = 10000;
17 var notify_perm;
18 var last_msg = '';
19
20 function set_name()
21 {
22 var data = {
23 op: 'set_name',
24 name: div_name.value
25 };
26 //console.log('set_name...');
27 ws.send(JSON.stringify(data));
28 }
29
30 function send_msg()
31 {
32 var data = {
33 op: 'msg',
34 text: div_msg.value
35 };
36
37 //console.log('send_msg...');
38 ws.send(JSON.stringify(data));
39 last_msg = div_msg.value;
40 div_msg.value = '';
41 }
42
43 function keep_alive()
44 {
45 var data = { op: 'ka' };
46
47 //console.log('keep_alive...');
48 ws.send(JSON.stringify(data));
49 }
50
51 function reconnect()
52 {
53 div_status.innerHTML = 'Connecting...';
54
55 // We do not want the re-connect timer to trigger now, when
56 // the connection is in progress.
57 if (timer != undefined) // TODO: check if this is correct
58 clearInterval(timer);
59
60 if (ka != undefined) // TODO: check if this is correct
61 clearInterval(ka);
62
63 console.log('connecting...');
64 ws = new WebSocket(my_ws_url);
65
66 ws.onopen = function(ev)
67 {
68 var data = {
69 op: 'init',
70 version: version
71 };
72
73 console.log('onopen: sending init...');
74 ws.send(JSON.stringify(data));
75
76 // Arm keep-alive timer
77 clearInterval(ka);
78 ka = setInterval(keep_alive, keep_alive_time_ms);
79
80 div_status.innerHTML = 'Connected';
81 }
82
83 ws.onerror = function(ev)
84 {
85 console.log('onerror: ' + ev.reason);
86 div_status.innerHTML = 'Error: ' + ev.reason + '!';
87 }
88
89 ws.onmessage = function(ev)
90 {
91 var j;
92
93 //console.log('onmessage: data: ' + ev.data);
94 j = JSON.parse(ev.data);
95
96 if (j.op == 'ka') {
97 //console.log('got a ka answer from server');
98 } else if (j.op == 'init') {
99 //console.log('got answer to init command');
100 div_status.innerHTML = 'OK (id ' + j.id + ')';
101 } else if (j.op == 'msg') {
102 div_chat.innerHTML += j.from + ': ' + j.msg + '<br />\n';
103 div_chat.scrollTop = div_chat.scrollHeight;
104
105 // TODO: This only works on Firefox (mobile and desktop)
106 // TODO: It does not work on Chrome 63 mobile
107 if (notify_perm == 'granted') {
108 var not = new Notification(
109 'New message from ' + j.from,
110 { body: j.msg });
111 }
112 } else {
113 console.log('invalid op [' + j.op + '] [' + ev.data + ']');
114 }
115
116 // re-arm the keep-alive timer
117 clearInterval(ka);
118 ka = setInterval(keep_alive, keep_alive_time_ms);
119 }
120
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 //console.log('ws.readyState=' + ws.readyState);
131 }
132
133 function msg_key_event(e)
134 {
135 //console.log('msg_key_event: e.keycode=' + e.keyCode);
136
137 if (e.shiftKey) {
138 // We want Shift+ENTER to be just a CR
139 } else {
140 switch (e.keyCode) {
141 case 13: send_msg(); e.preventDefault(); return false; // enter - send message
142 case 27: div_msg.value = ''; e.preventDefault(); return false; // escape cleans line
143 case 38: div_msg.value = last_msg; e.preventDefault(); return false; // edit line
144 }
145 }
146 }
147
148 function my_start()
149 {
150 div_name = document.getElementById('name');
151 div_status = document.getElementById('my_status');
152 div_chat = document.getElementById('chat');
153 div_msg = document.getElementById('msg');
154
155 // Ask permission for notifications (if not already granted)
156 Notification.requestPermission().then(function(r) { notify_perm = r; });
157
158 // Add a listener for msg div
159 div_msg.addEventListener('keydown', msg_key_event, false);
160
161 reconnect();
162 }
163
164 //ws.close();
File examples/websocket1.data/websocket1.nginx added (mode: 100644) (index 0000000..a74e231)
1 upstream websocket1 {
2 server 127.0.0.1:9021;
3 }
4
5 server {
6 listen 9050;
7 listen [::]:9050;
8
9 root /usr/share/websocket1/root;
10
11 access_log /var/log/nginx/websocket1b-access.log;
12 error_log /var/log/nginx/websocket1b-error.log;
13
14 location /ws {
15 proxy_pass http://websocket1;
16 proxy_http_version 1.1;
17 proxy_set_header X-Original-IP $remote_addr/$remote_port;
18 proxy_set_header Upgrade $http_upgrade;
19 proxy_set_header Connection "upgrade";
20 proxy_read_timeout 120;
21 proxy_buffering off;
22 }
23 }
File examples/websocket1.data/websocket1.service added (mode: 100644) (index 0000000..8c18579)
1 [Unit]
2 Description=websocket1 service example
3 After=network.target
4
5 [Service]
6 ExecStart=/usr/bin/websocket1
7 KillSignal=9
8 Restart=on-failure
9 RestartSec=5s
10
11 [Install]
12 WantedBy=multi-user.target
File examples/websocket1.sh added (mode: 100755) (index 0000000..ad8c726)
1 #!/bin/bash
2
3 set -e
4
5 cp -fv websocket1.data/websocket1.service /etc/systemd/system/
6 systemctl daemon-reload
7
8 make websocket1
9 rm -f /usr/bin/websocket1
10 cp -v websocket1 /usr/bin/
11 systemctl restart websocket1
12
13 mkdir -p /usr/share/websocket1/root
14 cp -av websocket1.data/* /usr/share/websocket1/root/
15
16 cp websocket1.data websocket1.nginx /etc/nginx/conf.d/websocket1.conf
17 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