]>
Commit | Line | Data |
---|---|---|
c4b7a5a9 | 1 | #ifndef __COMM_H__ |
2 | #define __COMM_H__ | |
3 | ||
ec41b64c | 4 | #include "comm/IoCallback.h" |
602d9612 | 5 | #include "CommCalls.h" |
cfd66529 | 6 | #include "StoreIOBuffer.h" |
c4b7a5a9 | 7 | |
e4a14600 A |
8 | namespace Ip |
9 | { | |
fafe8849 FC |
10 | class Address; |
11 | } | |
12 | ||
8a648e8d FC |
13 | bool comm_iocallbackpending(void); /* inline candidate */ |
14 | ||
15 | int commSetNonBlocking(int fd); | |
16 | int commUnsetNonBlocking(int fd); | |
17 | void commSetCloseOnExec(int fd); | |
18 | void commSetTcpKeepalive(int fd, int idle, int interval, int timeout); | |
19 | void _comm_close(int fd, char const *file, int line); | |
cfd66529 | 20 | #define comm_close(x) (_comm_close((x), __FILE__, __LINE__)) |
8a648e8d FC |
21 | void old_comm_reset_close(int fd); |
22 | void comm_reset_close(const Comm::ConnectionPointer &conn); | |
a553a5a3 | 23 | #if LINGERING_CLOSE |
8a648e8d | 24 | void comm_lingering_close(int fd); |
a553a5a3 | 25 | #endif |
a553a5a3 | 26 | |
8a648e8d FC |
27 | int comm_connect_addr(int sock, const Ip::Address &addr); |
28 | void comm_init(void); | |
29 | void comm_exit(void); | |
a553a5a3 | 30 | |
8a648e8d FC |
31 | int comm_open(int, int, Ip::Address &, int, const char *note); |
32 | int comm_open_uds(int sock_type, int proto, struct sockaddr_un* addr, int flags); | |
56c3c9aa | 33 | /// update Comm state after getting a comm_open() FD from another process |
8a648e8d | 34 | void comm_import_opened(const Comm::ConnectionPointer &, const char *note, struct addrinfo *AI); |
a553a5a3 | 35 | |
31be869c AJ |
36 | /** |
37 | * Open a port specially bound for listening or sending through a specific port. | |
38 | * This is a wrapper providing IPv4/IPv6 failover around comm_openex(). | |
39 | * Please use for all listening sockets and bind() outbound sockets. | |
40 | * | |
41 | * It will open a socket bound for: | |
42 | * - IPv4 if IPv6 is disabled or address is IPv4-native. | |
43 | * - IPv6 if address is IPv6-native | |
44 | * - IPv6 dual-stack mode if able to open [::] | |
45 | * | |
46 | * When an open performs failover it update the given address to feedback | |
47 | * the new IPv4-only status of the socket. Further displays of the IP | |
48 | * (in debugs or cachemgr) will occur in Native IPv4 format. | |
49 | * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open. | |
50 | */ | |
8a648e8d | 51 | int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note); |
e02ed2e3 | 52 | void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note); |
31be869c | 53 | |
e02ed2e3 | 54 | int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *); |
8a648e8d | 55 | unsigned short comm_local_port(int fd); |
a553a5a3 | 56 | |
8a648e8d FC |
57 | int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen); |
58 | void commCallCloseHandlers(int fd); | |
933dd095 AJ |
59 | |
60 | /// clear a timeout handler by FD number | |
8a648e8d | 61 | void commUnsetFdTimeout(int fd); |
7957e704 AJ |
62 | |
63 | /** | |
64 | * Set or clear the timeout for some action on an active connection. | |
65 | * API to replace commSetTimeout() when a Comm::ConnectionPointer is available. | |
66 | */ | |
8a648e8d FC |
67 | int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &callback); |
68 | int commUnsetConnTimeout(const Comm::ConnectionPointer &conn); | |
7957e704 | 69 | |
8a648e8d FC |
70 | int ignoreErrno(int); |
71 | void commCloseAllSockets(void); | |
72 | void checkTimeouts(void); | |
a553a5a3 | 73 | |
8a648e8d FC |
74 | void comm_add_close_handler(int fd, CLCB *, void *); |
75 | void comm_add_close_handler(int fd, AsyncCall::Pointer &); | |
76 | void comm_remove_close_handler(int fd, CLCB *, void *); | |
77 | void comm_remove_close_handler(int fd, AsyncCall::Pointer &); | |
78 | ||
8a648e8d FC |
79 | int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from); |
80 | int comm_udp_recv(int fd, void *buf, size_t len, int flags); | |
81 | ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags); | |
82 | bool comm_has_incomplete_write(int); | |
cf3c0ee3 | 83 | |
82ec8dfc AR |
84 | /** The read channel has closed and the caller does not expect more data |
85 | * but needs to detect connection aborts. The current detection method uses | |
86 | * 0-length reads: We read until the error occurs or the writer closes | |
87 | * the connection. If there is a read error, we close the connection. | |
88 | */ | |
8a648e8d FC |
89 | void commStartHalfClosedMonitor(int fd); |
90 | bool commHasHalfClosedMonitor(int fd); | |
82ec8dfc AR |
91 | // XXX: remove these wrappers which minimize client_side.cc changes in a commit |
92 | inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); } | |
93 | inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); } | |
94 | ||
8ff3fa2e | 95 | /* A comm engine that calls comm_select */ |
96 | ||
97 | class CommSelectEngine : public AsyncEngine | |
98 | { | |
99 | ||
100 | public: | |
101 | virtual int checkEvents(int timeout); | |
102 | }; | |
103 | ||
c4b7a5a9 | 104 | #endif |