XRootD
XrdClOperationTimeout.hh
Go to the documentation of this file.
1 /*
2  * XrdClOperationTimeout.hh
3  *
4  * Created on: 4 Nov 2020
5  * Author: simonm
6  */
7 
8 #ifndef SRC_XRDCL_XRDCLOPERATIONTIMEOUT_HH_
9 #define SRC_XRDCL_XRDCLOPERATIONTIMEOUT_HH_
10 
11 #include <cstdint>
12 #include <ctime>
13 #include <exception>
14 
15 namespace XrdCl
16 {
17  class operation_expired : public std::exception {};
18 
19  class Timeout
20  {
21  public:
22 
23  Timeout(): timeout( 0 ), start( 0 )
24  {
25  }
26 
27  Timeout( uint16_t timeout ): timeout( timeout ), start( time( 0 ) )
28  {
29  }
30 
32  {
33  timeout = to.timeout;
34  start = to.start;
35  return *this;
36  }
37 
38  Timeout( const Timeout &to ) : timeout( to.timeout ), start( to.start )
39  {
40  }
41 
42  operator uint16_t() const
43  {
44  if( !timeout ) return 0;
45  time_t elapsed = time( 0 ) - start;
46  if( timeout < elapsed) throw operation_expired();
47  return timeout - elapsed;
48  }
49 
50  private:
51 
52  uint16_t timeout;
53  time_t start;
54  };
55 
56 }
57 
58 #endif /* SRC_XRDCL_XRDCLOPERATIONTIMEOUT_HH_ */
Timeout(const Timeout &to)
Timeout(uint16_t timeout)
Timeout & operator=(const Timeout &to)
static INT to(const char *buffer)
Definition: XrdZipUtils.hh:91