compat_libevent.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /* Copyright (c) 2009-2011, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file compat_libevent.c
  5. * \brief Wrappers to handle porting between different versions of libevent.
  6. *
  7. * In an ideal world, we'd just use Libevent 2.0 from now on. But as of June
  8. * 2009, Libevent 2.0 is still in alpha, and we will have old versions of
  9. * Libevent for the forseeable future.
  10. **/
  11. #include "orconfig.h"
  12. #include "compat.h"
  13. #include "compat_libevent.h"
  14. #include "util.h"
  15. #include "torlog.h"
  16. #ifdef HAVE_EVENT2_EVENT_H
  17. #include <event2/event.h>
  18. #else
  19. #include <event.h>
  20. #endif
  21. /** A number representing a version of Libevent.
  22. This is a 4-byte number, with the first three bytes representing the
  23. major, minor, and patchlevel respectively of the library. The fourth
  24. byte is unused.
  25. This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
  26. 2.0.1 or later. For versions of Libevent before 1.4.0, which followed the
  27. format of "1.0, 1.0a, 1.0b", we define 1.0 to be equivalent to 1.0.0, 1.0a
  28. to be equivalent to 1.0.1, and so on.
  29. */
  30. typedef uint32_t le_version_t;
  31. /** @{ */
  32. /** Macros: returns the number of a libevent version as a le_version_t */
  33. #define V(major, minor, patch) \
  34. (((major) << 24) | ((minor) << 16) | ((patch) << 8))
  35. #define V_OLD(major, minor, patch) \
  36. V((major), (minor), (patch)-'a'+1)
  37. /** @} */
  38. /** Represetns a version of libevent so old we can't figure out what version
  39. * it is. */
  40. #define LE_OLD V(0,0,0)
  41. /** Represents a version of libevent so weird we can't figure out what version
  42. * it is. */
  43. #define LE_OTHER V(0,0,99)
  44. static le_version_t tor_get_libevent_version(const char **v_out);
  45. #ifdef HAVE_EVENT_SET_LOG_CALLBACK
  46. /** A string which, if it appears in a libevent log, should be ignored. */
  47. static const char *suppress_msg = NULL;
  48. /** Callback function passed to event_set_log() so we can intercept
  49. * log messages from libevent. */
  50. static void
  51. libevent_logging_callback(int severity, const char *msg)
  52. {
  53. char buf[1024];
  54. size_t n;
  55. if (suppress_msg && strstr(msg, suppress_msg))
  56. return;
  57. n = strlcpy(buf, msg, sizeof(buf));
  58. if (n && n < sizeof(buf) && buf[n-1] == '\n') {
  59. buf[n-1] = '\0';
  60. }
  61. switch (severity) {
  62. case _EVENT_LOG_DEBUG:
  63. log(LOG_DEBUG, LD_NOCB|LD_NET, "Message from libevent: %s", buf);
  64. break;
  65. case _EVENT_LOG_MSG:
  66. log(LOG_INFO, LD_NOCB|LD_NET, "Message from libevent: %s", buf);
  67. break;
  68. case _EVENT_LOG_WARN:
  69. log(LOG_WARN, LD_NOCB|LD_GENERAL, "Warning from libevent: %s", buf);
  70. break;
  71. case _EVENT_LOG_ERR:
  72. log(LOG_ERR, LD_NOCB|LD_GENERAL, "Error from libevent: %s", buf);
  73. break;
  74. default:
  75. log(LOG_WARN, LD_NOCB|LD_GENERAL, "Message [%d] from libevent: %s",
  76. severity, buf);
  77. break;
  78. }
  79. }
  80. /** Set hook to intercept log messages from libevent. */
  81. void
  82. configure_libevent_logging(void)
  83. {
  84. event_set_log_callback(libevent_logging_callback);
  85. }
  86. /** Ignore any libevent log message that contains <b>msg</b>. */
  87. void
  88. suppress_libevent_log_msg(const char *msg)
  89. {
  90. suppress_msg = msg;
  91. }
  92. #else
  93. void
  94. configure_libevent_logging(void)
  95. {
  96. }
  97. void
  98. suppress_libevent_log_msg(const char *msg)
  99. {
  100. (void)msg;
  101. }
  102. #endif
  103. #ifndef HAVE_EVENT2_EVENT_H
  104. /** Work-alike replacement for event_new() on pre-Libevent-2.0 systems. */
  105. struct event *
  106. tor_event_new(struct event_base *base, int sock, short what,
  107. void (*cb)(int, short, void *), void *arg)
  108. {
  109. struct event *e = tor_malloc_zero(sizeof(struct event));
  110. event_set(e, sock, what, cb, arg);
  111. if (! base)
  112. base = tor_libevent_get_base();
  113. event_base_set(base, e);
  114. return e;
  115. }
  116. /** Work-alike replacement for evtimer_new() on pre-Libevent-2.0 systems. */
  117. struct event *
  118. tor_evtimer_new(struct event_base *base,
  119. void (*cb)(int, short, void *), void *arg)
  120. {
  121. return tor_event_new(base, -1, 0, cb, arg);
  122. }
  123. /** Work-alike replacement for evsignal_new() on pre-Libevent-2.0 systems. */
  124. struct event *
  125. tor_evsignal_new(struct event_base * base, int sig,
  126. void (*cb)(int, short, void *), void *arg)
  127. {
  128. return tor_event_new(base, sig, EV_SIGNAL|EV_PERSIST, cb, arg);
  129. }
  130. /** Work-alike replacement for event_free() on pre-Libevent-2.0 systems. */
  131. void
  132. tor_event_free(struct event *ev)
  133. {
  134. event_del(ev);
  135. tor_free(ev);
  136. }
  137. #endif
  138. /** Global event base for use by the main thread. */
  139. struct event_base *the_event_base = NULL;
  140. /* This is what passes for version detection on OSX. We set
  141. * MACOSX_KQUEUE_IS_BROKEN to true iff we're on a version of OSX before
  142. * 10.4.0 (aka 1040). */
  143. #ifdef __APPLE__
  144. #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
  145. #define MACOSX_KQUEUE_IS_BROKEN \
  146. (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1040)
  147. #else
  148. #define MACOSX_KQUEUE_IS_BROKEN 0
  149. #endif
  150. #endif
  151. /** Initialize the Libevent library and set up the event base. */
  152. void
  153. tor_libevent_initialize(tor_libevent_cfg *torcfg)
  154. {
  155. tor_assert(the_event_base == NULL);
  156. /* some paths below don't use torcfg, so avoid unused variable warnings */
  157. (void)torcfg;
  158. #ifdef __APPLE__
  159. if (MACOSX_KQUEUE_IS_BROKEN ||
  160. tor_get_libevent_version(NULL) < V_OLD(1,1,'b')) {
  161. setenv("EVENT_NOKQUEUE","1",1);
  162. }
  163. #endif
  164. #ifdef HAVE_EVENT2_EVENT_H
  165. {
  166. struct event_config *cfg = event_config_new();
  167. #if defined(MS_WINDOWS) && defined(USE_BUFFEREVENTS)
  168. if (! torcfg->disable_iocp)
  169. event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP);
  170. #endif
  171. #if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= V(2,0,7)
  172. if (torcfg->num_cpus > 0)
  173. event_config_set_num_cpus_hint(cfg, torcfg->num_cpus);
  174. #endif
  175. #if LIBEVENT_VERSION_NUMBER >= V(2,0,9)
  176. /* We can enable changelist support with epoll, since we don't give
  177. * Libevent any dup'd fds. This lets us avoid some syscalls. */
  178. event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
  179. #endif
  180. the_event_base = event_base_new_with_config(cfg);
  181. event_config_free(cfg);
  182. }
  183. #else
  184. the_event_base = event_init();
  185. #endif
  186. #if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD)
  187. /* Making this a NOTICE for now so we can link bugs to a libevent versions
  188. * or methods better. */
  189. log(LOG_NOTICE, LD_GENERAL,
  190. "Initialized libevent version %s using method %s. Good.",
  191. event_get_version(), tor_libevent_get_method());
  192. #else
  193. log(LOG_NOTICE, LD_GENERAL,
  194. "Initialized old libevent (version 1.0b or earlier).");
  195. log(LOG_WARN, LD_GENERAL,
  196. "You have a *VERY* old version of libevent. It is likely to be buggy; "
  197. "please build Tor with a more recent version.");
  198. #endif
  199. }
  200. /** Return the current Libevent event base that we're set up to use. */
  201. struct event_base *
  202. tor_libevent_get_base(void)
  203. {
  204. return the_event_base;
  205. }
  206. #ifndef HAVE_EVENT_BASE_LOOPEXIT
  207. /** Replacement for event_base_loopexit on some very old versions of Libevent
  208. * that we are not yet brave enough to deprecate. */
  209. int
  210. tor_event_base_loopexit(struct event_base *base, struct timeval *tv)
  211. {
  212. tor_assert(base == the_event_base);
  213. return event_loopexit(tv);
  214. }
  215. #endif
  216. /** Return the name of the Libevent backend we're using. */
  217. const char *
  218. tor_libevent_get_method(void)
  219. {
  220. #ifdef HAVE_EVENT2_EVENT_H
  221. return event_base_get_method(the_event_base);
  222. #elif defined(HAVE_EVENT_GET_METHOD)
  223. return event_get_method();
  224. #else
  225. return "<unknown>";
  226. #endif
  227. }
  228. /** Return the le_version_t for the version of libevent specified in the
  229. * string <b>v</b>. If the version is very new or uses an unrecognized
  230. * version, format, return LE_OTHER. */
  231. static le_version_t
  232. tor_decode_libevent_version(const char *v)
  233. {
  234. unsigned major, minor, patchlevel;
  235. char c, e, extra;
  236. int fields;
  237. /* Try the new preferred "1.4.11-stable" format.
  238. * Also accept "1.4.14b-stable". */
  239. fields = tor_sscanf(v, "%u.%u.%u%c%c", &major, &minor, &patchlevel, &c, &e);
  240. if (fields == 3 ||
  241. ((fields == 4 || fields == 5 ) && (c == '-' || c == '_')) ||
  242. (fields == 5 && TOR_ISALPHA(c) && (e == '-' || e == '_'))) {
  243. return V(major,minor,patchlevel);
  244. }
  245. /* Try the old "1.3e" format. */
  246. fields = tor_sscanf(v, "%u.%u%c%c", &major, &minor, &c, &extra);
  247. if (fields == 3 && TOR_ISALPHA(c)) {
  248. return V_OLD(major, minor, c);
  249. } else if (fields == 2) {
  250. return V(major, minor, 0);
  251. }
  252. return LE_OTHER;
  253. }
  254. /** Return an integer representing the binary interface of a Libevent library.
  255. * Two different versions with different numbers are sure not to be binary
  256. * compatible. Two different versions with the same numbers have a decent
  257. * chance of binary compatibility.*/
  258. static int
  259. le_versions_compatibility(le_version_t v)
  260. {
  261. if (v == LE_OTHER)
  262. return 0;
  263. if (v < V_OLD(1,0,'c'))
  264. return 1;
  265. else if (v < V(1,4,0))
  266. return 2;
  267. else if (v < V(1,4,99))
  268. return 3;
  269. else if (v < V(2,0,1))
  270. return 4;
  271. else /* Everything 2.0 and later should be compatible. */
  272. return 5;
  273. }
  274. /** Return the version number of the currently running version of Libevent.
  275. * See le_version_t for info on the format.
  276. */
  277. static le_version_t
  278. tor_get_libevent_version(const char **v_out)
  279. {
  280. const char *v;
  281. le_version_t r;
  282. #if defined(HAVE_EVENT_GET_VERSION_NUMBER)
  283. v = event_get_version();
  284. r = event_get_version_number();
  285. #elif defined (HAVE_EVENT_GET_VERSION)
  286. v = event_get_version();
  287. r = tor_decode_libevent_version(v);
  288. #else
  289. v = "pre-1.0c";
  290. r = LE_OLD;
  291. #endif
  292. if (v_out)
  293. *v_out = v;
  294. return r;
  295. }
  296. /** Return a string representation of the version of the currently running
  297. * version of Libevent. */
  298. const char *
  299. tor_libevent_get_version_str(void)
  300. {
  301. #ifdef HAVE_EVENT_GET_VERSION
  302. return event_get_version();
  303. #else
  304. return "pre-1.0c";
  305. #endif
  306. }
  307. /**
  308. * Compare the current Libevent method and version to a list of versions
  309. * which are known not to work. Warn the user as appropriate.
  310. */
  311. void
  312. tor_check_libevent_version(const char *m, int server,
  313. const char **badness_out)
  314. {
  315. int buggy = 0, iffy = 0, slow = 0, thread_unsafe = 0;
  316. le_version_t version;
  317. const char *v = NULL;
  318. const char *badness = NULL;
  319. const char *sad_os = "";
  320. version = tor_get_libevent_version(&v);
  321. /* It would be better to disable known-buggy methods rather than warning
  322. * about them. But the problem is that with older versions of Libevent,
  323. * it's not trivial to get them to change their methods once they're
  324. * initialized... and with newer versions of Libevent, they aren't actually
  325. * broken. But we should revisit this if we ever find a post-1.4 version
  326. * of Libevent where we need to disable a given method. */
  327. if (!strcmp(m, "kqueue")) {
  328. if (version < V_OLD(1,1,'b'))
  329. buggy = 1;
  330. } else if (!strcmp(m, "epoll")) {
  331. if (version < V(1,1,0))
  332. iffy = 1;
  333. } else if (!strcmp(m, "poll")) {
  334. if (version < V_OLD(1,0,'e'))
  335. buggy = 1;
  336. if (version < V(1,1,0))
  337. slow = 1;
  338. } else if (!strcmp(m, "select")) {
  339. if (version < V(1,1,0))
  340. slow = 1;
  341. } else if (!strcmp(m, "win32")) {
  342. if (version < V_OLD(1,1,'b'))
  343. buggy = 1;
  344. }
  345. /* Libevent versions before 1.3b do very badly on operating systems with
  346. * user-space threading implementations. */
  347. #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
  348. if (server && version < V_OLD(1,3,'b')) {
  349. thread_unsafe = 1;
  350. sad_os = "BSD variants";
  351. }
  352. #elif defined(__APPLE__) || defined(__darwin__)
  353. if (server && version < V_OLD(1,3,'b')) {
  354. thread_unsafe = 1;
  355. sad_os = "Mac OS X";
  356. }
  357. #endif
  358. if (thread_unsafe) {
  359. log(LOG_WARN, LD_GENERAL,
  360. "Libevent version %s often crashes when running a Tor server with %s. "
  361. "Please use the latest version of libevent (1.3b or later)",v,sad_os);
  362. badness = "BROKEN";
  363. } else if (buggy) {
  364. log(LOG_WARN, LD_GENERAL,
  365. "There are serious bugs in using %s with libevent %s. "
  366. "Please use the latest version of libevent.", m, v);
  367. badness = "BROKEN";
  368. } else if (iffy) {
  369. log(LOG_WARN, LD_GENERAL,
  370. "There are minor bugs in using %s with libevent %s. "
  371. "You may want to use the latest version of libevent.", m, v);
  372. badness = "BUGGY";
  373. } else if (slow && server) {
  374. log(LOG_WARN, LD_GENERAL,
  375. "libevent %s can be very slow with %s. "
  376. "When running a server, please use the latest version of libevent.",
  377. v,m);
  378. badness = "SLOW";
  379. }
  380. *badness_out = badness;
  381. }
  382. #if defined(LIBEVENT_VERSION)
  383. #define HEADER_VERSION LIBEVENT_VERSION
  384. #elif defined(_EVENT_VERSION)
  385. #define HEADER_VERSION _EVENT_VERSION
  386. #endif
  387. /** See whether the headers we were built against differ from the library we
  388. * linked against so much that we're likely to crash. If so, warn the
  389. * user. */
  390. void
  391. tor_check_libevent_header_compatibility(void)
  392. {
  393. (void) le_versions_compatibility;
  394. (void) tor_decode_libevent_version;
  395. /* In libevent versions before 2.0, it's hard to keep binary compatibility
  396. * between upgrades, and unpleasant to detect when the version we compiled
  397. * against is unlike the version we have linked against. Here's how. */
  398. #if defined(HEADER_VERSION) && defined(HAVE_EVENT_GET_VERSION)
  399. /* We have a header-file version and a function-call version. Easy. */
  400. if (strcmp(HEADER_VERSION, event_get_version())) {
  401. le_version_t v1, v2;
  402. int compat1 = -1, compat2 = -1;
  403. int verybad;
  404. v1 = tor_decode_libevent_version(HEADER_VERSION);
  405. v2 = tor_decode_libevent_version(event_get_version());
  406. compat1 = le_versions_compatibility(v1);
  407. compat2 = le_versions_compatibility(v2);
  408. verybad = compat1 != compat2;
  409. log(verybad ? LOG_WARN : LOG_NOTICE,
  410. LD_GENERAL, "We were compiled with headers from version %s "
  411. "of Libevent, but we're using a Libevent library that says it's "
  412. "version %s.", HEADER_VERSION, event_get_version());
  413. if (verybad)
  414. log_warn(LD_GENERAL, "This will almost certainly make Tor crash.");
  415. else
  416. log_info(LD_GENERAL, "I think these versions are binary-compatible.");
  417. }
  418. #elif defined(HAVE_EVENT_GET_VERSION)
  419. /* event_get_version but no _EVENT_VERSION. We might be in 1.4.0-beta or
  420. earlier, where that's normal. To see whether we were compiled with an
  421. earlier version, let's see whether the struct event defines MIN_HEAP_IDX.
  422. */
  423. #ifdef HAVE_STRUCT_EVENT_MIN_HEAP_IDX
  424. /* The header files are 1.4.0-beta or later. If the version is not
  425. * 1.4.0-beta, we are incompatible. */
  426. {
  427. if (strcmp(event_get_version(), "1.4.0-beta")) {
  428. log_warn(LD_GENERAL, "It's a little hard to tell, but you seem to have "
  429. "Libevent 1.4.0-beta header files, whereas you have linked "
  430. "against Libevent %s. This will probably make Tor crash.",
  431. event_get_version());
  432. }
  433. }
  434. #else
  435. /* Our headers are 1.3e or earlier. If the library version is not 1.4.x or
  436. later, we're probably fine. */
  437. {
  438. const char *v = event_get_version();
  439. if ((v[0] == '1' && v[2] == '.' && v[3] > '3') || v[0] > '1') {
  440. log_warn(LD_GENERAL, "It's a little hard to tell, but you seem to have "
  441. "Libevent header file from 1.3e or earlier, whereas you have "
  442. "linked against Libevent %s. This will probably make Tor "
  443. "crash.", event_get_version());
  444. }
  445. }
  446. #endif
  447. #elif defined(HEADER_VERSION)
  448. #warn "_EVENT_VERSION is defined but not get_event_version(): Libevent is odd."
  449. #else
  450. /* Your libevent is ancient. */
  451. #endif
  452. }
  453. /*
  454. If possible, we're going to try to use Libevent's periodic timer support,
  455. since it does a pretty good job of making sure that periodic events get
  456. called exactly M seconds apart, rather than starting each one exactly M
  457. seconds after the time that the last one was run.
  458. */
  459. #ifdef HAVE_EVENT2_EVENT_H
  460. #define HAVE_PERIODIC
  461. #define PERIODIC_FLAGS EV_PERSIST
  462. #else
  463. #define PERIODIC_FLAGS 0
  464. #endif
  465. /** Represents a timer that's run every N microseconds by Libevent. */
  466. struct periodic_timer_t {
  467. /** Underlying event used to implement this periodic event. */
  468. struct event *ev;
  469. /** The callback we'll be invoking whenever the event triggers */
  470. void (*cb)(struct periodic_timer_t *, void *);
  471. /** User-supplied data for the callback */
  472. void *data;
  473. #ifndef HAVE_PERIODIC
  474. /** If Libevent doesn't know how to invoke events every N microseconds,
  475. * we'll need to remember the timeout interval here. */
  476. struct timeval tv;
  477. #endif
  478. };
  479. /** Libevent callback to implement a periodic event. */
  480. static void
  481. periodic_timer_cb(evutil_socket_t fd, short what, void *arg)
  482. {
  483. periodic_timer_t *timer = arg;
  484. (void) what;
  485. (void) fd;
  486. #ifndef HAVE_PERIODIC
  487. /** reschedule the event as needed. */
  488. event_add(timer->ev, &timer->tv);
  489. #endif
  490. timer->cb(timer, timer->data);
  491. }
  492. /** Create and schedule a new timer that will run every <b>tv</b> in
  493. * the event loop of <b>base</b>. When the timer fires, it will
  494. * run the timer in <b>cb</b> with the user-supplied data in <b>data</b>. */
  495. periodic_timer_t *
  496. periodic_timer_new(struct event_base *base,
  497. const struct timeval *tv,
  498. void (*cb)(periodic_timer_t *timer, void *data),
  499. void *data)
  500. {
  501. periodic_timer_t *timer;
  502. tor_assert(base);
  503. tor_assert(tv);
  504. tor_assert(cb);
  505. timer = tor_malloc_zero(sizeof(periodic_timer_t));
  506. if (!(timer->ev = tor_event_new(base, -1, PERIODIC_FLAGS,
  507. periodic_timer_cb, timer))) {
  508. tor_free(timer);
  509. return NULL;
  510. }
  511. timer->cb = cb;
  512. timer->data = data;
  513. #ifndef HAVE_PERIODIC
  514. memcpy(&timer->tv, tv, sizeof(struct timeval));
  515. #endif
  516. event_add(timer->ev, (struct timeval *)tv); /*drop const for old libevent*/
  517. return timer;
  518. }
  519. /** Stop and free a periodic timer */
  520. void
  521. periodic_timer_free(periodic_timer_t *timer)
  522. {
  523. if (!timer)
  524. return;
  525. tor_event_free(timer->ev);
  526. tor_free(timer);
  527. }
  528. #ifdef USE_BUFFEREVENTS
  529. static const struct timeval *one_tick = NULL;
  530. /**
  531. * Return a special timeout to be passed whenever libevent's O(1) timeout
  532. * implementation should be used. Only use this when the timer is supposed
  533. * to fire after 1 / TOR_LIBEVENT_TICKS_PER_SECOND seconds have passed.
  534. */
  535. const struct timeval *
  536. tor_libevent_get_one_tick_timeout(void)
  537. {
  538. if (PREDICT_UNLIKELY(one_tick == NULL)) {
  539. struct event_base *base = tor_libevent_get_base();
  540. struct timeval tv;
  541. if (TOR_LIBEVENT_TICKS_PER_SECOND == 1) {
  542. tv.tv_sec = 1;
  543. tv.tv_usec = 0;
  544. } else {
  545. tv.tv_sec = 0;
  546. tv.tv_usec = 1000000 / TOR_LIBEVENT_TICKS_PER_SECOND;
  547. }
  548. one_tick = event_base_init_common_timeout(base, &tv);
  549. }
  550. return one_tick;
  551. }
  552. #endif