Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Added a reconnect example. | 59b8156a8c5d17c90b5b064b1e1043b365ddac0a | Catalin(ux) M. BOIE | 2009-04-17 14:31:47 |
Show a nicer value if the reconnect feat was never used. | f51cf254286f76721e517eb69aa00695bdb3b2f5 | Catalin(ux) M. BOIE | 2009-04-17 14:30:59 |
Reget the time, even if no events. Else, the expiration will not work. | a1167cc19d739d62d6a21fd238c701c60a64cf6d | Catalin(ux) M. BOIE | 2009-04-17 14:12:57 |
Be more verbose and show also the flags. | 377f288df5d1fbde5c14276e8256fb88216d8761 | Catalin(ux) M. BOIE | 2009-04-17 13:01:59 |
Changed split test to show that we can get past 4096 limit. | 8ae8fefc1f2d19dbc893a95818ecadcc5c3014e0 | Catalin(ux) M. BOIE | 2009-04-17 12:46:03 |
Improved Conn_split (and remove the limitation to 4096 'right' value. | ec46e3c94da65fe94ed109727fd3dcb50384a44e | Catalin(ux) M. BOIE | 2009-04-17 12:31:53 |
Removed an unsused variable. | 1fa664bac9482c6e053bb3ea1d06280b66dadfed | Catalin(ux) M. BOIE | 2009-04-17 12:04:46 |
Simplified expand_buf and also fixed an out-of-bounds wrinting. | a2a507f235f7847277c2a485af8efb8efaa1ffa7 | Catalin(ux) M. BOIE | 2009-04-17 12:03:34 |
Bump up the version. | b720ca953940baf51a3e8263e6ec5d397a1c1ff2 | Catalin(ux) M. BOIE | 2009-04-14 12:39:01 |
Fixed Conn_rtrim. | 5f12cd953b0b998db8530eaed30b91bb181b7b26 | Catalin(ux) M. BOIE | 2009-04-14 12:38:39 |
Really fixed Conn_split_get. | 5ab1e0a47574fc6776e014be3d8150a048866607 | Catalin(ux) M. BOIE | 2009-04-14 08:34:38 |
Added Conn_alphanum (test if a string is alpha numeric or not). | 0bb8d19eed947aa82640610a0d894141e466105a | Catalin(ux) M. BOIE | 2009-04-14 08:22:02 |
Reverse the meaning of Conn_split_get_e and Conn_split_get. | 836229353a26ecc1bac762ece6cf42319113f5b1 | Catalin(ux) M. BOIE | 2009-04-14 08:21:35 |
Before calling callback in Conn_for_every_line, just trim '\r'. | 51e532893e74c4bee9b6847732442536e79eb2a0 | Catalin(ux) M. BOIE | 2009-04-14 06:39:29 |
Added Conn_rtrim function. | c37737a16e3d9de95cf659bae546de8808a3e3ed | Catalin(ux) M. BOIE | 2009-04-14 06:26:16 |
Revert "Conn_get_line removes also '\r' now." | 9d56ef9813225fe1127a2d5800c124aa65d5e1d2 | Catalin(ux) M. BOIE | 2009-04-14 06:20:50 |
Changed Conn_split to not modify original line. | 2f0d734f54b243356d0d4468691af50aad9e667a | Catalin(ux) M. BOIE | 2009-04-14 06:00:26 |
Added Conn_split_get_ull (unsigned long long). | 735e92324db56d5e9875f4e123102fc1e995cb4d | Catalin(ux) M. BOIE | 2009-04-13 22:13:04 |
Conn_get_line removes also '\r' now. | c1e5a9915b3ae6196a68fb1e7f73f295bef1737c | Catalin(ux) M. BOIE | 2009-04-13 21:56:47 |
Re-export Conn_get lost somehow. | 293f7aaed4f39de54821c8863023adb0e00234ac | Catalin(ux) M. BOIE | 2009-04-13 21:33:19 |
File | Lines added | Lines deleted |
---|---|---|
examples/Makefile | 4 | 1 |
examples/reconnect.c | 26 | 35 |
examples/reconnect.run | 2 | 2 |
File examples/Makefile changed (mode: 100644) (index d5cf65e..ffefa3f) | |||
1 | TARGETS := s s_bind c raw udp_s timeout trigger line1 | ||
1 | TARGETS := s s_bind c raw udp_s timeout trigger line1 reconnect | ||
2 | 2 | ||
3 | 3 | all: $(TARGETS) | all: $(TARGETS) |
4 | 4 | ||
... | ... | timeout: timeout.c $(DEPS) | |
28 | 28 | line1: line1.c $(DEPS) | line1: line1.c $(DEPS) |
29 | 29 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) |
30 | 30 | ||
31 | reconnect: reconnect.c $(DEPS) | ||
32 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | ||
33 | |||
31 | 34 | %: %.c $(DEPS) | %: %.c $(DEPS) |
32 | 35 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) |
33 | 36 |
File examples/reconnect.c copied from file examples/timeout.c (similarity 63%) (mode: 100644) (index 8245c3a..9d669a6) | |||
1 | /* | ||
2 | * Shows how reconnect works | ||
3 | * Author: Catalin(ux) M. BOIE | ||
4 | */ | ||
5 | |||
1 | 6 | #define _GNU_SOURCE | #define _GNU_SOURCE |
2 | 7 | ||
3 | 8 | #include <errno.h> | #include <errno.h> |
21 | 26 | ||
22 | 27 | /* Global variables */ | /* Global variables */ |
23 | 28 | static unsigned short debug = 20; | static unsigned short debug = 20; |
24 | |||
25 | 29 | static FILE *Logf = NULL; | static FILE *Logf = NULL; |
26 | static char *log_file = "timeout.log"; | ||
30 | static char *log_file = "reconnect.log"; | ||
27 | 31 | ||
28 | 32 | ||
29 | 33 | static void c_connected(struct Conn *C) | static void c_connected(struct Conn *C) |
30 | 34 | { | { |
31 | Log(4, "%s(A connection was estabilished on slot %d)\n", | ||
32 | __FUNCTION__, C->slot); | ||
33 | |||
34 | |||
35 | Conn_close(C); | ||
35 | Log(4, "%s: A connection was estabilished with id %llu)\n", | ||
36 | __FUNCTION__, Conn_getid(C)); | ||
36 | 37 | } | } |
37 | 38 | ||
38 | 39 | static void c_close(struct Conn *C) | static void c_close(struct Conn *C) |
39 | 40 | { | { |
40 | Log(5, "%s(Slot %d will close)\n", | ||
41 | __FUNCTION__, C->slot); | ||
42 | free(C->private); | ||
41 | Log(5, "%s: id=%llu will close...\n", | ||
42 | __FUNCTION__, Conn_getid(C)); | ||
43 | 43 | } | } |
44 | 44 | ||
45 | static void c_data(struct Conn *C) | ||
45 | static int c_data_cb(struct Conn *C, char *line) | ||
46 | 46 | { | { |
47 | 47 | char *dump; | char *dump; |
48 | 48 | ||
49 | 49 | if (debug >= 8) { | if (debug >= 8) { |
50 | dump = Conn_dump(C->ibuf + C->ibuf_head, Conn_qlen(C)); | ||
50 | dump = Conn_dump(line, strlen(line)); | ||
51 | 51 | Log(8, "data: recv: %s\n", dump); | Log(8, "data: recv: %s\n", dump); |
52 | 52 | free(dump); | free(dump); |
53 | 53 | } | } |
54 | 54 | ||
55 | Conn_close(C); | ||
55 | return 0; | ||
56 | } | ||
56 | 57 | ||
57 | Conn_eatall(C); | ||
58 | static void c_data(struct Conn *C) | ||
59 | { | ||
60 | Conn_for_every_line(C, c_data_cb); | ||
58 | 61 | } | } |
59 | 62 | ||
60 | 63 | static void c_error(struct Conn *C) | static void c_error(struct Conn *C) |
61 | 64 | { | { |
62 | Log(0, "%s Slot=%u [%s]\n", | ||
63 | __FUNCTION__, C->slot, Conn_strerror()); | ||
65 | Log(0, "%s id=%llu [%s]\n", | ||
66 | __FUNCTION__, Conn_getid(C), Conn_strerror()); | ||
64 | 67 | } | } |
65 | 68 | ||
66 | 69 | int main(void) | int main(void) |
67 | 70 | { | { |
68 | char *stat; | ||
69 | 71 | int ret; | int ret; |
70 | 72 | struct Conn *C; | struct Conn *C; |
71 | 73 | ||
... | ... | int main(void) | |
78 | 80 | if (debug > 0) | if (debug > 0) |
79 | 81 | setlinebuf(Logf); | setlinebuf(Logf); |
80 | 82 | ||
81 | Log(0, "Starting...\n"); | ||
82 | Log(0, "\tLogFile=%s Debug=%d\n", log_file, debug); | ||
83 | |||
84 | 83 | Conn_debug(Logf, debug); | Conn_debug(Logf, debug); |
85 | 84 | ||
86 | 85 | ret = Conn_init(0); | ret = Conn_init(0); |
... | ... | int main(void) | |
94 | 93 | Conn_close_cb = c_close; | Conn_close_cb = c_close; |
95 | 94 | Conn_error_cb = c_error; | Conn_error_cb = c_error; |
96 | 95 | ||
97 | /* Connect to google */ | ||
98 | C = Conn_connect(PF_INET, SOCK_STREAM, "209.85.129.104", 80); | ||
96 | C = Conn_connect(PF_INET, SOCK_STREAM, "www.google.com", 80); | ||
99 | 97 | if (C == NULL) { | if (C == NULL) { |
100 | 98 | Log(0, "Error calling Conn_connect [%s]!\n", | Log(0, "Error calling Conn_connect [%s]!\n", |
101 | 99 | Conn_strerror()); | Conn_strerror()); |
102 | 100 | return 1; | return 1; |
103 | 101 | } | } |
104 | 102 | ||
105 | /* Force a timeout for connect */ | ||
106 | Conn_set(C, CONN_PARA_CONN_TIMEOUT, 1); | ||
103 | Conn_set(C, CONN_PARA_AUTO_RECONNECT, 1); | ||
104 | Conn_set(C, CONN_PARA_RECONNECT_DELAY, 10); | ||
107 | 105 | ||
108 | 106 | while (1) { | while (1) { |
109 | ret = Conn_poll(10); | ||
107 | ret = Conn_poll(-1); | ||
110 | 108 | if (ret == -1) { | if (ret == -1) { |
111 | 109 | Log(0, "Error in poll [%s]!\n", | Log(0, "Error in poll [%s]!\n", |
112 | 110 | Conn_strerror()); | Conn_strerror()); |
113 | 111 | break; | break; |
114 | 112 | } | } |
113 | } | ||
115 | 114 | ||
116 | if (ret == 0) { | ||
117 | Log(0, "Finish work!\n"); | ||
118 | break; | ||
119 | } | ||
115 | Conn_shutdown(); | ||
120 | 116 | ||
121 | if (debug >= 9) { | ||
122 | stat = Conn_status(0); | ||
123 | Log(9, "%s\n", stat); | ||
124 | free(stat); | ||
125 | } | ||
126 | } | ||
117 | fclose(Logf); | ||
127 | 118 | ||
128 | 119 | return 0; | return 0; |
129 | 120 | } | } |
File examples/reconnect.run copied from file examples/c.run (similarity 89%) (mode: 100755) (index 4d21c30..67c7fdb) | |||
3 | 3 | export LD_LIBRARY_PATH=..:${LD_LIBRARY_PATH} | export LD_LIBRARY_PATH=..:${LD_LIBRARY_PATH} |
4 | 4 | ||
5 | 5 | ulimit -n60000 | ulimit -n60000 |
6 | >c.log | ||
6 | >reconnect.log | ||
7 | 7 | valgrind --tool=memcheck \ | valgrind --tool=memcheck \ |
8 | 8 | -v \ | -v \ |
9 | 9 | --num-callers=16 \ | --num-callers=16 \ |
... | ... | valgrind --tool=memcheck \ | |
11 | 11 | --db-command="gdb -nw %f %p" \ | --db-command="gdb -nw %f %p" \ |
12 | 12 | --db-attach=yes \ | --db-attach=yes \ |
13 | 13 | --show-reachable=yes \ | --show-reachable=yes \ |
14 | ./c | ||
14 | ./reconnect |