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