File examples/c.c changed (mode: 100644) (index f7a867a..79d49f4) |
20 |
20 |
#include <Conn.h> |
#include <Conn.h> |
21 |
21 |
|
|
22 |
22 |
/* Global variables */ |
/* Global variables */ |
23 |
|
static unsigned short debug = 12; |
|
|
23 |
|
static unsigned short debug = 9; |
24 |
24 |
|
|
25 |
25 |
static FILE *Logf = NULL; |
static FILE *Logf = NULL; |
26 |
26 |
static char *log_file = "c.log"; |
static char *log_file = "c.log"; |
|
... |
... |
static void c_close(struct Conn *C) |
57 |
57 |
free(C->private); |
free(C->private); |
58 |
58 |
} |
} |
59 |
59 |
|
|
60 |
|
static void c_data(struct Conn *C) |
|
|
60 |
|
static int c_data_cb(struct Conn *C, char *line) |
61 |
61 |
{ |
{ |
62 |
62 |
struct priv *p; |
struct priv *p; |
63 |
63 |
char *dump; |
char *dump; |
64 |
|
char *line; |
|
65 |
64 |
|
|
66 |
65 |
p = (struct priv *) C->private; |
p = (struct priv *) C->private; |
67 |
66 |
|
|
68 |
|
while ((line = Conn_get_line(C))) { |
|
69 |
|
if (debug >= 8) { |
|
70 |
|
dump = Conn_dump(line, strlen(line)); |
|
71 |
|
Log(8, "data: recv: %s\n", dump); |
|
72 |
|
free(dump); |
|
73 |
|
} |
|
|
67 |
|
if (debug >= 8) { |
|
68 |
|
dump = Conn_dump(line, strlen(line)); |
|
69 |
|
Log(8, "data: recv: %s\n", dump); |
|
70 |
|
free(dump); |
|
71 |
|
} |
74 |
72 |
|
|
75 |
|
p->dummy++; |
|
|
73 |
|
p->dummy++; |
76 |
74 |
|
|
77 |
|
answers++; |
|
|
75 |
|
answers++; |
78 |
76 |
|
|
79 |
|
Conn_eat(C, strlen(line)); |
|
80 |
|
} |
|
|
77 |
|
return 0; |
|
78 |
|
} |
|
79 |
|
|
|
80 |
|
static void c_data(struct Conn *C) |
|
81 |
|
{ |
|
82 |
|
Conn_for_every_line(C, c_data_cb); |
81 |
83 |
|
|
82 |
84 |
Conn_close(C); |
Conn_close(C); |
83 |
85 |
} |
} |
|
... |
... |
static void c_error(struct Conn *C) |
90 |
92 |
|
|
91 |
93 |
int main(void) |
int main(void) |
92 |
94 |
{ |
{ |
93 |
|
char *stat; |
|
94 |
|
int ret; |
|
95 |
|
struct timeval start, end; |
|
96 |
|
unsigned int elap; |
|
97 |
|
unsigned int i, ipv4conns = 1, ipv6conns = 0; |
|
|
95 |
|
int ret; |
|
96 |
|
struct timeval start, end; |
|
97 |
|
unsigned int elap; |
|
98 |
|
unsigned int i, ipv4conns = 5000, ipv6conns = 5000; |
98 |
99 |
struct Conn *C4, *C6; |
struct Conn *C4, *C6; |
99 |
100 |
|
|
100 |
|
|
|
101 |
101 |
Logf = fopen(log_file, "a+"); |
Logf = fopen(log_file, "a+"); |
102 |
102 |
if (!Logf) { |
if (!Logf) { |
103 |
103 |
fprintf(stderr, "Cannot open log file [%s] [%s]\n", |
fprintf(stderr, "Cannot open log file [%s] [%s]\n", |
|
... |
... |
int main(void) |
161 |
161 |
break; |
break; |
162 |
162 |
} |
} |
163 |
163 |
|
|
164 |
|
if (debug >= 9) { |
|
165 |
|
stat = Conn_status(0); |
|
166 |
|
Log(9, "%s\n", stat); |
|
167 |
|
free(stat); |
|
168 |
|
} |
|
169 |
|
|
|
170 |
164 |
if (answers % 10 == 0) |
if (answers % 10 == 0) |
171 |
165 |
printf("."); |
printf("."); |
172 |
166 |
|
|
File examples/s.c changed (mode: 100644) (index d269331..8b9cb42) |
20 |
20 |
#include <Conn.h> |
#include <Conn.h> |
21 |
21 |
|
|
22 |
22 |
/* Global variables */ |
/* Global variables */ |
23 |
|
static unsigned short debug = 12; |
|
|
23 |
|
static unsigned short debug = 9; |
24 |
24 |
|
|
25 |
25 |
static FILE *Logf = NULL; |
static FILE *Logf = NULL; |
26 |
26 |
static char *log_file = "s.log"; |
static char *log_file = "s.log"; |
|
... |
... |
static void s_close(struct Conn *C) |
45 |
45 |
__FUNCTION__, C->addr, C->port, Conn_getid(C)); |
__FUNCTION__, C->addr, C->port, Conn_getid(C)); |
46 |
46 |
} |
} |
47 |
47 |
|
|
48 |
|
static void s_data(struct Conn *C) |
|
|
48 |
|
static int s_data_cb(struct Conn *C, char *line) |
49 |
49 |
{ |
{ |
50 |
|
char *line; |
|
51 |
50 |
char *dump; |
char *dump; |
52 |
51 |
|
|
53 |
|
line = Conn_get_line(C); |
|
54 |
|
if (!line) |
|
55 |
|
return; |
|
56 |
|
|
|
57 |
52 |
if (debug >= 8) { |
if (debug >= 8) { |
58 |
53 |
dump = Conn_dump(line, strlen(line)); |
dump = Conn_dump(line, strlen(line)); |
59 |
54 |
Log(8, "%s: recv head=%d tail=%d bytes on slot %d: [%s]\n", |
Log(8, "%s: recv head=%d tail=%d bytes on slot %d: [%s]\n", |
|
... |
... |
static void s_data(struct Conn *C) |
68 |
63 |
Log(8, " Send back: %s", line); |
Log(8, " Send back: %s", line); |
69 |
64 |
Conn_enqueue(C, line, strlen(line)); |
Conn_enqueue(C, line, strlen(line)); |
70 |
65 |
|
|
71 |
|
Conn_eat(C, strlen(line) + 1); |
|
|
66 |
|
return 0; |
|
67 |
|
} |
|
68 |
|
|
|
69 |
|
static void s_data(struct Conn *C) |
|
70 |
|
{ |
|
71 |
|
Conn_for_every_line(C, s_data_cb); |
72 |
72 |
} |
} |
73 |
73 |
|
|
74 |
74 |
static void s_error(struct Conn *C) |
static void s_error(struct Conn *C) |
|
... |
... |
int main(void) |
82 |
82 |
struct Conn *I4 = NULL, *I6 = NULL; |
struct Conn *I4 = NULL, *I6 = NULL; |
83 |
83 |
int ret; |
int ret; |
84 |
84 |
struct timeval start; |
struct timeval start; |
85 |
|
int loops = 0; |
|
86 |
85 |
|
|
87 |
86 |
Logf = fopen(log_file, "w"); |
Logf = fopen(log_file, "w"); |
88 |
87 |
if (!Logf) { |
if (!Logf) { |