1 /* 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors 3 * 4 * Squid software is distributed under GPLv2+ license and includes 5 * contributions from numerous individuals and organizations. 6 * Please see the COPYING and CONTRIBUTORS files for details. 7 */ 8 9 #ifndef _SQUID_COMM_IOCALLBACK_H 10 #define _SQUID_COMM_IOCALLBACK_H 11 12 #include "base/AsyncCall.h" 13 #include "comm/Flag.h" 14 #include "comm/forward.h" 15 #include "mem/forward.h" 16 #include "sbuf/forward.h" 17 18 namespace Comm 19 { 20 21 /// Type of IO callbacks the Comm layer deals with. 22 typedef enum { 23 IOCB_NONE, 24 IOCB_READ, 25 IOCB_WRITE 26 } iocb_type; 27 28 /// Details about a particular Comm IO callback event. 29 class IoCallback 30 { 31 public: 32 iocb_type type; 33 Comm::ConnectionPointer conn; 34 AsyncCall::Pointer callback; 35 char *buf; 36 FREE *freefunc; 37 int size; 38 int offset; 39 Comm::Flag errcode; 40 int xerrno; 41 #if USE_DELAY_POOLS 42 unsigned int quotaQueueReserv; ///< reservation ID from CommQuotaQueue 43 #endif 44 active()45 bool active() const { return callback != NULL; } 46 void setCallback(iocb_type type, AsyncCall::Pointer &cb, char *buf, FREE *func, int sz); 47 48 /// called when fd needs to write but may need to wait in line for its quota 49 void selectOrQueueWrite(); 50 51 /// Actively cancel the given callback 52 void cancel(const char *reason); 53 54 /// finish the IO operation imediately and schedule the callback with the current state. 55 void finish(Comm::Flag code, int xerrn); 56 57 private: 58 void reset(); 59 }; 60 61 /// Entry nodes for the IO callback table: iocb_table 62 /// Keyed off the FD which the event applies to. 63 class CbEntry 64 { 65 public: 66 int fd; 67 IoCallback readcb; 68 IoCallback writecb; 69 }; 70 71 /// Table of scheduled IO events which have yet to be processed ?? 72 /// Callbacks which might be scheduled in future are stored in fd_table. 73 extern CbEntry *iocb_table; 74 75 void CallbackTableInit(); 76 void CallbackTableDestruct(); 77 78 #define COMMIO_FD_READCB(fd) (&Comm::iocb_table[(fd)].readcb) 79 #define COMMIO_FD_WRITECB(fd) (&Comm::iocb_table[(fd)].writecb) 80 81 } // namespace Comm 82 83 #endif /* _SQUID_COMM_IOCALLBACK_H */ 84 85