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