0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PollTimeout.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef AsyncComm_PollTimeout_h
28 #define AsyncComm_PollTimeout_h
29 
30 #include "Clock.h"
31 
32 #include <cassert>
33 
34 namespace Hypertable {
35 
38 
44  class PollTimeout {
45 
46  public:
47 
50 
56  assert(std::chrono::operator<=(now, expire));
57  auto diff_usec = expire - now;
58  duration_ts.tv_sec = diff_usec.count() / 1000000;
59  duration_ts.tv_nsec = (diff_usec.count() % 1000000) * 1000;
61  duration_millis = std::chrono::duration_cast<std::chrono::milliseconds>(diff_usec);
62  }
63 
66  void set_indefinite() {
67  ts_ptr = nullptr;
68  duration_millis = std::chrono::milliseconds(-1);
69  }
70 
74  int get_millis() { return duration_millis.count(); }
75 
79  struct timespec *get_timespec() { return ts_ptr; }
80 
81  private:
82 
84  struct timespec *ts_ptr {};
85 
87  struct timespec duration_ts;
88 
90  std::chrono::milliseconds duration_millis {-1};
91  };
92 
94 }
95 
96 #endif // AsyncComm_PollTimeout_h
std::chrono::milliseconds duration_millis
Duration until next timeout in milliseconds.
Definition: PollTimeout.h:90
struct timespec duration_ts
timespec structure holding duration until next timeout
Definition: PollTimeout.h:87
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
Maintains next timeout for event polling loop.
Definition: PollTimeout.h:44
struct timespec * ts_ptr
Pointer to to duration_ts or 0 if indefinite.
Definition: PollTimeout.h:84
void set(ClockT::time_point now, ClockT::time_point expire)
Sets the next timeout.
Definition: PollTimeout.h:55
Declaration of ClockT.
int get_millis()
Gets duration until next timeout in the form of milliseconds.
Definition: PollTimeout.h:74
PollTimeout()
Constructor.
Definition: PollTimeout.h:49
Hypertable definitions
void set_indefinite()
Sets the next timeout to be an indefinite time in the future.
Definition: PollTimeout.h:66
struct timespec * get_timespec()
Gets duration until next timeout in the form of a pointer to timespec.
Definition: PollTimeout.h:79