struct rconn *rc = xcalloc(1, sizeof *rc);
rc->state = S_VOID;
- rc->state_entered = time(0);
+ rc->state_entered = time_now();
rc->vconn = NULL;
rc->name = xstrdup("void");
rc->backoff = 0;
rc->max_backoff = max_backoff ? max_backoff : 60;
rc->backoff_deadline = TIME_MIN;
- rc->last_received = time(0);
- rc->last_connected = time(0);
+ rc->last_received = time_now();
+ rc->last_connected = time_now();
rc->packets_sent = 0;
rc->questionable_connectivity = false;
- rc->last_questioned = time(0);
+ rc->last_questioned = time_now();
rc->probe_interval = probe_interval ? MAX(5, probe_interval) : 0;
rc->name = xstrdup(name);
rc->reliable = false;
rc->vconn = vconn;
- rc->last_connected = time(0);
+ rc->last_connected = time_now();
state_transition(rc, S_ACTIVE);
}
VLOG_WARN("%s: connecting...", rc->name);
retval = vconn_open(rc->name, &rc->vconn);
if (!retval) {
- rc->backoff_deadline = time(0) + rc->backoff;
+ rc->backoff_deadline = time_now() + rc->backoff;
state_transition(rc, S_CONNECTING);
} else {
VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval));
unsigned int base = MAX(rc->last_received, rc->state_entered);
queue_push_tail(&rc->txq, make_echo_request());
VLOG_DBG("%s: idle %u seconds, sending inactivity probe",
- rc->name, (unsigned int) (time(0) - base));
+ rc->name, (unsigned int) (time_now() - base));
state_transition(rc, S_IDLE);
return;
}
struct buffer *buffer;
int error = vconn_recv(rc->vconn, &buffer);
if (!error) {
- rc->last_received = time(0);
+ rc->last_received = time_now();
if (rc->state == S_IDLE) {
state_transition(rc, S_ACTIVE);
}
int
rconn_disconnected_duration(const struct rconn *rconn)
{
- return rconn_is_connected(rconn) ? 0 : time(0) - rconn->last_received;
+ return rconn_is_connected(rconn) ? 0 : time_now() - rconn->last_received;
}
/* Returns the IP address of the peer, or 0 if the peer is not connected over
disconnect(struct rconn *rc, int error)
{
if (rc->reliable) {
- time_t now = time(0);
+ time_t now = time_now();
if (rc->state & (S_CONNECTING | S_ACTIVE | S_IDLE)) {
if (error > 0) {
static unsigned int
elapsed_in_this_state(const struct rconn *rc)
{
- return time(0) - rc->state_entered;
+ return time_now() - rc->state_entered;
}
static unsigned int
static bool
timed_out(const struct rconn *rc)
{
- return time(0) >= sat_add(rc->state_entered, timeout(rc));
+ return time_now() >= sat_add(rc->state_entered, timeout(rc));
}
static void
{
VLOG_DBG("%s: entering %s", rc->name, state_name(state));
rc->state = state;
- rc->state_entered = time(0);
+ rc->state_entered = time_now();
}
static unsigned int
static void
question_connectivity(struct rconn *rc)
{
- time_t now = time(0);
+ time_t now = time_now();
if (now - rc->last_questioned > 60) {
rc->questionable_connectivity = true;
rc->last_questioned = now;