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