]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm.h
9ccd68db77ecf7723375d966e672ce312475620e
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
12 #include "comm/IoCallback.h"
13 #include "CommCalls.h"
14 #include "StoreIOBuffer.h"
21 bool comm_iocallbackpending(void); /* inline candidate */
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
);
32 void comm_lingering_close(int fd
);
35 int comm_connect_addr(int sock
, const Ip::Address
&addr
);
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
);
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.
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 [::]
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.
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
);
62 int comm_openex(int, int, Ip::Address
&, int, const char *);
63 unsigned short comm_local_port(int fd
);
65 int comm_udp_sendto(int sock
, const Ip::Address
&to
, const void *buf
, int buflen
);
66 void commCallCloseHandlers(int fd
);
68 /// clear a timeout handler by FD number
69 void commUnsetFdTimeout(int fd
);
72 * Set or clear the timeout for some action on an active connection.
73 * API to replace commSetTimeout() when a Comm::ConnectionPointer is available.
75 int commSetConnTimeout(const Comm::ConnectionPointer
&conn
, int seconds
, AsyncCall::Pointer
&callback
);
76 int commUnsetConnTimeout(const Comm::ConnectionPointer
&conn
);
79 void commCloseAllSockets(void);
80 void checkTimeouts(void);
82 AsyncCall::Pointer
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
&);
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);
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.
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
); }
103 /* A comm engine that calls comm_select */
105 class CommSelectEngine
: public AsyncEngine
109 virtual int checkEvents(int timeout
);