]>
Commit | Line | Data |
---|---|---|
c4b7a5a9 | 1 | #ifndef __COMM_H__ |
2 | #define __COMM_H__ | |
3 | ||
8ff3fa2e | 4 | #include "AsyncEngine.h" |
882255af | 5 | #include "base/AsyncCall.h" |
f9b72e0c | 6 | #include "CommCalls.h" |
ec41b64c AJ |
7 | #include "comm_err_t.h" |
8 | #include "comm/IoCallback.h" | |
582c2af2 | 9 | #include "ip/Address.h" |
cfd66529 | 10 | #include "StoreIOBuffer.h" |
c4b7a5a9 | 11 | |
a553a5a3 | 12 | /* comm.c */ |
a553a5a3 | 13 | extern bool comm_iocallbackpending(void); /* inline candidate */ |
14 | ||
a553a5a3 | 15 | SQUIDCEXTERN int commSetNonBlocking(int fd); |
16 | SQUIDCEXTERN int commUnsetNonBlocking(int fd); | |
17 | SQUIDCEXTERN void commSetCloseOnExec(int fd); | |
b2130d58 | 18 | SQUIDCEXTERN void commSetTcpKeepalive(int fd, int idle, int interval, int timeout); |
a553a5a3 | 19 | extern void _comm_close(int fd, char const *file, int line); |
cfd66529 | 20 | #define comm_close(x) (_comm_close((x), __FILE__, __LINE__)) |
5c336a3b | 21 | SQUIDCEXTERN void old_comm_reset_close(int fd); |
8ace824c | 22 | SQUIDCEXTERN void comm_reset_close(const Comm::ConnectionPointer &conn); |
a553a5a3 | 23 | #if LINGERING_CLOSE |
24 | SQUIDCEXTERN void comm_lingering_close(int fd); | |
25 | #endif | |
a553a5a3 | 26 | |
b7ac5457 | 27 | SQUIDCEXTERN int comm_connect_addr(int sock, const Ip::Address &addr); |
a553a5a3 | 28 | SQUIDCEXTERN void comm_init(void); |
236d1779 | 29 | SQUIDCEXTERN void comm_exit(void); |
a553a5a3 | 30 | |
b7ac5457 | 31 | SQUIDCEXTERN int comm_open(int, int, Ip::Address &, int, const char *note); |
10cefb7b | 32 | SQUIDCEXTERN 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 |
e0d28505 | 34 | SQUIDCEXTERN 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 | */ | |
e0d28505 AJ |
51 | extern int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note); |
52 | extern void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note); | |
31be869c | 53 | |
425de4c8 | 54 | SQUIDCEXTERN int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *); |
f45dd259 | 55 | SQUIDCEXTERN unsigned short comm_local_port(int fd); |
a553a5a3 | 56 | |
b7ac5457 | 57 | SQUIDCEXTERN int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen); |
a553a5a3 | 58 | SQUIDCEXTERN void commCallCloseHandlers(int fd); |
933dd095 AJ |
59 | |
60 | /// clear a timeout handler by FD number | |
61 | extern 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 | */ | |
ec20038e | 67 | extern int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &callback); |
8d77a37c | 68 | extern int commUnsetConnTimeout(const Comm::ConnectionPointer &conn); |
7957e704 | 69 | |
a553a5a3 | 70 | SQUIDCEXTERN int ignoreErrno(int); |
71 | SQUIDCEXTERN void commCloseAllSockets(void); | |
72 | SQUIDCEXTERN void checkTimeouts(void); | |
73 | ||
74 | ||
f9b72e0c | 75 | //typedef void IOACB(int fd, int nfd, Comm::ConnectionPointer details, comm_err_t flag, int xerrno, void *data); |
575d05c4 | 76 | extern void comm_add_close_handler(int fd, CLCB *, void *); |
b0469965 | 77 | extern void comm_add_close_handler(int fd, AsyncCall::Pointer &); |
575d05c4 | 78 | extern void comm_remove_close_handler(int fd, CLCB *, void *); |
b0469965 | 79 | extern void comm_remove_close_handler(int fd, AsyncCall::Pointer &); |
80 | ||
ee0989f2 | 81 | |
c4b7a5a9 | 82 | extern int comm_has_pending_read_callback(int fd); |
b0469965 | 83 | extern bool comm_monitors_read(int fd); |
abd8f140 | 84 | //extern void comm_read(const Comm::ConnectionPointer &conn, char *buf, int len, IOCB *handler, void *data); |
ec20038e | 85 | extern void comm_read(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer &callback); |
c4b7a5a9 | 86 | extern void comm_read_cancel(int fd, IOCB *callback, void *data); |
b0469965 | 87 | extern void comm_read_cancel(int fd, AsyncCall::Pointer &callback); |
b7ac5457 | 88 | extern int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from); |
7d21986b | 89 | extern int comm_udp_recv(int fd, void *buf, size_t len, int flags); |
90 | extern ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags); | |
545d554b | 91 | extern bool comm_has_incomplete_write(int); |
cf3c0ee3 | 92 | |
82ec8dfc AR |
93 | /** The read channel has closed and the caller does not expect more data |
94 | * but needs to detect connection aborts. The current detection method uses | |
95 | * 0-length reads: We read until the error occurs or the writer closes | |
96 | * the connection. If there is a read error, we close the connection. | |
97 | */ | |
98 | extern void commStartHalfClosedMonitor(int fd); | |
99 | extern bool commHasHalfClosedMonitor(int fd); | |
100 | // XXX: remove these wrappers which minimize client_side.cc changes in a commit | |
101 | inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); } | |
102 | inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); } | |
103 | ||
8ff3fa2e | 104 | /* A comm engine that calls comm_select */ |
105 | ||
106 | class CommSelectEngine : public AsyncEngine | |
107 | { | |
108 | ||
109 | public: | |
110 | virtual int checkEvents(int timeout); | |
111 | }; | |
112 | ||
c4b7a5a9 | 113 | #endif |