8 gchar *flx_get_host_name(void) {
10 gethostname(t, sizeof(t));
11 return g_strndup(t, sizeof(t));
14 gchar *flx_normalize_name(const gchar *s) {
26 return g_strdup_printf("%s.", s);
29 gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) {
33 if (a->tv_sec < b->tv_sec)
36 if (a->tv_sec > b->tv_sec)
39 if (a->tv_usec < b->tv_usec)
42 if (a->tv_usec > b->tv_usec)
48 glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) {
51 g_assert(flx_timeval_compare(a, b) >= 0);
53 return (a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
57 gint flx_set_cloexec(gint fd) {
62 if ((n = fcntl(fd, F_GETFD)) < 0)
68 return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
71 gint flx_set_nonblock(gint fd) {
76 if ((n = fcntl(fd, F_GETFL)) < 0)
82 return fcntl(fd, F_SETFL, n|O_NONBLOCK);
85 gint flx_wait_for_write(gint fd) {
92 if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0) {
93 g_message("select() failed: %s", strerror(errno));
103 GTimeVal *flx_elapse_time(GTimeVal *tv, guint msec, guint jitter) {
106 g_get_current_time(tv);
109 g_time_val_add(tv, msec*1000);
112 g_time_val_add(tv, g_random_int_range(0, jitter) * 1000);
117 gint flx_age(const GTimeVal *a) {
122 g_get_current_time(&now);
124 return flx_timeval_diff(&now, a);