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