]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
ec41b64c AJ |
9 | #ifndef _SQUID_COMM_IOCALLBACK_H |
10 | #define _SQUID_COMM_IOCALLBACK_H | |
11 | ||
ec41b64c | 12 | #include "base/AsyncCall.h" |
c8407295 | 13 | #include "comm/Flag.h" |
b0388924 | 14 | #include "comm/forward.h" |
3d41e53a | 15 | #include "typedefs.h" |
ec41b64c | 16 | |
73042f2e AJ |
17 | class SBuf; |
18 | ||
f31be4b0 A |
19 | namespace Comm |
20 | { | |
ec41b64c AJ |
21 | |
22 | /// Type of IO callbacks the Comm layer deals with. | |
23 | typedef enum { | |
24 | IOCB_NONE, | |
25 | IOCB_READ, | |
26 | IOCB_WRITE | |
27 | } iocb_type; | |
28 | ||
29 | /// Details about a particular Comm IO callback event. | |
f31be4b0 A |
30 | class IoCallback |
31 | { | |
ec41b64c AJ |
32 | public: |
33 | iocb_type type; | |
b0388924 | 34 | Comm::ConnectionPointer conn; |
ec41b64c AJ |
35 | AsyncCall::Pointer callback; |
36 | char *buf; | |
37 | FREE *freefunc; | |
38 | int size; | |
39 | int offset; | |
c8407295 | 40 | Comm::Flag errcode; |
ec41b64c | 41 | int xerrno; |
9a0a18de | 42 | #if USE_DELAY_POOLS |
ec41b64c AJ |
43 | unsigned int quotaQueueReserv; ///< reservation ID from CommQuotaQueue |
44 | #endif | |
45 | ||
46 | bool active() const { return callback != NULL; } | |
47 | void setCallback(iocb_type type, AsyncCall::Pointer &cb, char *buf, FREE *func, int sz); | |
48 | ||
49 | /// called when fd needs to write but may need to wait in line for its quota | |
50 | void selectOrQueueWrite(); | |
51 | ||
52 | /// Actively cancel the given callback | |
53 | void cancel(const char *reason); | |
54 | ||
55 | /// finish the IO operation imediately and schedule the callback with the current state. | |
c8407295 | 56 | void finish(Comm::Flag code, int xerrn); |
ec41b64c AJ |
57 | |
58 | private: | |
59 | void reset(); | |
60 | }; | |
61 | ||
62 | /// Entry nodes for the IO callback table: iocb_table | |
63 | /// Keyed off the FD which the event applies to. | |
f31be4b0 A |
64 | class CbEntry |
65 | { | |
ec41b64c AJ |
66 | public: |
67 | int fd; | |
68 | IoCallback readcb; | |
69 | IoCallback writecb; | |
70 | }; | |
71 | ||
72 | /// Table of scheduled IO events which have yet to be processed ?? | |
73 | /// Callbacks which might be scheduled in future are stored in fd_table. | |
74 | extern CbEntry *iocb_table; | |
75 | ||
8a648e8d FC |
76 | void CallbackTableInit(); |
77 | void CallbackTableDestruct(); | |
ec41b64c AJ |
78 | |
79 | #define COMMIO_FD_READCB(fd) (&Comm::iocb_table[(fd)].readcb) | |
80 | #define COMMIO_FD_WRITECB(fd) (&Comm::iocb_table[(fd)].writecb) | |
81 | ||
e5519212 | 82 | } // namespace Comm |
ec41b64c AJ |
83 | |
84 | #endif /* _SQUID_COMM_IOCALLBACK_H */ | |
f53969cc | 85 |