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