コード例 #1
0
uint32_t roadmap_time_get_millis(void) {
   struct timeval tv;

   gettimeofday(&tv, NULL);
   return tv_to_msec(&tv);

}
コード例 #2
0
ファイル: epoll_wait_call.cpp プロジェクト: AlexeyAB/libvma
bool epoll_wait_call::wait(const timeval &elapsed)
{
	int timeout;

	if (m_timeout < 0) {
		timeout = m_timeout;
	} else {
		timeout = m_timeout - tv_to_msec(&elapsed);
		if (timeout < 0) {
			// Already reached timeout
			return false;
		}
	}

	return _wait(timeout);
}
コード例 #3
0
ファイル: test_oom.c プロジェクト: 1234max/tor
/** Run unit tests for buffers.c */
static void
test_oom_streambuf(void *arg)
{
  or_options_t *options = get_options_mutable();
  circuit_t *c1 = NULL, *c2 = NULL, *c3 = NULL, *c4 = NULL, *c5 = NULL;
  struct timeval tv = { 1389641159, 0 };
  uint32_t tvms;
  int i;
  smartlist_t *edgeconns = smartlist_new();

  (void) arg;

  MOCK(circuit_mark_for_close_, circuit_mark_for_close_dummy_);

  /* Far too low for real life. */
  options->MaxMemInQueues = 81*packed_cell_mem_cost() + 4096 * 34;
  options->CellStatistics = 0;

  tt_int_op(cell_queues_check_size(), OP_EQ, 0); /* We don't start out OOM. */
  tt_int_op(cell_queues_get_total_allocation(), OP_EQ, 0);
  tt_int_op(buf_get_total_allocation(), OP_EQ, 0);

  /* Start all circuits with a bit of data queued in cells */
  tv.tv_usec = 500*1000; /* go halfway into the second. */
  tor_gettimeofday_cache_set(&tv);
  c1 = dummy_or_circuit_new(10,10);
  tv.tv_usec = 510*1000;
  tor_gettimeofday_cache_set(&tv);
  c2 = dummy_origin_circuit_new(20);
  tv.tv_usec = 520*1000;
  tor_gettimeofday_cache_set(&tv);
  c3 = dummy_or_circuit_new(20,20);
  tv.tv_usec = 530*1000;
  tor_gettimeofday_cache_set(&tv);
  c4 = dummy_or_circuit_new(0,0);
  tt_int_op(cell_queues_get_total_allocation(), OP_EQ,
            packed_cell_mem_cost() * 80);

  tv.tv_usec = 600*1000;
  tor_gettimeofday_cache_set(&tv);

  /* Add some connections to c1...c4. */
  for (i = 0; i < 4; ++i) {
    edge_connection_t *ec;
    /* link it to a circuit */
    tv.tv_usec += 10*1000;
    tor_gettimeofday_cache_set(&tv);
    ec = dummy_edge_conn_new(c1, CONN_TYPE_EXIT, 1000, 1000);
    tt_assert(ec);
    smartlist_add(edgeconns, ec);
    tv.tv_usec += 10*1000;
    tor_gettimeofday_cache_set(&tv);
    ec = dummy_edge_conn_new(c2, CONN_TYPE_AP, 1000, 1000);
    tt_assert(ec);
    smartlist_add(edgeconns, ec);
    tv.tv_usec += 10*1000;
    tor_gettimeofday_cache_set(&tv);
    ec = dummy_edge_conn_new(c4, CONN_TYPE_EXIT, 1000, 1000); /* Yes, 4 twice*/
    tt_assert(ec);
    smartlist_add(edgeconns, ec);
    tv.tv_usec += 10*1000;
    tor_gettimeofday_cache_set(&tv);
    ec = dummy_edge_conn_new(c4, CONN_TYPE_EXIT, 1000, 1000);
    smartlist_add(edgeconns, ec);
    tt_assert(ec);
  }

  tv.tv_sec += 1;
  tv.tv_usec = 0;
  tvms = (uint32_t) tv_to_msec(&tv);

  tt_int_op(circuit_max_queued_cell_age(c1, tvms), OP_EQ, 500);
  tt_int_op(circuit_max_queued_cell_age(c2, tvms), OP_EQ, 490);
  tt_int_op(circuit_max_queued_cell_age(c3, tvms), OP_EQ, 480);
  tt_int_op(circuit_max_queued_cell_age(c4, tvms), OP_EQ, 0);

  tt_int_op(circuit_max_queued_data_age(c1, tvms), OP_EQ, 390);
  tt_int_op(circuit_max_queued_data_age(c2, tvms), OP_EQ, 380);
  tt_int_op(circuit_max_queued_data_age(c3, tvms), OP_EQ, 0);
  tt_int_op(circuit_max_queued_data_age(c4, tvms), OP_EQ, 370);

  tt_int_op(circuit_max_queued_item_age(c1, tvms), OP_EQ, 500);
  tt_int_op(circuit_max_queued_item_age(c2, tvms), OP_EQ, 490);
  tt_int_op(circuit_max_queued_item_age(c3, tvms), OP_EQ, 480);
  tt_int_op(circuit_max_queued_item_age(c4, tvms), OP_EQ, 370);

  tt_int_op(cell_queues_get_total_allocation(), OP_EQ,
            packed_cell_mem_cost() * 80);
  tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*16*2);

  /* Now give c4 a very old buffer of modest size */
  {
    edge_connection_t *ec;
    tv.tv_sec -= 1;
    tv.tv_usec = 0;
    tor_gettimeofday_cache_set(&tv);
    ec = dummy_edge_conn_new(c4, CONN_TYPE_EXIT, 1000, 1000);
    tt_assert(ec);
    smartlist_add(edgeconns, ec);
  }
  tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*17*2);
  tt_int_op(circuit_max_queued_item_age(c4, tvms), OP_EQ, 1000);

  tt_int_op(cell_queues_check_size(), OP_EQ, 0);

  /* And run over the limit. */
  tv.tv_usec = 800*1000;
  tor_gettimeofday_cache_set(&tv);
  c5 = dummy_or_circuit_new(0,5);

  tt_int_op(cell_queues_get_total_allocation(), OP_EQ,
            packed_cell_mem_cost() * 85);
  tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*17*2);

  tt_int_op(cell_queues_check_size(), OP_EQ, 1); /* We are now OOM */

  /* C4 should have died. */
  tt_assert(! c1->marked_for_close);
  tt_assert(! c2->marked_for_close);
  tt_assert(! c3->marked_for_close);
  tt_assert(c4->marked_for_close);
  tt_assert(! c5->marked_for_close);

  tt_int_op(cell_queues_get_total_allocation(), OP_EQ,
            packed_cell_mem_cost() * 85);
  tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*8*2);

 done:
  circuit_free(c1);
  circuit_free(c2);
  circuit_free(c3);
  circuit_free(c4);
  circuit_free(c5);

  SMARTLIST_FOREACH(edgeconns, edge_connection_t *, ec,
                    connection_free_(TO_CONN(ec)));
  smartlist_free(edgeconns);

  UNMOCK(circuit_mark_for_close_);
}
コード例 #4
0
ファイル: epoll_wait_call.cpp プロジェクト: AlexeyAB/libvma
bool epoll_wait_call::is_timeout(const timeval &elapsed)
{
	return m_timeout >= 0 && m_timeout <= tv_to_msec(&elapsed);
}