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_SRC_HELPER_REQUEST_H 10 #define _SQUID_SRC_HELPER_REQUEST_H 11 12 #include "helper/forward.h" 13 #include "SquidTime.h" 14 15 namespace Helper 16 { 17 18 class Request 19 { 20 MEMPROXY_CLASS(Helper::Request); 21 22 public: Request(HLPCB * c,void * d,const char * b)23 Request(HLPCB *c, void *d, const char *b) : 24 buf(b ? xstrdup(b) : NULL), 25 callback(c), 26 data(cbdataReference(d)), 27 placeholder(b == NULL), 28 Id(0), 29 retries(0) 30 { 31 memset(&dispatch_time, 0, sizeof(dispatch_time)); 32 } 33 ~Request()34 ~Request() { 35 cbdataReferenceDone(data); 36 xfree(buf); 37 } 38 39 char *buf; 40 HLPCB *callback; 41 void *data; 42 43 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */ 44 struct timeval dispatch_time; 45 uint64_t Id; 46 /** 47 * A helper may configured to retry timed out requests or on BH replies. 48 * We attempt to recover by trying the lookup again, but limit the 49 * number of retries to prevent lag and lockups. 50 * This tracks the number of previous failures for the request. 51 */ 52 int retries; timedOut(time_t timeout)53 bool timedOut(time_t timeout) {return (squid_curtime - dispatch_time.tv_sec) > timeout;} 54 }; 55 56 } // namespace Helper 57 58 #endif /* _SQUID_SRC_HELPER_REQUEST_H */ 59 60