~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/comm.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
#include "squid.h"
5
5
#include "AsyncEngine.h"
6
 
#include "CompletionDispatcher.h"
 
6
#include "base/AsyncCall.h"
7
7
#include "StoreIOBuffer.h"
8
8
#include "Array.h"
 
9
#include "ip/IpAddress.h"
9
10
 
10
11
#define COMMIO_FD_READCB(fd)    (&commfd_table[(fd)].readcb)
11
12
#define COMMIO_FD_WRITECB(fd)   (&commfd_table[(fd)].writecb)
21
22
    COMM_ERR_CONNECT = -8,
22
23
    COMM_ERR_DNS = -9,
23
24
    COMM_ERR_CLOSING = -10,
 
25
#if USE_IPV6
 
26
    COMM_ERR_PROTOCOL = -11, /* IPv4 or IPv6 cannot be used on the fd socket */
 
27
#endif
24
28
} comm_err_t;
25
 
typedef void IOFCB(int fd, StoreIOBuffer receivedData, comm_err_t flag, int xerrno, void *data);
26
 
typedef void IOWCB(int fd, char *buffer, size_t len, comm_err_t flag, int xerrno, void *data);
27
29
 
28
 
typedef void CWCB(int fd, char *, size_t size, comm_err_t flag, void *data);
29
 
typedef void CNCB(int fd, comm_err_t status, int xerrno, void *data);
 
30
class DnsLookupDetails;
 
31
typedef void CNCB(int fd, const DnsLookupDetails &dns, comm_err_t status, int xerrno, void *data);
30
32
 
31
33
typedef void IOCB(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data);
32
34
 
 
35
 
33
36
/* comm.c */
34
 
extern void comm_calliocallback(void);
35
37
extern bool comm_iocallbackpending(void); /* inline candidate */
36
38
 
37
39
extern int comm_listen(int fd);
38
40
SQUIDCEXTERN int commSetNonBlocking(int fd);
39
41
SQUIDCEXTERN int commUnsetNonBlocking(int fd);
40
42
SQUIDCEXTERN void commSetCloseOnExec(int fd);
 
43
SQUIDCEXTERN void commSetTcpKeepalive(int fd, int idle, int interval, int timeout);
41
44
extern void _comm_close(int fd, char const *file, int line);
42
45
#define comm_close(fd) (_comm_close((fd), __FILE__, __LINE__))
43
46
SQUIDCEXTERN void comm_reset_close(int fd);
45
48
SQUIDCEXTERN void comm_lingering_close(int fd);
46
49
#endif
47
50
SQUIDCEXTERN void commConnectStart(int fd, const char *, u_short, CNCB *, void *);
 
51
void commConnectStart(int fd, const char *, u_short, AsyncCall::Pointer &cb);
48
52
 
49
 
SQUIDCEXTERN int comm_connect_addr(int sock, const struct sockaddr_in *);
 
53
SQUIDCEXTERN int comm_connect_addr(int sock, const IpAddress &addr);
50
54
SQUIDCEXTERN void comm_init(void);
51
55
SQUIDCEXTERN void comm_exit(void);
52
56
 
53
 
SQUIDCEXTERN int comm_open(int, int, struct IN_ADDR, u_short port, int, const char *note);
54
 
 
55
 
SQUIDCEXTERN int comm_openex(int, int, struct IN_ADDR, u_short, int, unsigned char TOS, const char *);
 
57
SQUIDCEXTERN int comm_open(int, int, IpAddress &, int, const char *note);
 
58
 
 
59
/**
 
60
 * Open a port specially bound for listening or sending through a specific port.
 
61
 * This is a wrapper providing IPv4/IPv6 failover around comm_openex().
 
62
 * Please use for all listening sockets and bind() outbound sockets.
 
63
 *
 
64
 * It will open a socket bound for:
 
65
 *  - IPv4 if IPv6 is disabled or address is IPv4-native.
 
66
 *  - IPv6 if address is IPv6-native
 
67
 *  - IPv6 dual-stack mode if able to open [::]
 
68
 *
 
69
 * When an open performs failover it update the given address to feedback
 
70
 * the new IPv4-only status of the socket. Further displays of the IP
 
71
 * (in debugs or cachemgr) will occur in Native IPv4 format.
 
72
 * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open.
 
73
 */
 
74
SQUIDCEXTERN int comm_open_listener(int sock_type, int proto, IpAddress &addr, int flags, const char *note);
 
75
 
 
76
SQUIDCEXTERN int comm_openex(int, int, IpAddress &, int, unsigned char TOS, const char *);
56
77
SQUIDCEXTERN u_short comm_local_port(int fd);
57
78
SQUIDCEXTERN int comm_set_tos(int fd, int tos);
58
79
 
59
80
SQUIDCEXTERN void commSetSelect(int, unsigned int, PF *, void *, time_t);
60
81
SQUIDCEXTERN void commResetSelect(int);
61
82
 
62
 
SQUIDCEXTERN int comm_udp_sendto(int, const struct sockaddr_in *, int, const void *, int);
 
83
SQUIDCEXTERN int comm_udp_sendto(int sock, const IpAddress &to, const void *buf, int buflen);
63
84
extern void comm_write(int fd, const char *buf, int len, IOCB *callback, void *callback_data, FREE *func);
 
85
extern void comm_write(int fd, const char *buf, int size, AsyncCall::Pointer &callback, FREE * free_func = NULL);
64
86
SQUIDCEXTERN void comm_write_mbuf(int fd, MemBuf *mb, IOCB * handler, void *handler_data);
 
87
extern void comm_write_mbuf(int fd, MemBuf *mb, AsyncCall::Pointer &callback);
65
88
SQUIDCEXTERN void commCallCloseHandlers(int fd);
66
89
SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *);
 
90
extern int commSetTimeout(int fd, int, AsyncCall::Pointer &calback);
67
91
SQUIDCEXTERN int ignoreErrno(int);
68
92
SQUIDCEXTERN void commCloseAllSockets(void);
69
93
SQUIDCEXTERN void checkTimeouts(void);
79
103
class ConnectionDetail;
80
104
typedef void IOACB(int fd, int nfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data);
81
105
extern void comm_accept(int fd, IOACB *handler, void *handler_data);
 
106
extern void comm_accept(int fd, AsyncCall::Pointer &call);
82
107
extern void comm_add_close_handler(int fd, PF *, void *);
 
108
extern void comm_add_close_handler(int fd, AsyncCall::Pointer &);
83
109
extern void comm_remove_close_handler(int fd, PF *, void *);
 
110
extern void comm_remove_close_handler(int fd, AsyncCall::Pointer &);
 
111
 
84
112
 
85
113
extern int comm_has_pending_read_callback(int fd);
86
 
extern bool comm_has_pending_read(int fd);
 
114
extern bool comm_monitors_read(int fd);
87
115
extern void comm_read(int fd, char *buf, int len, IOCB *handler, void *data);
 
116
extern void comm_read(int fd, char *buf, int len, AsyncCall::Pointer &callback);
88
117
extern void comm_read_cancel(int fd, IOCB *callback, void *data);
89
 
extern void fdc_open(int fd, unsigned int type, char const *desc);
90
 
extern int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags,
91
 
 
92
 
                                 struct sockaddr *from, socklen_t *fromlen);
 
118
extern void comm_read_cancel(int fd, AsyncCall::Pointer &callback);
 
119
extern int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, IpAddress &from);
93
120
extern int comm_udp_recv(int fd, void *buf, size_t len, int flags);
94
121
extern ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags);
95
 
extern void commMarkHalfClosed(int);
96
 
extern int commIsHalfClosed(int);
97
 
extern void commCheckHalfClosed(void *);
98
122
extern bool comm_has_incomplete_write(int);
99
123
 
 
124
/** The read channel has closed and the caller does not expect more data
 
125
 * but needs to detect connection aborts. The current detection method uses
 
126
 * 0-length reads: We read until the error occurs or the writer closes
 
127
 * the connection. If there is a read error, we close the connection.
 
128
 */
 
129
extern void commStartHalfClosedMonitor(int fd);
 
130
extern bool commHasHalfClosedMonitor(int fd);
 
131
// XXX: remove these wrappers which minimize client_side.cc changes in a commit
 
132
inline void commMarkHalfClosed(int fd) { commStartHalfClosedMonitor(fd); }
 
133
inline bool commIsHalfClosed(int fd) { return commHasHalfClosedMonitor(fd); }
 
134
 
100
135
/* Not sure where these should live yet */
101
136
 
102
137
class Acceptor
124
159
    Vector<Acceptor> deferred;
125
160
};
126
161
 
127
 
/* App layer doesn't want any more data from the socket, as the read channel is
128
 
 * closed, but we need to detect aborts, so this lets us do so.
129
 
 */
130
 
 
131
 
class AbortChecker
132
 
{
133
 
 
134
 
public:
135
 
    static AbortChecker &Instance();
136
 
    /* the current method of checking, is via a 0 length read every second.
137
 
     * if nothing is returned by the next IO loop, we let it be.
138
 
     * If an error occurs, we close the conn.
139
 
     * Note that some tcp environments may allow direct polling for the socket status
140
 
     * and this could be adjusted to use that method for the test. (in which case
141
 
     * the singleton should be refactored to have the tcp engine register the
142
 
     * instance with it).
143
 
     */
144
 
    static IOCB AbortCheckReader;
145
 
    void monitor (int);
146
 
    void stopMonitoring (int);
147
 
    void doIOLoop();
148
 
 
149
 
private:
150
 
    static AbortChecker Instance_;
151
 
    static void AddCheck (int const &, void *);
152
 
    static int IntCompare (int const &, int const &);
153
 
    static void RemoveCheck (int const &, void *);
154
 
    AbortChecker() : fds (NULL), checking (false), lastCheck (0){}
155
 
 
156
 
    mutable SplayNode<int> *fds;
157
 
    bool checking;
158
 
    time_t lastCheck;
159
 
    bool contains (int const) const;
160
 
 
161
 
    void remove
162
 
        (int const);
163
 
 
164
 
    void add
165
 
        (int const);
166
 
 
167
 
    void addCheck (int const);
168
 
 
169
 
    void removeCheck (int const);
170
 
};
171
 
 
172
 
/* a dispatcher for comms events */
173
 
 
174
 
class CommDispatcher : public CompletionDispatcher
175
 
{
176
 
 
177
 
public:
178
 
    virtual bool dispatch();
179
 
};
180
 
 
181
162
/* A comm engine that calls comm_select */
182
163
 
183
164
class CommSelectEngine : public AsyncEngine