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)
Improved ntime example. b63de9b82ffab1c0d759571a40f1d72f9b8df927 Catalin(ux) M. BOIE 2009-08-24 17:09:21
Removed unused includes. 8af81a4c311caa7d738000a5208d01d7620d1040 Catalin(ux) M. BOIE 2009-08-21 18:57:33
Improved blackhole example. 2fd7ff181a412f4ba060b0e89b97acdf89a8fb88 Catalin(ux) M. BOIE 2009-08-21 18:03:22
Fixed connections to outside. Still, it is a little mess there. 417ccd4a48508a810377676658d51c5103168472 Catalin(ux) M. BOIE 2009-08-21 17:42:37
addr and bind_addr are not pointers! Corrected them. e1deeb765500ee079802c2cd6543f9c9496d8f9b Catalin(ux) M. BOIE 2009-08-21 16:49:24
Exported _alloc and _commit functions. 9a3159e89eff020cfb75b9eec49a45a637a6da57 Catalin(ux) M. BOIE 2009-08-21 16:39:27
Added blackhole example. 8a7ac49b018ad65ba386f8a50725745127b4cbd2 Catalin(ux) M. BOIE 2009-08-21 15:54:55
TODO in/out. fdcfbf9e18ed5fbe0135b9aa702e09432fa71e93 Catalin(ux) M. BOIE 2009-08-21 15:53:05
First chunk of generic socket handling. b9a488ba615c4322b5d116a29919f11fd476b200 Catalin(ux) M. BOIE 2009-08-21 15:50:45
Added ntime example (returns CLOCK_REALTIME as fast as it can). e2fa318caf3e9aea09a853ab2b4af4b5a2cc8261 Catalin(ux) M. BOIE 2009-08-20 15:41:20
TODO ins and outs. 66a987be5d8e08ef6fe1ce0c056b8c3acd65bdb7 Catalin(ux) M. BOIE 2009-08-20 15:36:14
Cosmetic change. 5dab6539af2ca97f3f3f9b55e20be7d6f423829e Catalin(ux) M. BOIE 2009-08-20 15:34:01
Abort if current slot is in state FREE. It must not happen. 14dc9f444309cddd46996a47277cefe4eec77db5 Catalin(ux) M. BOIE 2009-08-20 15:33:31
Clean a slot only after we move it in the end. This fixes an infinite loop if last and first slots were both in state FREE. eecc6decaea6801235aa7a02d193782e1accc58f Catalin(ux) M. BOIE 2009-08-20 15:32:38
Cosmetic changes. c147533732f8b7b4bbe2725f04bcce0df0271c70 Catalin(ux) M. BOIE 2009-08-20 15:31:12
Call del_obj only if we have a valid file descriptor. 95c90269de0fa59a6ea69c2067827bbf57db16d5 Catalin(ux) M. BOIE 2009-08-20 15:29:42
Conn_enqueue returns now the number of bytes queued or -1. You should really check the error code. ab88f823936ad67ba08aa5fd7984ea735c6c7dd7 Catalin(ux) M. BOIE 2009-08-20 15:28:42
Added CONN_STATE_ERROR. e20e518e10f686eb0b248ae23fe193ea7344594b Catalin(ux) M. BOIE 2009-08-20 15:27:50
Added ERROR_INTERNAL. 380a956dacfc05f0668e6a3fac941a464b5d7deb Catalin(ux) M. BOIE 2009-08-20 15:27:08
Added helper raise_error. 10abeda5c6e4d1fb2c7011b9d2d070ea4db1cc11 Catalin(ux) M. BOIE 2009-08-20 15:26:32
Commit b63de9b82ffab1c0d759571a40f1d72f9b8df927 - Improved ntime example.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-08-24 17:09
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-09-02 15:42
Parent(s): 8af81a4c311caa7d738000a5208d01d7620d1040
Signing key:
Tree: 5f7b572fa3515cb1009e71f90c64c6529ce86156
File Lines added Lines deleted
examples/ntime.c 49 39
File examples/ntime.c changed (mode: 100644) (index 904765f..f00f0e9)
5 5
6 6 #define _GNU_SOURCE #define _GNU_SOURCE
7 7
8 #include <errno.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sys/poll.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <stdio.h>
17 #include <fcntl.h>
18 #include <netinet/in.h>
19 #include <sys/time.h>
20 #include <sys/ioctl.h>
21 #include <time.h>
22 #include <arpa/inet.h>
23 #include <stdarg.h>
24
25 8 #include <Conn.h> #include <Conn.h>
26 9
27 10 /* Global variables */ /* Global variables */
28 static unsigned short debug = 20;
11 static unsigned short debug = 20;
12
13 static FILE *Logf = NULL;
14 static char *log_file = "ntime.log";
15 static int port = 9000;
16 static short ipv4 = 1, ipv6 = 1;
17 static unsigned long long errors;
29 18
30 static FILE *Logf = NULL;
31 static char *log_file = "ntime.log";
32 static int port = 9000;
33 static short ipv4 = 1, ipv6 = 1;
34 19
35 20 static void s_accept_error(struct Conn *C) static void s_accept_error(struct Conn *C)
36 21 { {
37 Log(0, "%s: Cannot accept a new connection!\n");
22 Log(0, "%s: Cannot accept a new connection on id %llu!\n",
23 Conn_getid(C));
24 errors++;
38 25 } }
39 26
40 27 static void s_accept(struct Conn *C) static void s_accept(struct Conn *C)
 
... ... static void s_accept(struct Conn *C)
50 37
51 38 int main(void) int main(void)
52 39 { {
53 struct Conn *I4 = NULL, *I6 = NULL;
40 struct Conn *C;
54 41 int ret; int ret;
55 42
56 43 Logf = fopen(log_file, "w"); Logf = fopen(log_file, "w");
 
... ... int main(void)
78 65 } }
79 66
80 67 if (ipv4 == 1) { if (ipv4 == 1) {
81 Log(9, "Try to register IPv4 socket...\n");
82 I4 = Conn_socket(PF_INET, SOCK_STREAM, port);
83 if (!I4)
84 Log(1, "Cannot bind on ipv4 socket [%s].\n", Conn_strerror());
68 printf("Trying to register IPv4 socket...\n");
69 C = Conn_alloc();
70 if (!C) {
71 printf("Cannot alloc socket [%s].\n",
72 Conn_strerror());
73 errors++;
74 } else {
75 Conn_set_socket_domain(C, PF_INET);
76 Conn_set_socket_type(C, SOCK_STREAM);
77 Conn_set_socket_bind_port(C, port);
78 ret = Conn_commit(C);
79 if (ret != 0) {
80 printf("Cannot bind on ipv4 socket [%s].\n",
81 Conn_strerror());
82 errors++;
83 }
84 }
85 85 } }
86 86
87 87 if (ipv6 == 1) { if (ipv6 == 1) {
88 Log(9, "Try to register IPv6 socket...\n");
89 I6 = Conn_socket(PF_INET6, SOCK_STREAM, port);
90 if (!I6)
91 Log(1, "Cannot bind on ipv6 socket [%s].\n", Conn_strerror());
92 }
93
94 if ((I6 == NULL) && (I4 == NULL)) {
95 Log(0, "Cannot bind!\n");
96 return 1;
88 printf("Trying to register IPv6 socket...\n");
89 C = Conn_alloc();
90 if (!C) {
91 printf("Cannot alloc socket [%s].\n",
92 Conn_strerror());
93 errors++;
94 } else {
95 Conn_set_socket_domain(C, PF_INET6);
96 Conn_set_socket_type(C, SOCK_STREAM);
97 Conn_set_socket_bind_port(C, port);
98 ret = Conn_commit(C);
99 if (ret != 0) {
100 printf("Cannot bind on ipv6 socket [%s].\n",
101 Conn_strerror());
102 errors++;
103 }
104 }
97 105 } }
98 106
99 107 Conn_accept_cb = s_accept; Conn_accept_cb = s_accept;
 
... ... int main(void)
104 112 if (ret == -1) { if (ret == -1) {
105 113 Log(0, "Error calling Conn_poll [%s]!\n", Conn_strerror()); Log(0, "Error calling Conn_poll [%s]!\n", Conn_strerror());
106 114 return 1; return 1;
107 }
115 } else if (ret == 0)
116 break;
108 117 } }
109 118
110 Log(0, "Finish!\n\n");
119 Log(0, "Finish. Errors=%llu!\n\n",
120 errors);
111 121
112 122 return 0; return 0;
113 123 } }
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