LCOV - code coverage report
Current view: top level - source/common/network - io_socket_error_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 6 7 85.7 %
Date: 2024-01-05 06:35:25 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/api/io_error.h"
       4             : 
       5             : #include "source/common/common/assert.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Network {
       9             : 
      10             : class IoSocketError : public Api::IoError {
      11             : public:
      12             :   static Api::IoErrorPtr create(int sys_errno);
      13          88 :   ~IoSocketError() override = default;
      14             : 
      15             :   Api::IoError::IoErrorCode getErrorCode() const override;
      16             :   std::string getErrorDetails() const override;
      17           0 :   int getSystemErrorCode() const override { return errno_; }
      18             : 
      19             :   // IoErrorCode::Again is used frequently. This custom error returns a
      20             :   // reusable singleton to avoid repeated allocation.
      21             :   static Api::IoErrorPtr getIoSocketEagainError();
      22             :   static Api::IoErrorPtr getIoSocketEbadfError();
      23             : 
      24             :   // This error is introduced when Envoy create socket for unsupported address. It is either a bug,
      25             :   // or this Envoy instance received config which is not yet supported. This should not be fatal
      26             :   // error.
      27             :   static Api::IoCallUint64Result ioResultSocketInvalidAddress();
      28             : 
      29             : private:
      30             :   explicit IoSocketError(int sys_errno)
      31          88 :       : errno_(sys_errno), error_code_(errorCodeFromErrno(errno_)) {
      32          88 :     ASSERT(error_code_ != IoErrorCode::Again,
      33          88 :            "Didn't use getIoSocketEagainError() to generate `Again`.");
      34          88 :   }
      35             :   explicit IoSocketError(int sys_errno, Api::IoError::IoErrorCode error_code)
      36          13 :       : errno_(sys_errno), error_code_(error_code) {}
      37             : 
      38             :   static Api::IoError::IoErrorCode errorCodeFromErrno(int sys_errno);
      39             : 
      40             :   static Api::IoErrorPtr getIoSocketInvalidAddressError();
      41             : 
      42             :   const int errno_;
      43             :   const Api::IoError::IoErrorCode error_code_;
      44             : };
      45             : 
      46             : } // namespace Network
      47             : } // namespace Envoy

Generated by: LCOV version 1.15