File indexing completed on 2025-01-18 10:15:36
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef SRC_XRDCL_XRDCLOPERATIONTIMEOUT_HH_
0009 #define SRC_XRDCL_XRDCLOPERATIONTIMEOUT_HH_
0010
0011 #include <cstdint>
0012 #include <ctime>
0013 #include <exception>
0014
0015 namespace XrdCl
0016 {
0017 class operation_expired : public std::exception {};
0018
0019 class Timeout
0020 {
0021 public:
0022
0023 Timeout(): timeout( 0 ), start( 0 )
0024 {
0025 }
0026
0027 Timeout( uint16_t timeout ): timeout( timeout ), start( time( 0 ) )
0028 {
0029 }
0030
0031 Timeout& operator=( const Timeout &to )
0032 {
0033 timeout = to.timeout;
0034 start = to.start;
0035 return *this;
0036 }
0037
0038 Timeout( const Timeout &to ) : timeout( to.timeout ), start( to.start )
0039 {
0040 }
0041
0042 operator uint16_t() const
0043 {
0044 if( !timeout ) return 0;
0045 time_t elapsed = time( 0 ) - start;
0046 if( timeout < elapsed) throw operation_expired();
0047 return timeout - elapsed;
0048 }
0049
0050 private:
0051
0052 uint16_t timeout;
0053 time_t start;
0054 };
0055
0056 }
0057
0058 #endif