]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/IoCallback.h
Boilerplate: update copyright blurbs on Squid helpers
[thirdparty/squid.git] / src / comm / IoCallback.h
CommitLineData
ec41b64c
AJ
1#ifndef _SQUID_COMM_IOCALLBACK_H
2#define _SQUID_COMM_IOCALLBACK_H
3
ec41b64c 4#include "base/AsyncCall.h"
c8407295 5#include "comm/Flag.h"
b0388924 6#include "comm/forward.h"
3d41e53a 7#include "typedefs.h"
ec41b64c 8
73042f2e
AJ
9class SBuf;
10
f31be4b0
A
11namespace Comm
12{
ec41b64c
AJ
13
14/// Type of IO callbacks the Comm layer deals with.
15typedef enum {
16 IOCB_NONE,
17 IOCB_READ,
18 IOCB_WRITE
19} iocb_type;
20
21/// Details about a particular Comm IO callback event.
f31be4b0
A
22class IoCallback
23{
ec41b64c
AJ
24public:
25 iocb_type type;
b0388924 26 Comm::ConnectionPointer conn;
ec41b64c
AJ
27 AsyncCall::Pointer callback;
28 char *buf;
29 FREE *freefunc;
30 int size;
31 int offset;
c8407295 32 Comm::Flag errcode;
ec41b64c 33 int xerrno;
9a0a18de 34#if USE_DELAY_POOLS
ec41b64c
AJ
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.
c8407295 48 void finish(Comm::Flag code, int xerrn);
ec41b64c
AJ
49
50private:
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.
f31be4b0
A
56class CbEntry
57{
ec41b64c
AJ
58public:
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.
66extern CbEntry *iocb_table;
67
8a648e8d
FC
68void CallbackTableInit();
69void CallbackTableDestruct();
ec41b64c
AJ
70
71#define COMMIO_FD_READCB(fd) (&Comm::iocb_table[(fd)].readcb)
72#define COMMIO_FD_WRITECB(fd) (&Comm::iocb_table[(fd)].writecb)
73
e5519212 74} // namespace Comm
ec41b64c
AJ
75
76#endif /* _SQUID_COMM_IOCALLBACK_H */