Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Added Conn_for_every_line. | e7b9ae7009aa9a5cafa1f0f4e3916729f69dbb6b | Catalin(ux) M. BOIE | 2008-07-15 14:38:29 |
Bump version to 1.0.10. | 4919629756fe6236e2ff75e646e612ed534353e8 | Catalin(ux) M. BOIE | 2008-07-04 09:23:00 |
Updated duilder. | a20257fddc85103b43978c64d9cd4a5d4c1451ea | Catalin(ux) M. BOIE | 2008-07-04 09:14:18 |
Added SRPM_POST_RUN duilder config variable. | f7c007d745d147f285ad8bc0a9bdfea3a7d832c0 | Catalin(ux) M. BOIE | 2008-07-04 09:13:47 |
Changed my e-mail address and URL. | 9353a5fd0cad934232e41b23ee10872f33df2da1 | Catalin(ux) M. BOIE | 2008-07-04 09:13:10 |
Updated .gitignore. | c40b1c4bf37a2b43804e39444571110eb79be466 | Catalin(ux) M. BOIE | 2008-07-04 09:07:56 |
Added .gitignore for examples directory. | fc20d411e784066c30e3abe3d77989168fca1ee9 | Catalin(ux) M. BOIE | 2008-07-04 09:07:33 |
Added Conn_get_line. | 5916ac4c9544d242a21ac50178efae893dff4806 | Catalin(ux) M. BOIE | 2008-07-04 08:59:27 |
Prepared to use duilder (my custom builder). | 058d181795e64c0d1a82d587e7b1d858b7af87b2 | Catalin(ux) M. BOIE | 2008-03-21 13:37:19 |
Populated .gitignore file. | e549ac0271ac654f039d5a04a0708d25030b0ed6 | Catalin(ux) M. BOIE | 2008-03-21 13:12:49 |
Replaced umbrella with embedromix. | 6b6671cce7f0a2c98ac27705ad638c4e1bc52213 | Catalin(ux) M. BOIE | 2007-10-03 21:56:40 |
Incremented revision. | e79bace79bb15f59133841a144ef1ff04e516cd5 | Catalin(ux) M. BOIE | 2007-10-03 21:55:25 |
Changed changelog. | 00c9dba4e97d924299fd992ff8f4e20fce5c770e | Catalin(ux) M. BOIE | 2007-10-03 20:43:21 |
First import. | 5ad0e7b8aa527aaebab52c53b45c36257fce5d0a | Catalin(ux) M. BOIE | 2007-10-03 20:20:26 |
File | Lines added | Lines deleted |
---|---|---|
Conn.c | 27 | 0 |
Conn.h | 2 | 0 |
examples/Makefile | 4 | 1 |
examples/line1.c | 15 | 26 |
File Conn.c changed (mode: 100644) (index fdc5bb1..4f15ea5) | |||
... | ... | char *Conn_get_line(struct Conn *C) | |
1825 | 1825 | ||
1826 | 1826 | return Conn_ibuf(C); | return Conn_ibuf(C); |
1827 | 1827 | } | } |
1828 | |||
1829 | /* | ||
1830 | * Helper help building text line daemons | ||
1831 | */ | ||
1832 | void Conn_for_every_line(struct Conn *C, int (*cb)(struct Conn *C, char *line)) | ||
1833 | { | ||
1834 | int ret = 0; | ||
1835 | char *line; | ||
1836 | unsigned int line_size; | ||
1837 | |||
1838 | if (cb == NULL) | ||
1839 | return; | ||
1840 | |||
1841 | while (1) { | ||
1842 | line = Conn_get_line(C); | ||
1843 | if (line == NULL) | ||
1844 | break; | ||
1845 | |||
1846 | line_size = strlen(line) + 1; | ||
1847 | |||
1848 | ret = cb(C, line); | ||
1849 | if (ret != 0) | ||
1850 | break; | ||
1851 | |||
1852 | Conn_eat(C, line_size); | ||
1853 | } | ||
1854 | } |
File Conn.h changed (mode: 100644) (index 5cfc105..7241948) | |||
... | ... | extern void Conn_last_time(struct Conn *C, struct timeval *tv); | |
219 | 219 | extern int Conn_set_cb(struct Conn *C, unsigned int type, | extern int Conn_set_cb(struct Conn *C, unsigned int type, |
220 | 220 | void (*f)(struct Conn *)); | void (*f)(struct Conn *)); |
221 | 221 | extern char *Conn_get_line(struct Conn *C); | extern char *Conn_get_line(struct Conn *C); |
222 | extern void Conn_for_every_line(struct Conn *C, | ||
223 | int (*cb)(struct Conn *C, char *line)); | ||
222 | 224 | ||
223 | 225 | #endif | #endif |
File examples/Makefile changed (mode: 100644) (index 6016348..1503a0b) | |||
1 | TARGETS := s c raw udp_s timeout trigger | ||
1 | TARGETS := s c raw udp_s timeout trigger line1 | ||
2 | 2 | ||
3 | 3 | all: $(TARGETS) | all: $(TARGETS) |
4 | 4 | ||
... | ... | udp_s: udp_s.c $(OBJS) | |
21 | 21 | timeout: timeout.c $(OBJS) | timeout: timeout.c $(OBJS) |
22 | 22 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) |
23 | 23 | ||
24 | line1: line1.c $(OBJS) | ||
25 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | ||
26 | |||
24 | 27 | %: %.c $(OBJS) | %: %.c $(OBJS) |
25 | 28 | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) | gcc $(CFLAGS) $(INCS) $@.c -o $@ $(LIBS) |
26 | 29 |
File examples/line1.c copied from file examples/s.c (similarity 81%) (mode: 100644) (index 13143a0..a9b23f7) | |||
20 | 20 | #include <Conn.h> | #include <Conn.h> |
21 | 21 | ||
22 | 22 | /* Global variables */ | /* Global variables */ |
23 | static unsigned short debug = 1; | ||
23 | static unsigned short debug = 3; | ||
24 | 24 | ||
25 | 25 | static FILE *Logf = NULL; | static FILE *Logf = NULL; |
26 | static char *log_file = "s.log"; | ||
26 | static char *log_file = "line1.log"; | ||
27 | 27 | static int port = 9000; | static int port = 9000; |
28 | 28 | static short ipv4 = 1, ipv6 = 1; | static short ipv4 = 1, ipv6 = 1; |
29 | 29 | static int maxconn = 0; | static int maxconn = 0; |
... | ... | static void Log(unsigned short level, char *format, ...) | |
42 | 42 | ||
43 | 43 | static void s_accept(struct Conn *C) | static void s_accept(struct Conn *C) |
44 | 44 | { | { |
45 | char *s; | ||
46 | |||
47 | 45 | Log(4, "%s (A connection was accepted from [%s] on slot %d. Set POLLIN and enq greeting...\n", | Log(4, "%s (A connection was accepted from [%s] on slot %d. Set POLLIN and enq greeting...\n", |
48 | 46 | __FUNCTION__, C->addr, C->slot); | __FUNCTION__, C->addr, C->slot); |
49 | |||
50 | s = "Hello!\r\n"; | ||
51 | Conn_enqueue(C, s, strlen(s)); | ||
52 | Conn_close(C); | ||
53 | 47 | } | } |
54 | 48 | ||
55 | 49 | static void s_close(struct Conn *C) | static void s_close(struct Conn *C) |
... | ... | static void s_close(struct Conn *C) | |
58 | 52 | __FUNCTION__, C->addr, C->slot); | __FUNCTION__, C->addr, C->slot); |
59 | 53 | } | } |
60 | 54 | ||
61 | static void s_data(struct Conn *C) | ||
55 | static int s_data_cb(struct Conn *C, char *line) | ||
62 | 56 | { | { |
63 | int len; | ||
64 | char *buf; | ||
65 | 57 | char *dump; | char *dump; |
66 | 58 | ||
67 | len = C->ibuf_tail - C->ibuf_head; | ||
68 | buf = C->ibuf + C->ibuf_head; | ||
69 | |||
70 | if (debug >= 8) { | ||
71 | dump = Conn_dump(buf, len); | ||
72 | Log(8, "%s: recv head=%d tail=%d bytes on slot %d: [%s]\n", | ||
73 | __FUNCTION__, C->ibuf_head, C->ibuf_tail, | ||
74 | C->slot, dump); | ||
75 | free(dump); | ||
76 | } | ||
59 | dump = Conn_dump(line, strlen(line)); | ||
60 | Log(0, "%s: recv bytes head=%d tail=%d on slot %d: [%s]\n", | ||
61 | __FUNCTION__, C->ibuf_head, C->ibuf_tail, | ||
62 | C->slot, dump); | ||
63 | free(dump); | ||
77 | 64 | ||
78 | Log(8, " Send back: %s", buf); | ||
79 | Conn_enqueue(C, buf, len); | ||
65 | return 0; | ||
66 | } | ||
80 | 67 | ||
81 | Conn_eatall(C); | ||
68 | static void s_data(struct Conn *C) | ||
69 | { | ||
70 | Conn_for_every_line(C, s_data_cb); | ||
82 | 71 | } | } |
83 | 72 | ||
84 | 73 | static void s_error(struct Conn *C) | static void s_error(struct Conn *C) |
85 | 74 | { | { |
86 | Log(1, "%s slot=%d C=%p\n", | ||
87 | __FUNCTION__, C == NULL ? -1 : C->slot, (void *) C); | ||
75 | Log(1, "%s: cid=%llu\n", | ||
76 | __FUNCTION__, Conn_getid(C)); | ||
88 | 77 | } | } |
89 | 78 | ||
90 | 79 | int main(void) | int main(void) |