author | Tero Marttila <terom@fixme.fi> |
Sat, 11 Apr 2009 06:03:24 +0300 | |
changeset 130 | ffefb6d85ea6 |
parent 118 | 05b8d5150313 |
permissions | -rw-r--r-- |
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
|
1 |
#include "sock_fd.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
|
2 |
|
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
|
3 |
#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
|
4 |
#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
|
5 |
#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
|
6 |
|
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 |
void sock_fd_event_handler (evutil_socket_t fd, short what, void *arg) |
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 |
{ |
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
|
9 |
struct sock_fd *sock = arg; |
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
|
10 |
|
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
|
11 |
(void) fd; |
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
|
12 |
|
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
|
13 |
// invoke appropriate callback |
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
|
14 |
sock_stream_invoke_callbacks(SOCK_FD_BASE(sock), what); |
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 |
} |
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
|
16 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
17 |
err_t sock_fd_read (struct sock_stream *base_sock, 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
|
18 |
{ |
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
|
19 |
struct sock_fd *sock = SOCK_FROM_BASE(base_sock, struct sock_fd); |
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
|
20 |
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
|
21 |
|
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
|
22 |
// read(), and detect non-EAGAIN or EOF |
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
|
23 |
if ((ret = read(sock->fd, buf, *len)) < 0 && errno != EAGAIN) |
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
|
24 |
// unexpected error |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
25 |
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
|
26 |
|
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
|
27 |
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
|
28 |
// EOF |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
29 |
return SET_ERROR(err, ERR_READ_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
|
30 |
|
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
|
31 |
|
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
|
32 |
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
|
33 |
// 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
|
34 |
*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
|
35 |
|
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
|
36 |
} 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
|
37 |
// 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
|
38 |
*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
|
39 |
} |
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 |
// 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
|
42 |
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
|
43 |
} |
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
|
44 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
45 |
err_t sock_fd_write (struct sock_stream *base_sock, 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
|
46 |
{ |
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 |
struct sock_fd *sock = SOCK_FROM_BASE(base_sock, struct sock_fd); |
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
|
48 |
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
|
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 |
// write(), and detect non-EAGAIN or EOF |
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 = write(sock->fd, buf, *len)) < 0 && errno != EAGAIN) |
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 |
// unexpected error |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
53 |
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
|
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 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
|
56 |
// EOF |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
57 |
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
|
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 |
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
|
61 |
// 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
|
62 |
*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
|
63 |
|
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
|
64 |
} 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
|
65 |
// 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
|
66 |
*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
|
67 |
} |
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 |
|
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
|
69 |
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
|
70 |
} |
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 |
|
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
|
72 |
err_t sock_fd_event_init (struct sock_stream *base_sock) |
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 |
{ |
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
|
74 |
struct sock_fd *sock = SOCK_FROM_BASE(base_sock, struct sock_fd); |
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 |
err_t err; |
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 |
|
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 |
// set nonblocking |
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
|
78 |
if ((err = sock_fd_set_nonblock(sock, 1))) |
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 |
return err; |
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 |
// add ourselves as the event handler |
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 |
if ((err = sock_fd_init_ev(sock, &sock_fd_event_handler, sock))) |
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 |
return err; |
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 |
|
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
|
85 |
// done |
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
|
86 |
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
|
87 |
} |
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
|
88 |
|
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
|
89 |
err_t sock_fd_event_enable (struct sock_stream *base_sock, short mask) |
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 |
{ |
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 |
struct sock_fd *sock = SOCK_FROM_BASE(base_sock, struct sock_fd); |
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 |
|
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 |
// implemented in sock_fd_add_event |
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 |
return sock_fd_enable_events(sock, mask); |
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 |
} |
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 |
void sock_fd_init (struct sock_fd *sock, int fd) |
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
|
98 |
{ |
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
|
99 |
assert(!sock->ev_read && !sock->ev_write); |
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
|
100 |
|
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
|
101 |
// initialize |
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
|
102 |
sock->fd = fd; |
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
|
103 |
} |
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
|
104 |
|
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
|
105 |
err_t sock_fd_set_nonblock (struct sock_fd *sock, bool nonblock) |
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
|
106 |
{ |
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
|
107 |
// fcntl it |
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
|
108 |
// XXX: maintain old flags? |
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
|
109 |
if (fcntl(sock->fd, F_SETFL, nonblock ? O_NONBLOCK : 0) < 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
|
110 |
RETURN_SET_ERROR_ERRNO(SOCK_FD_ERR(sock), ERR_FCNTL); |
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
|
111 |
|
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
|
112 |
// 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
|
113 |
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
|
114 |
} |
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
|
115 |
|
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
|
116 |
err_t sock_fd_init_ev (struct sock_fd *sock, void (*ev_cb)(evutil_socket_t, short, void *), void *cb_arg) |
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 |
{ |
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
|
118 |
// require valid fd |
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
|
119 |
assert(sock->fd >= 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
|
120 |
|
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 |
// this is initialization |
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 |
assert(sock->ev_read == NULL && sock->ev_write == NULL); |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
123 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
124 |
// store |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
125 |
sock->ev_cb = ev_cb; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
126 |
sock->ev_arg = 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
|
127 |
|
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
|
128 |
// create new event |
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
|
129 |
if ((sock->ev_read = event_new(_sock_stream_ctx.ev_base, sock->fd, EV_READ, ev_cb, cb_arg)) == NULL) |
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
|
130 |
return SET_ERROR(SOCK_FD_ERR(sock), ERR_EVENT_NEW); |
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
|
131 |
|
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
|
132 |
if ((sock->ev_write = event_new(_sock_stream_ctx.ev_base, sock->fd, EV_WRITE, ev_cb, cb_arg)) == NULL) |
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
|
133 |
return SET_ERROR(SOCK_FD_ERR(sock), ERR_EVENT_NEW); |
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
|
134 |
|
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
|
135 |
// 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
|
136 |
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
|
137 |
} |
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
|
138 |
|
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
|
139 |
err_t sock_fd_enable_events (struct sock_fd *sock, short mask) |
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
|
140 |
{ |
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
|
141 |
// just add the appropraite events |
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
|
142 |
if (mask & EV_READ && event_add(sock->ev_read, NULL)) |
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
|
143 |
return SET_ERROR(SOCK_FD_ERR(sock), ERR_EVENT_ADD); |
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
|
144 |
|
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
|
145 |
if (mask & EV_WRITE && event_add(sock->ev_write, NULL)) |
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
|
146 |
return SET_ERROR(SOCK_FD_ERR(sock), ERR_EVENT_ADD); |
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
|
147 |
|
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
|
148 |
// done |
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
|
149 |
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
|
150 |
} |
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
|
151 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
152 |
static void sock_fd_free_ev (struct sock_fd *sock) |
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
|
153 |
{ |
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
|
154 |
if (sock->ev_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
|
155 |
event_free(sock->ev_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
|
156 |
|
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
|
157 |
sock->ev_read = NULL; |
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
|
158 |
} |
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
|
159 |
|
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 |
if (sock->ev_write) { |
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 |
event_free(sock->ev_write); |
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
|
162 |
|
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 |
sock->ev_write = NULL; |
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
|
164 |
} |
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
|
165 |
} |
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
|
166 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
167 |
void sock_fd_deinit_ev (struct sock_fd *sock) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
168 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
169 |
sock_fd_free_ev(sock); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
170 |
sock->ev_cb = NULL; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
171 |
sock->ev_arg = NULL; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
172 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
173 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
174 |
err_t sock_fd_set (struct sock_fd *sock, int fd) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
175 |
{ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
176 |
// close the old one? |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
177 |
if (sock->fd >= 0) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
178 |
// XXX: warn on errors |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
179 |
close(sock->fd); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
180 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
181 |
// remove any old events |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
182 |
sock_fd_free_ev(sock); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
183 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
184 |
// set the new one |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
185 |
sock->fd = fd; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
186 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
187 |
// restore them |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
188 |
if (sock->ev_cb) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
189 |
return sock_fd_init_ev(sock, sock->ev_cb, sock->ev_arg); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
190 |
|
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
191 |
// ok |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
192 |
return SUCCESS; |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
193 |
} |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
194 |
|
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
|
195 |
err_t sock_fd_close (struct sock_fd *sock) |
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
|
196 |
{ |
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
|
197 |
struct error_info *err = SOCK_FD_ERR(sock); |
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
|
198 |
|
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
|
199 |
// no errors yet |
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
|
200 |
RESET_ERROR(err); |
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
|
201 |
|
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
|
202 |
// must be connected |
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
|
203 |
assert(sock->fd >= 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
|
204 |
|
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
|
205 |
// kill any events |
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
|
206 |
sock_fd_deinit_ev(sock); |
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
|
207 |
|
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
|
208 |
// close the socket itself |
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
|
209 |
if (close(sock->fd)) |
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
|
210 |
SET_ERROR_ERRNO(err, ERR_CLOSE); |
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
|
211 |
|
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
|
212 |
// invalidate |
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
|
213 |
sock->fd = -1; |
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
|
214 |
|
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
|
215 |
return ERROR_CODE(err); |
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
|
216 |
} |
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
|
217 |