]> git.ipfire.org Git - thirdparty/squid.git/blob - src/error/SysErrorDetail.h
Detail client closures of CONNECT tunnels during TLS handshake (#691)
[thirdparty/squid.git] / src / error / SysErrorDetail.h
1 /*
2 * Copyright (C) 1996-2020 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_ERROR_SYSERRORDETAIL_H
10 #define _SQUID_SRC_ERROR_SYSERRORDETAIL_H
11
12 #include "error/Detail.h"
13 #include "sbuf/SBuf.h"
14 #include "sbuf/Stream.h"
15
16 /// system call failure detail based on standard errno(3)/strerror(3) APIs
17 class SysErrorDetail: public ErrorDetail
18 {
19 MEMPROXY_CLASS(SysErrorDetail);
20
21 public:
22 /// \returns a pointer to a SysErrorDetail instance (or nil for lost errnos)
23 static ErrorDetail::Pointer NewIfAny(const int errorNo)
24 {
25 // we could optimize by caching results for (frequently used?) errnos
26 return errorNo ? new SysErrorDetail(errorNo) : nullptr;
27 }
28
29 static SBuf Brief(int errorNo) {
30 return SysErrorDetail(errorNo).brief();
31 }
32
33 /* ErrorDetail API */
34 virtual SBuf brief() const override {
35 return ToSBuf("errno=", errorNo);
36 }
37
38 virtual SBuf verbose(const HttpRequestPointer &) const override {
39 return SBuf(strerror(errorNo));
40 }
41
42 private:
43 // hidden by NewIfAny() to avoid creating SysErrorDetail from zero errno
44 explicit SysErrorDetail(const int anErrorNo): errorNo(anErrorNo) {}
45
46 int errorNo; ///< errno(3) set by the last failed system call or equivalent
47 };
48
49 #endif /* _SQUID_SRC_ERROR_SYSERRORDETAIL_H */
50