]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/IoCallback.h
merge from trunk
[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 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
29 /// Buffer to store read(2) into when set.
30 // This is a pointer to the Jobs buffer rather than an SBuf using
31 // the same store since we cannot know when or how the Job will
32 // alter its SBuf while we are reading.
33 SBuf *buf2;
34
35 // Legacy c-string buffers used when buf2 is unset.
36 char *buf;
37 FREE *freefunc;
38 int size;
39 int offset;
40 comm_err_t errcode;
41 int xerrno;
42 #if USE_DELAY_POOLS
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.
56 void finish(comm_err_t code, int xerrn);
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.
64 class CbEntry
65 {
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
76 void CallbackTableInit();
77 void CallbackTableDestruct();
78
79 #define COMMIO_FD_READCB(fd) (&Comm::iocb_table[(fd)].readcb)
80 #define COMMIO_FD_WRITECB(fd) (&Comm::iocb_table[(fd)].writecb)
81
82 } // namespace Comm
83
84 #endif /* _SQUID_COMM_IOCALLBACK_H */