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 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
Correctly set error state and errno code. 6eca4a62d11c1881c8803d927e8155f15ca39072 Catalin(ux) M. BOIE 2009-08-20 15:25:11
Converted #defines to enums. 6bafbb8f6887be62ccc668411b3e336d732c82dc Catalin(ux) M. BOIE 2009-08-20 15:20:38
Commit 2fd7ff181a412f4ba060b0e89b97acdf89a8fb88 - Improved blackhole example.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-08-21 18:03
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-09-02 15:42
Parent(s): 417ccd4a48508a810377676658d51c5103168472
Signer:
Signing key:
Signing status: N
Tree: b2399bad85005271b01eeafa5ac61b076b05e463
File Lines added Lines deleted
examples/blackhole_c.c 37 23
examples/blackhole_s.c 37 27
File examples/blackhole_c.c changed (mode: 100644) (index 50b23f1..a391810)
25 25
26 26 /* Global variables */ /* Global variables */
27 27 static unsigned short debug = 4; static unsigned short debug = 4;
28 static unsigned int ipv4conns = 0, ipv6conns = 5000;
28 static unsigned int ipv4conns = 1000, ipv6conns = 1000;
29 29
30 30 static int port = 9000; static int port = 9000;
31 31 static unsigned int ends = 0; static unsigned int ends = 0;
 
... ... static void c_connected(struct Conn *C)
40 40 int amount; int amount;
41 41
42 42 amount = Conn_enqueue(C, buf, buf_size); amount = Conn_enqueue(C, buf, buf_size);
43 /* old Conn_enqueue returned 0 */
44 if ((amount != 0) && (amount != buf_size))
43 if (amount != buf_size) {
45 44 printf("Cannot enqueue whole buffer (%d/%d)!\n", printf("Cannot enqueue whole buffer (%d/%d)!\n",
46 45 amount, buf_size); amount, buf_size);
47 bytes += amount;
46 errors++;
47 } else {
48 bytes += amount;
49 }
48 50 Conn_close(C); Conn_close(C);
49 51 } }
50 52
51 static void c_close(struct Conn *C)
52 {
53 }
54
55 static void c_data(struct Conn *C)
56 {
57 }
58
59 53 static void c_error(struct Conn *C) static void c_error(struct Conn *C)
60 54 { {
61 55 printf("%s id=%llu [%s]\n", printf("%s id=%llu [%s]\n",
 
... ... int main(void)
69 63 struct timeval start, end; struct timeval start, end;
70 64 unsigned int elap; unsigned int elap;
71 65 unsigned int i; unsigned int i;
72 struct Conn *C4, *C6;
66 struct Conn *C;
73 67
74 68 buf_size = 4096; buf_size = 4096;
75 69 buf = malloc(buf_size); buf = malloc(buf_size);
 
... ... int main(void)
96 90 } }
97 91
98 92 Conn_connected_cb = c_connected; Conn_connected_cb = c_connected;
99 Conn_data_cb = c_data;
100 Conn_close_cb = c_close;
101 93 Conn_error_cb = c_error; Conn_error_cb = c_error;
102 94
103 95 gettimeofday(&start, NULL); gettimeofday(&start, NULL);
 
... ... int main(void)
106 98
107 99 /* ipv4 */ /* ipv4 */
108 100 for (i = 0; i < ipv4conns; i++) { for (i = 0; i < ipv4conns; i++) {
109 C4 = Conn_connect(PF_INET, SOCK_STREAM, "127.0.0.1", port);
110 if (C4 == NULL) {
111 printf("Error calling Conn_connect [%s]!\n",
101 C = Conn_alloc();
102 if (!C) {
103 printf("Error alloc Conn struct [%s]!\n",
112 104 Conn_strerror()); Conn_strerror());
113 return 1;
105 errors++;
106 } else {
107 Conn_set_socket_domain(C, PF_INET);
108 Conn_set_socket_type(C, SOCK_STREAM);
109 Conn_set_socket_addr(C, "127.0.0.1");
110 Conn_set_socket_port(C, port);
111 ret = Conn_commit(C);
112 if (ret != 0) {
113 printf("Error commiting [%s]!\n",
114 Conn_strerror());
115 errors++;
116 }
114 117 } }
115 118 } }
116 119
117 120 /* ipv6 */ /* ipv6 */
118 121 for (i = 0; i < ipv6conns; i++) { for (i = 0; i < ipv6conns; i++) {
119 C6 = Conn_connect(PF_INET6, SOCK_STREAM, "::1", port);
120 if (C6 == NULL) {
121 printf("Error calling Conn_connect6 [%s]!\n",
122 C = Conn_alloc();
123 if (!C) {
124 printf("Error alloc Conn struct [%s]!\n",
122 125 Conn_strerror()); Conn_strerror());
123 return 1;
126 errors++;
127 } else {
128 Conn_set_socket_domain(C, PF_INET6);
129 Conn_set_socket_type(C, SOCK_STREAM);
130 Conn_set_socket_addr(C, "::1");
131 Conn_set_socket_port(C, port);
132 ret = Conn_commit(C);
133 if (ret != 0) {
134 printf("Error commiting [%s]!\n",
135 Conn_strerror());
136 errors++;
137 }
124 138 } }
125 139 } }
126 140
File examples/blackhole_s.c changed (mode: 100644) (index 3229d7f..78fbbd6)
25 25 #include <Conn.h> #include <Conn.h>
26 26
27 27 /* Global variables */ /* Global variables */
28 static unsigned short debug = 4;
28 static unsigned short debug = 7;
29 29
30 30 static int port = 9000; static int port = 9000;
31 31 static short ipv4 = 1, ipv6 = 1; static short ipv4 = 1, ipv6 = 1;
 
... ... static unsigned long long errors = 0;
34 34
35 35 static void s_accept_error(struct Conn *C) static void s_accept_error(struct Conn *C)
36 36 { {
37 printf("Cannot accept a new connection!\n");
38 }
39
40 static void s_accept(struct Conn *C)
41 {
42 }
43
44 static void s_close(struct Conn *C)
45 {
37 printf("Cannot accept a new connection via %llu!\n",
38 Conn_getid(C));
39 errors++;
46 40 } }
47 41
48 42 static void s_data(struct Conn *C) static void s_data(struct Conn *C)
 
... ... static void s_data(struct Conn *C)
54 48
55 49 static void s_error(struct Conn *C) static void s_error(struct Conn *C)
56 50 { {
57 /*
58 51 printf("%s id=%llu (%s)\n", printf("%s id=%llu (%s)\n",
59 52 __FUNCTION__, Conn_getid(C), Conn_strerror()); __FUNCTION__, Conn_getid(C), Conn_strerror());
60 */
61 53 errors++; errors++;
62 54 } }
63 55
64 56 int main(void) int main(void)
65 57 { {
66 struct Conn *I4 = NULL, *I6 = NULL;
58 struct Conn *C = NULL;
67 59 int ret; int ret;
68 60
69 61 printf("\tPort=%d\n", port); printf("\tPort=%d\n", port);
 
... ... int main(void)
83 75
84 76 if (ipv4 == 1) { if (ipv4 == 1) {
85 77 printf("Trying to register IPv4 socket...\n"); printf("Trying to register IPv4 socket...\n");
86 I4 = Conn_socket(PF_INET, SOCK_STREAM, port);
87 if (!I4)
88 printf("Cannot bind on ipv4 socket [%s].\n", Conn_strerror());
78 C = Conn_alloc();
79 if (!C) {
80 printf("Cannot alloc socket [%s].\n", Conn_strerror());
81 errors++;
82 } else {
83 Conn_set_socket_domain(C, PF_INET);
84 Conn_set_socket_type(C, SOCK_STREAM);
85 Conn_set_socket_bind_port(C, port);
86 ret = Conn_commit(C);
87 if (ret != 0) {
88 printf("Cannot bind on ipv4 socket [%s].\n",
89 Conn_strerror());
90 errors++;
91 }
92 }
89 93 } }
90 94
91 95 if (ipv6 == 1) { if (ipv6 == 1) {
92 96 printf("Trying to register IPv6 socket...\n"); printf("Trying to register IPv6 socket...\n");
93 I6 = Conn_socket(PF_INET6, SOCK_STREAM, port);
94 if (!I6)
95 printf("Cannot bind on ipv6 socket [%s].\n", Conn_strerror());
96 }
97
98 if ((I6 == NULL) && (I4 == NULL)) {
99 printf("Cannot bind!\n");
100 return 1;
97 C = Conn_alloc();
98 if (!C) {
99 printf("Cannot alloc socket [%s].\n", Conn_strerror());
100 errors++;
101 } else {
102 Conn_set_socket_domain(C, PF_INET6);
103 Conn_set_socket_type(C, SOCK_STREAM);
104 Conn_set_socket_bind_port(C, port);
105 ret = Conn_commit(C);
106 if (ret != 0) {
107 printf("Cannot bind on ipv6 socket [%s].\n",
108 Conn_strerror());
109 errors++;
110 }
111 }
101 112 } }
102 113
103 Conn_accept_cb = s_accept;
104 114 Conn_data_cb = s_data; Conn_data_cb = s_data;
105 Conn_close_cb = s_close;
106 115 Conn_error_cb = s_error; Conn_error_cb = s_error;
107 116 Conn_accept_error_cb = s_accept_error; Conn_accept_error_cb = s_accept_error;
108 117
 
... ... int main(void)
112 121 if (ret == -1) { if (ret == -1) {
113 122 printf("Error calling Conn_poll [%s]!\n", Conn_strerror()); printf("Error calling Conn_poll [%s]!\n", Conn_strerror());
114 123 return 1; return 1;
115 }
124 } else if (ret == 0)
125 break;
116 126 } }
117 127
118 128 printf("Finish. Errors=%llu, Bytes=%llu!\n\n", errors, bytes); printf("Finish. Errors=%llu, Bytes=%llu!\n\n", errors, bytes);
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