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