1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

Merge pull request #1145 from ailin-nemui/time

remove GTimeVal following glib 2.61.2 deprecation
This commit is contained in:
ailin-nemui 2020-01-08 10:41:08 +01:00 committed by GitHub
commit 363a79dc7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 74 additions and 69 deletions

View File

@ -6,7 +6,7 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
#define IRSSI_ABI_VERSION 24 #define IRSSI_ABI_VERSION 25
#define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697 #define DEFAULT_SERVER_ADD_TLS_PORT 6697

View File

@ -94,8 +94,11 @@ int g_input_add_poll(int fd, int priority, int condition,
return ret; return ret;
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2) int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2)
{ {
#pragma GCC diagnostic pop
if (tv1->tv_sec < tv2->tv_sec) if (tv1->tv_sec < tv2->tv_sec)
return -1; return -1;
if (tv1->tv_sec > tv2->tv_sec) if (tv1->tv_sec > tv2->tv_sec)
@ -105,8 +108,11 @@ int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2)
tv1->tv_usec > tv2->tv_usec ? 1 : 0; tv1->tv_usec > tv2->tv_usec ? 1 : 0;
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2) long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2)
{ {
#pragma GCC diagnostic pop
long secs, usecs; long secs, usecs;
secs = tv1->tv_sec - tv2->tv_sec; secs = tv1->tv_sec - tv2->tv_sec;

View File

@ -11,11 +11,14 @@ int g_input_add_poll(int fd, int priority, int condition,
typedef void* (*FOREACH_FIND_FUNC) (void *item, void *data); typedef void* (*FOREACH_FIND_FUNC) (void *item, void *data);
typedef int (*COLUMN_LEN_FUNC)(void *data); typedef int (*COLUMN_LEN_FUNC)(void *data);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/* Returns 1 if tv1 > tv2, -1 if tv2 > tv1 or 0 if they're equal. */ /* Returns 1 if tv1 > tv2, -1 if tv2 > tv1 or 0 if they're equal. */
int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2); int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2) G_GNUC_DEPRECATED;
/* Returns "tv1 - tv2", returns the result in milliseconds. Note that /* Returns "tv1 - tv2", returns the result in milliseconds. Note that
if the difference is too large, the result might be invalid. */ if the difference is too large, the result might be invalid. */
long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2); long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2) G_GNUC_DEPRECATED;
#pragma GCC diagnostic pop
GSList *gslist_find_string(GSList *list, const char *key); GSList *gslist_find_string(GSList *list, const char *key);
GSList *gslist_find_icase_string(GSList *list, const char *key); GSList *gslist_find_icase_string(GSList *list, const char *key);

View File

@ -37,7 +37,7 @@ unsigned int usermode_away:1;
unsigned int banned:1; /* not allowed to connect to this server */ unsigned int banned:1; /* not allowed to connect to this server */
unsigned int dns_error:1; /* DNS said the host doesn't exist */ unsigned int dns_error:1; /* DNS said the host doesn't exist */
GTimeVal lag_sent; /* 0 or time when last lag query was sent to server */ gint64 lag_sent; /* 0 or time when last lag query was sent to server */
time_t lag_last_check; /* last time we checked lag */ time_t lag_last_check; /* last time we checked lag */
int lag; /* server lag in milliseconds */ int lag; /* server lag in milliseconds */

View File

@ -65,7 +65,7 @@ int command_hide_output;
the line had one or two command chars, and which one.. */ the line had one or two command chars, and which one.. */
static const char *current_cmdline; static const char *current_cmdline;
static GTimeVal time_command_last, time_command_now; static gint64 time_command_last, time_command_now;
static int last_command_cmd, command_cmd; static int last_command_cmd, command_cmd;
/* SYNTAX: ECHO [-window <name>] [-level <level>] <text> */ /* SYNTAX: ECHO [-window <name>] [-level <level>] <text> */
@ -222,7 +222,7 @@ static void event_command(const char *data)
time_command_last = time_command_now; time_command_last = time_command_now;
last_command_cmd = command_cmd; last_command_cmd = command_cmd;
g_get_current_time(&time_command_now); time_command_now = g_get_real_time();
command_cmd = *data != '\0' && command_cmd = *data != '\0' &&
strchr(settings_get_str("cmdchars"), *data) != NULL; strchr(settings_get_str("cmdchars"), *data) != NULL;
@ -271,7 +271,7 @@ static void event_default_command(const char *data, void *server,
/* maybe we're copy+pasting text? check how long it was since the /* maybe we're copy+pasting text? check how long it was since the
last line */ last line */
diff = get_timeval_diff(&time_command_now, &time_command_last); diff = time_command_now - time_command_last;
if (item != NULL && !last_command_cmd && diff < PASTE_CHECK_SPEED) { if (item != NULL && !last_command_cmd && diff < PASTE_CHECK_SPEED) {
signal_emit("send text", 3, current_cmdline, active_win->active_server, active_win->active); signal_emit("send text", 3, current_cmdline, active_win->active_server, active_win->active);
command_cmd = FALSE; command_cmd = FALSE;
@ -334,7 +334,7 @@ void fe_core_commands_init(void)
command_hide_output = 0; command_hide_output = 0;
command_cmd = FALSE; command_cmd = FALSE;
memset(&time_command_now, 0, sizeof(GTimeVal)); time_command_now = 0;
command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo); command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo);
command_bind("version", NULL, (SIGNAL_FUNC) cmd_version); command_bind("version", NULL, (SIGNAL_FUNC) cmd_version);

View File

@ -415,7 +415,7 @@ static void sig_server_lag_disconnected(SERVER_REC *server)
printformat(server, NULL, MSGLEVEL_CLIENTNOTICE, printformat(server, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_LAG_DISCONNECTED, server->connrec->address, TXT_LAG_DISCONNECTED, server->connrec->address,
time(NULL)-server->lag_sent.tv_sec); time(NULL)-(server->lag_sent / G_TIME_SPAN_SECOND));
} }
static void sig_server_reconnect_removed(RECONNECT_REC *reconnect) static void sig_server_reconnect_removed(RECONNECT_REC *reconnect)

View File

@ -123,22 +123,23 @@ static void ctcp_ping_reply(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr, const char *nick, const char *addr,
const char *target) const char *target)
{ {
GTimeVal tv, tv2; gint64 tv, tv2;
long usecs; long usecs;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
if (sscanf(data, "%ld %ld", &tv2.tv_sec, &tv2.tv_usec) < 1) { if (sscanf(data, "%ld %ld", &tv, &tv2) < 1) {
char *tmp = g_strconcat("PING ", data, NULL); char *tmp = g_strconcat("PING ", data, NULL);
ctcp_default_reply(server, tmp, nick, addr, target); ctcp_default_reply(server, tmp, nick, addr, target);
g_free(tmp); g_free(tmp);
return; return;
} }
g_get_current_time(&tv); tv2 += tv * G_TIME_SPAN_SECOND;
usecs = get_timeval_diff(&tv, &tv2); tv = g_get_real_time();
printformat(server, server_ischannel(SERVER(server), target) ? target : nick, MSGLEVEL_CTCPS, usecs = tv - tv2;
IRCTXT_CTCP_PING_REPLY, nick, usecs/1000, usecs%1000); printformat(server, server_ischannel(SERVER(server), target) ? target : nick, MSGLEVEL_CTCPS,
IRCTXT_CTCP_PING_REPLY, nick, usecs / G_TIME_SPAN_SECOND, usecs % G_TIME_SPAN_SECOND);
} }
void fe_ctcp_init(void) void fe_ctcp_init(void)

View File

@ -58,7 +58,7 @@ static int escape_next_key;
static int readtag; static int readtag;
static unichar prev_key; static unichar prev_key;
static GTimeVal last_keypress; static gint64 last_keypress;
static int paste_detect_time, paste_verify_line_count; static int paste_detect_time, paste_verify_line_count;
static char *paste_entry; static char *paste_entry;
@ -395,8 +395,8 @@ static void insert_paste_prompt(void)
static void sig_gui_key_pressed(gpointer keyp) static void sig_gui_key_pressed(gpointer keyp)
{ {
GTimeVal now; gint64 now;
unichar key; unichar key;
char str[20]; char str[20];
int ret; int ret;
@ -407,7 +407,7 @@ static void sig_gui_key_pressed(gpointer keyp)
return; return;
} }
g_get_current_time(&now); now = g_get_real_time();
if (key < 32) { if (key < 32) {
/* control key */ /* control key */
@ -875,7 +875,7 @@ static void key_paste_start(void)
time_t get_idle_time(void) time_t get_idle_time(void)
{ {
return last_keypress.tv_sec; return last_keypress / G_TIME_SPAN_SECOND;
} }
static void key_scroll_backward(void) static void key_scroll_backward(void)
@ -1154,8 +1154,8 @@ void gui_readline_init(void)
paste_old_prompt = NULL; paste_old_prompt = NULL;
paste_timeout_id = -1; paste_timeout_id = -1;
paste_bracketed_mode = FALSE; paste_bracketed_mode = FALSE;
g_get_current_time(&last_keypress); last_keypress = g_get_real_time();
input_listen_init(STDIN_FILENO); input_listen_init(STDIN_FILENO);
settings_add_bool("lookandfeel", "term_appkey_mode", TRUE); settings_add_bool("lookandfeel", "term_appkey_mode", TRUE);
settings_add_str("history", "scroll_page_count", "/2"); settings_add_str("history", "scroll_page_count", "/2");

View File

@ -333,15 +333,15 @@ static int get_lag(SERVER_REC *server, int *unknown)
return 0; return 0;
} }
if (server->lag_sent.tv_sec == 0) { if (server->lag_sent == 0) {
/* no lag queries going on currently */ /* no lag queries going on currently */
return server->lag; return server->lag;
} }
/* we're not sure about our current lag.. */ /* we're not sure about our current lag.. */
*unknown = TRUE; *unknown = TRUE;
lag = (long) (time(NULL)-server->lag_sent.tv_sec); lag = (long) (time(NULL) - (server->lag_sent / G_TIME_SPAN_SECOND));
if (server->lag/1000 > lag) { if (server->lag/1000 > lag) {
/* we've been waiting the lag reply less time than /* we've been waiting the lag reply less time than
what last known lag was -> use the last known lag */ what last known lag was -> use the last known lag */

View File

@ -528,7 +528,7 @@ static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
/* SYNTAX: PING [<nick> | <channel> | *] */ /* SYNTAX: PING [<nick> | <channel> | *] */
static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{ {
GTimeVal tv; gint64 tv;
char *str; char *str;
CMD_IRC_SERVER(server); CMD_IRC_SERVER(server);
@ -539,9 +539,9 @@ static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
data = window_item_get_target(item); data = window_item_get_target(item);
} }
g_get_current_time(&tv); tv = g_get_real_time();
str = g_strdup_printf("%s PING %ld %ld", data, tv.tv_sec, tv.tv_usec); str = g_strdup_printf("%s PING %ld %ld", data, tv / G_TIME_SPAN_SECOND, tv % G_TIME_SPAN_SECOND);
signal_emit("command ctcp", 3, str, server, item); signal_emit("command ctcp", 3, str, server, item);
g_free(str); g_free(str);
} }
@ -616,13 +616,8 @@ static void cmd_wait(const char *data, IRC_SERVER_REC *server)
n = atoi(msecs); n = atoi(msecs);
if (server != NULL && n > 0) { if (server != NULL && n > 0) {
g_get_current_time(&server->wait_cmd); server->wait_cmd = g_get_real_time();
server->wait_cmd.tv_sec += n/1000; server->wait_cmd += n * G_TIME_SPAN_MILLISECOND;
server->wait_cmd.tv_usec += n%1000;
if (server->wait_cmd.tv_usec >= 1000) {
server->wait_cmd.tv_sec++;
server->wait_cmd.tv_usec -= 1000;
}
} }
cmd_params_free(free_arg); cmd_params_free(free_arg);
} }

View File

@ -294,8 +294,8 @@ static void server_init(IRC_SERVER_REC *server)
/* prevent the queue from sending too early, we have a max cut off of 120 secs */ /* prevent the queue from sending too early, we have a max cut off of 120 secs */
/* this will reset to 1 sec after we get the 001 event */ /* this will reset to 1 sec after we get the 001 event */
g_get_current_time(&server->wait_cmd); server->wait_cmd = g_get_real_time();
g_time_val_add(&server->wait_cmd, 120 * G_USEC_PER_SEC); server->wait_cmd += 120 * G_USEC_PER_SEC;
} }
SERVER_REC *irc_server_init_connect(SERVER_CONNECT_REC *conn) SERVER_REC *irc_server_init_connect(SERVER_CONNECT_REC *conn)
@ -559,21 +559,21 @@ void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len)
return; return;
} }
g_get_current_time(&server->last_cmd); server->last_cmd = g_get_real_time();
/* A bit kludgy way to do the flood protection. In ircnet, there /* A bit kludgy way to do the flood protection. In ircnet, there
actually is 1sec / 100 bytes penalty, but we rather want to deal actually is 1sec / 100 bytes penalty, but we rather want to deal
with the max. 1000 bytes input buffer problem. If we send more with the max. 1000 bytes input buffer problem. If we send more
than that with the burst, we'll get excess flooded. */ than that with the burst, we'll get excess flooded. */
if (len < 100 || server->cmd_queue_speed <= 10) if (len < 100 || server->cmd_queue_speed <= 10)
server->wait_cmd.tv_sec = 0; server->wait_cmd = 0;
else { else {
memcpy(&server->wait_cmd, &server->last_cmd, sizeof(GTimeVal)); server->wait_cmd = server->last_cmd;
g_time_val_add(&server->wait_cmd, (2 + len/100) * G_USEC_PER_SEC); server->wait_cmd += (2 + len / 100) * G_USEC_PER_SEC;
} }
} }
static int server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now)
{ {
REDIRECT_REC *redirect; REDIRECT_REC *redirect;
GSList *link; GSList *link;
@ -587,10 +587,10 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now)
if (server->cmdcount == 0 && server->cmdqueue == NULL) if (server->cmdcount == 0 && server->cmdqueue == NULL)
return 0; return 0;
if (g_timeval_cmp(now, &server->wait_cmd) == -1) if (now < server->wait_cmd)
return 1; return 1;
usecs = get_timeval_diff(now, &server->last_cmd); usecs = (now - server->last_cmd) / G_TIME_SPAN_MILLISECOND;
if (usecs < server->cmd_queue_speed) if (usecs < server->cmd_queue_speed)
return 1; return 1;
@ -626,13 +626,13 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now)
/* check every now and then if there's data to be sent in command buffer */ /* check every now and then if there's data to be sent in command buffer */
static int servers_cmd_timeout(void) static int servers_cmd_timeout(void)
{ {
GTimeVal now; gint64 now;
GSList *tmp; GSList *tmp;
int keep = 0; int keep = 0;
g_get_current_time(&now); now = g_get_real_time();
for (tmp = servers; tmp != NULL; tmp = tmp->next) { for (tmp = servers; tmp != NULL; tmp = tmp->next) {
keep |= server_cmd_timeout(tmp->data, &now); keep |= server_cmd_timeout(tmp->data, now);
} }
if (keep) if (keep)
return 1; return 1;
@ -735,7 +735,7 @@ static void event_connected(IRC_SERVER_REC *server, const char *data, const char
server->real_connect_time = time(NULL); server->real_connect_time = time(NULL);
/* let the queue send now that we are identified */ /* let the queue send now that we are identified */
g_get_current_time(&server->wait_cmd); server->wait_cmd = g_get_real_time();
if (server->connrec->usermode != NULL) { if (server->connrec->usermode != NULL) {
/* Send the user mode, before the autosendcmd. /* Send the user mode, before the autosendcmd.

View File

@ -113,8 +113,8 @@ struct _IRC_SERVER_REC {
how many messages can be sent before starting the how many messages can be sent before starting the
flood control */ flood control */
GSList *cmdqueue; /* command, redirection, ... */ GSList *cmdqueue; /* command, redirection, ... */
GTimeVal wait_cmd; /* don't send anything to server before this */ gint64 wait_cmd; /* don't send anything to server before this */
GTimeVal last_cmd; /* last time command was sent to server */ gint64 last_cmd; /* last time command was sent to server */
int max_cmds_at_once; /* How many messages can be sent immediately before timeouting starts */ int max_cmds_at_once; /* How many messages can be sent immediately before timeouting starts */
int cmd_queue_speed; /* Timeout between sending commands */ int cmd_queue_speed; /* Timeout between sending commands */

View File

@ -140,15 +140,15 @@ void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd,
/* Send command to IRC server */ /* Send command to IRC server */
void irc_send_cmd(IRC_SERVER_REC *server, const char *cmd) void irc_send_cmd(IRC_SERVER_REC *server, const char *cmd)
{ {
GTimeVal now; gint64 now;
int send_now; int send_now;
g_get_current_time(&now); now = g_get_real_time();
send_now = g_timeval_cmp(&now, &server->wait_cmd) >= 0 && send_now = now >= server->wait_cmd &&
(server->cmdcount < server->max_cmds_at_once || (server->cmdcount < server->max_cmds_at_once ||
server->cmd_queue_speed <= 0); server->cmd_queue_speed <= 0);
irc_send_cmd_full(server, cmd, send_now, FALSE, FALSE); irc_send_cmd_full(server, cmd, send_now, FALSE, FALSE);
} }
/* Send command to IRC server */ /* Send command to IRC server */

View File

@ -30,7 +30,7 @@ static int timeout_tag;
static void lag_get(IRC_SERVER_REC *server) static void lag_get(IRC_SERVER_REC *server)
{ {
g_get_current_time(&server->lag_sent); server->lag_sent = g_get_real_time();
server->lag_last_check = time(NULL); server->lag_last_check = time(NULL);
server_redirect_event(server, "ping", 1, NULL, FALSE, server_redirect_event(server, "ping", 1, NULL, FALSE,
@ -48,18 +48,18 @@ static void lag_ping_error(IRC_SERVER_REC *server)
static void lag_event_pong(IRC_SERVER_REC *server, const char *data, static void lag_event_pong(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr) const char *nick, const char *addr)
{ {
GTimeVal now; gint64 now;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
if (server->lag_sent.tv_sec == 0) { if (server->lag_sent == 0) {
/* not expecting lag reply.. */ /* not expecting lag reply.. */
return; return;
} }
g_get_current_time(&now); now = g_get_real_time();
server->lag = (int) get_timeval_diff(&now, &server->lag_sent); server->lag = (now - server->lag_sent) / G_TIME_SPAN_MILLISECOND;
memset(&server->lag_sent, 0, sizeof(server->lag_sent)); server->lag_sent = 0;
signal_emit("server lag", 1, server); signal_emit("server lag", 1, server);
} }
@ -76,8 +76,8 @@ static void sig_unknown_command(IRC_SERVER_REC *server, const char *data)
trying alternative methods to detect lag with these trying alternative methods to detect lag with these
servers. */ servers. */
server->disable_lag = TRUE; server->disable_lag = TRUE;
server->lag_sent.tv_sec = 0; server->lag_sent = 0;
server->lag = 0; server->lag = 0;
} }
g_free(params); g_free(params);
} }
@ -102,16 +102,16 @@ static int sig_check_lag(void)
if (!IS_IRC_SERVER(rec) || rec->disable_lag) if (!IS_IRC_SERVER(rec) || rec->disable_lag)
continue; continue;
if (rec->lag_sent.tv_sec != 0) { if (rec->lag_sent != 0) {
/* waiting for lag reply */ /* waiting for lag reply */
if (max_lag > 1 && now-rec->lag_sent.tv_sec > max_lag) { if (max_lag > 1 && now - rec->lag_sent > max_lag * G_TIME_SPAN_SECOND) {
/* too much lag, disconnect */ /* too much lag, disconnect */
signal_emit("server lag disconnect", 1, rec); signal_emit("server lag disconnect", 1, rec);
rec->connection_lost = TRUE; rec->connection_lost = TRUE;
server_disconnect((SERVER_REC *) rec); server_disconnect((SERVER_REC *) rec);
} }
} else if (rec->lag_last_check+lag_check_time < now && } else if (rec->lag_last_check + lag_check_time < now && rec->cmdcount == 0 &&
rec->cmdcount == 0 && rec->connected) { rec->connected) {
/* no commands in buffer - get the lag */ /* no commands in buffer - get the lag */
lag_get(rec); lag_get(rec);
} }