author | Tero Marttila <terom@fixme.fi> |
Wed, 27 May 2009 23:57:48 +0300 | |
branch | new-lib-errors |
changeset 217 | 7728d6ec3abf |
parent 182 | 471ca1e744da |
permissions | -rw-r--r-- |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
1 |
#include "transport_fd.h" |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
|
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
3 |
#include "log.h" |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
4 |
|
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
#include <fcntl.h> |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
#include <unistd.h> |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
#include <assert.h> |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
9 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
10 |
* Our libevent callback |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
11 |
*/ |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
12 |
static void transport_fd_on_event (evutil_socket_t _fd, short ev_what, void *arg) |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
13 |
{ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
14 |
struct transport_fd *fd = arg; |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
16 |
(void) _fd; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
17 |
|
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
18 |
short what = 0; |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
19 |
|
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
20 |
// build flags |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
21 |
if (ev_what & EV_READ) |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
22 |
what |= TRANSPORT_READ; |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
23 |
|
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
24 |
if (ev_what & EV_WRITE) |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
25 |
what |= TRANSPORT_WRITE; |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
26 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
27 |
// invoke user callback |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
28 |
fd->cb_func(fd, what, fd->cb_arg); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
31 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
32 |
* Our transport_methods implementations |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
33 |
*/ |
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
34 |
err_t transport_fd__read (transport_t *transport, void *buf, size_t *len, error_t *err) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
{ |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
36 |
struct transport_fd *fd = transport_check(transport, &transport_fd_type); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
int ret; |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
38 |
|
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
39 |
RESET_ERROR(err); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
40 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
// read(), and detect non-EAGAIN or EOF |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
42 |
if ((ret = read(fd->fd, buf, *len)) < 0 && errno != EAGAIN) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
// unexpected error |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
44 |
RETURN_SET_ERROR_ERRNO(err, ERR_READ); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
else if (ret == 0) |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
// EOF |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
48 |
return SET_ERROR(err, ERR_EOF); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
if (ret < 0) { |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
// EAGAIN -> zero bytes |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
*len = 0; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
} else { |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
// normal -> bytes read |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
*len = ret; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
// ok |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
return SUCCESS; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
|
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
64 |
err_t transport_fd__write (transport_t *transport, const void *buf, size_t *len, struct error_info *err) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
66 |
struct transport_fd *fd = transport_check(transport, &transport_fd_type); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
int ret; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
|
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
69 |
RESET_ERROR(err); |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
70 |
|
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
// write(), and detect non-EAGAIN or EOF |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
72 |
if ((ret = write(fd->fd, buf, *len)) < 0 && errno != EAGAIN) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
// unexpected error |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
74 |
RETURN_SET_ERROR_ERRNO(err, ERR_WRITE); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
else if (ret == 0) |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
// EOF |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
78 |
return SET_ERROR(err, ERR_WRITE_EOF); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
if (ret < 0) { |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
// EAGAIN -> zero bytes |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
*len = 0; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
|
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
85 |
if (transport->info.ev_mask & TRANSPORT_WRITE) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
86 |
// enable the write event |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
87 |
if ((ERROR_CODE(err) = transport_fd_enable(fd, TRANSPORT_WRITE))) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
88 |
return ERROR_CODE(err); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
89 |
|
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
} else { |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
// normal -> bytes read |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
*len = ret; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
return SUCCESS; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
|
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
98 |
err_t transport_fd__events (transport_t *transport, short ev_mask, error_t *err) |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
99 |
{ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
100 |
struct transport_fd *fd = transport_check(transport, &transport_fd_type); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
101 |
|
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
102 |
short mask = 0; |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
103 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
104 |
// enable read as requested |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
105 |
if (ev_mask & TRANSPORT_READ) |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
106 |
mask |= TRANSPORT_READ; |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
107 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
108 |
// enable write if requested and it's currently enabled |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
109 |
if ((ev_mask & TRANSPORT_WRITE) && event_pending(fd->ev_write, EV_WRITE, NULL)) |
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
110 |
mask |= TRANSPORT_WRITE; |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
111 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
112 |
// set |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
113 |
return (ERROR_CODE(err) = transport_fd_events(fd, mask)); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
114 |
} |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
115 |
|
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
116 |
void transport_fd__deinit (transport_t *transport) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
118 |
struct transport_fd *fd = transport_check(transport, &transport_fd_type); |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
119 |
|
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
120 |
transport_fd_deinit(fd); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
121 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
|
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
123 |
const struct transport_type transport_fd_type = { |
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
124 |
.base_type = { |
182
471ca1e744da
fix transport_fd to have the right parent, and fix transport_test
Tero Marttila <terom@fixme.fi>
parents:
176
diff
changeset
|
125 |
.parent = &transport_type_type, |
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
126 |
}, |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
127 |
.methods = { |
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
128 |
.read = transport_fd__read, |
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
129 |
.write = transport_fd__write, |
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
130 |
.events = transport_fd__events, |
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
131 |
.deinit = transport_fd__deinit |
159
d3e253d7281a
implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents:
157
diff
changeset
|
132 |
} |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
133 |
}; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
134 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
135 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
136 |
* Dummy callbacks |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
137 |
*/ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
138 |
void transport_fd_callback_user (struct transport_fd *fd, short what, void *arg) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
139 |
{ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
140 |
(void) arg; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
141 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
142 |
// proxy |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
143 |
transport_invoke(TRANSPORT_FD_BASE(fd), what); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
144 |
} |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
145 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
146 |
/** |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
147 |
* Function implementations |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
148 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
149 |
void transport_fd_init (struct transport_fd *fd, struct event_base *ev_base, int _fd) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
150 |
{ |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
151 |
// sanity-check |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
152 |
assert(!fd->fd); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
153 |
assert(!fd->ev_read && !fd->ev_write); |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
154 |
assert(_fd == TRANSPORT_FD_INVALID || _fd >= 0); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
155 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
156 |
// initialize |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
157 |
fd->ev_base = ev_base; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
158 |
fd->fd = _fd; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
159 |
fd->cb_func = fd->cb_arg = NULL; |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
160 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
161 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
162 |
err_t transport_fd_nonblock (struct transport_fd *fd, bool nonblock) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
163 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
164 |
assert(fd->fd != TRANSPORT_FD_INVALID); |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
165 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
166 |
// XXX: maintain old flags? |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
167 |
|
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
168 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
169 |
// set new flags |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
170 |
if (fcntl(fd->fd, F_SETFL, nonblock ? O_NONBLOCK : 0) < 0) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
171 |
return ERR_FCNTL; |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
172 |
|
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
173 |
return SUCCESS; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
174 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
176 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
177 |
* Install our internal event handler. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
178 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
179 |
* The events should not already be set up. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
180 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
181 |
* Cleans up partial events on errors |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
182 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
183 |
err_t transport_fd_install (struct transport_fd *fd) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
184 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
185 |
assert(fd->fd != TRANSPORT_FD_INVALID); |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
186 |
assert(!fd->ev_read && !fd->ev_write); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
187 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
188 |
// create new events |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
189 |
if ((fd->ev_read = event_new(fd->ev_base, fd->fd, EV_READ | EV_PERSIST, transport_fd_on_event, fd)) == NULL) |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
190 |
goto err_event_add; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
191 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
192 |
if ((fd->ev_write = event_new(fd->ev_base, fd->fd, EV_WRITE, transport_fd_on_event, fd)) == NULL) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
193 |
goto err_event_add; |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
194 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
195 |
// ok |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
196 |
return SUCCESS; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
197 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
198 |
err_event_add: |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
199 |
// remove partial events |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
200 |
transport_fd_clear(fd); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
201 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
202 |
return ERR_EVENT_NEW; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
203 |
} |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
204 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
205 |
err_t transport_fd_setup (struct transport_fd *fd, transport_fd_callback_func cb_func, void *cb_arg) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
206 |
{ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
207 |
// requires a valid fd |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
208 |
assert(fd->fd != TRANSPORT_FD_INVALID); |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
209 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
210 |
// store |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
211 |
fd->cb_func = cb_func; |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
212 |
fd->cb_arg = cb_arg; |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
213 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
214 |
// install the event handlers? |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
215 |
if (!fd->ev_read || !fd->ev_write) |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
216 |
return transport_fd_install(fd); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
217 |
else |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
218 |
return SUCCESS; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
219 |
} |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
220 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
221 |
err_t transport_fd_enable (struct transport_fd *fd, short mask) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
222 |
{ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
223 |
// just add the appropriate events |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
224 |
if (mask & TRANSPORT_READ && event_add(fd->ev_read, NULL)) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
225 |
return ERR_EVENT_ADD; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
226 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
227 |
if (mask & TRANSPORT_WRITE && event_add(fd->ev_write, NULL)) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
228 |
return ERR_EVENT_ADD; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
229 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
230 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
231 |
return SUCCESS; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
232 |
} |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
233 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
234 |
err_t transport_fd_disable (struct transport_fd *fd, short mask) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
235 |
{ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
236 |
if (mask & TRANSPORT_READ && event_del(fd->ev_read)) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
237 |
return ERR_EVENT_DEL; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
238 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
239 |
if (mask & TRANSPORT_WRITE && event_del(fd->ev_write)) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
240 |
return ERR_EVENT_DEL; |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
241 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
242 |
|
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
243 |
return SUCCESS; |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
244 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
245 |
|
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
246 |
err_t transport_fd_events (struct transport_fd *fd, short mask) |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
247 |
{ |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
248 |
err_t err; |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
249 |
|
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
250 |
// enable/disable read |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
251 |
if (mask & TRANSPORT_READ) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
252 |
err = event_add(fd->ev_read, NULL); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
253 |
else |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
254 |
err = event_del(fd->ev_read); |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
255 |
|
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
256 |
if (err) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
257 |
return err; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
258 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
259 |
// enable/disable write |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
260 |
if (mask & TRANSPORT_WRITE) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
261 |
err = event_add(fd->ev_write, NULL); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
262 |
else |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
263 |
err = event_del(fd->ev_write); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
264 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
265 |
if (err) |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
266 |
return err; |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
267 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
268 |
// ok |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
269 |
return SUCCESS; |
117
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
270 |
} |
9cb405164250
move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
271 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
272 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
273 |
* Remove our current ev_* events, but leave the cb_* intact. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
274 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
275 |
static void transport_fd_remove (struct transport_fd *fd) |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
276 |
{ |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
277 |
if (fd->ev_read) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
278 |
event_free(fd->ev_read); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
279 |
|
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
280 |
if (fd->ev_write) |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
281 |
event_free(fd->ev_write); |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
282 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
283 |
fd->ev_read = NULL; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
284 |
fd->ev_write = NULL; |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
285 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
286 |
|
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
287 |
void transport_fd_clear (struct transport_fd *fd) |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
288 |
{ |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
289 |
// remove the events |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
290 |
transport_fd_remove(fd); |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
291 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
292 |
// clear the callbacks |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
293 |
fd->cb_func = fd->cb_arg = NULL; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
294 |
} |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
295 |
|
157 | 296 |
err_t transport_fd_defaults (struct transport_fd *fd) |
297 |
{ |
|
298 |
error_t err; |
|
299 |
||
300 |
// install the transport_invoke callback handler |
|
301 |
if ((ERROR_CODE(&err) = transport_fd_setup(fd, transport_fd_callback_user, NULL))) |
|
302 |
goto error; |
|
303 |
||
304 |
// enable read unless masked out |
|
305 |
if (TRANSPORT_FD_BASE(fd)->info.ev_mask & TRANSPORT_READ) { |
|
306 |
if ((ERROR_CODE(&err) = transport_fd_enable(fd, TRANSPORT_READ))) |
|
307 |
goto error; |
|
308 |
} |
|
309 |
||
310 |
// ok |
|
311 |
return SUCCESS; |
|
312 |
||
313 |
error: |
|
314 |
return ERROR_CODE(&err); |
|
315 |
} |
|
316 |
||
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
317 |
err_t transport_fd_set (struct transport_fd *fd, int _fd) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
318 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
319 |
assert(_fd == TRANSPORT_FD_INVALID || _fd >= 0); |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
320 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
321 |
// close the old stuff |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
322 |
transport_fd_close(fd); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
323 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
324 |
// set the new one |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
325 |
fd->fd = _fd; |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
326 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
327 |
// do we have callbacks that we need to setup? |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
328 |
if (fd->cb_func) |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
329 |
return transport_fd_install(fd); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
330 |
else |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
331 |
return SUCCESS; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
332 |
} |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
333 |
|
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
334 |
void transport_fd_invoke (struct transport_fd *fd, short what) |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
335 |
{ |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
336 |
// invoke |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
337 |
transport_invoke(TRANSPORT_FD_BASE(fd), what); |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
338 |
} |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
339 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
340 |
err_t transport_fd_close (struct transport_fd *fd) |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
341 |
{ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
342 |
int _fd = fd->fd; |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
343 |
|
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
344 |
// remove any installed events |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
345 |
transport_fd_remove(fd); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
346 |
|
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
347 |
// invalidate fd |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
348 |
fd->fd = TRANSPORT_FD_INVALID; |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
349 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
350 |
// close the fd |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
351 |
if (_fd != TRANSPORT_FD_INVALID && close(_fd)) |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
352 |
return ERR_CLOSE; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
353 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
354 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
355 |
return SUCCESS; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
356 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
357 |
|
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
358 |
void transport_fd_deinit (struct transport_fd *fd) |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
359 |
{ |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
360 |
err_t tmp; |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
361 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
362 |
// XXX: this might block |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
363 |
if ((tmp = transport_fd_close(fd))) |
176
6750d50ee8cd
modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents:
159
diff
changeset
|
364 |
log_warn_err(tmp, "close"); |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
365 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
366 |
} |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
367 |