mirror of
https://github.com/irssi/irssi.git
synced 2024-09-01 04:14:16 -04:00
Merge pull request #1145 from ailin-nemui/time
remove GTimeVal following glib 2.61.2 deprecation
This commit is contained in:
commit
363a79dc7a
@ -6,7 +6,7 @@
|
||||
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||
#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_TLS_PORT 6697
|
||||
|
@ -94,8 +94,11 @@ int g_input_add_poll(int fd, int priority, int condition,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
int g_timeval_cmp(const GTimeVal *tv1, const GTimeVal *tv2)
|
||||
{
|
||||
#pragma GCC diagnostic pop
|
||||
if (tv1->tv_sec < tv2->tv_sec)
|
||||
return -1;
|
||||
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;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
long get_timeval_diff(const GTimeVal *tv1, const GTimeVal *tv2)
|
||||
{
|
||||
#pragma GCC diagnostic pop
|
||||
long secs, usecs;
|
||||
|
||||
secs = tv1->tv_sec - tv2->tv_sec;
|
||||
|
@ -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 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. */
|
||||
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
|
||||
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_icase_string(GSList *list, const char *key);
|
||||
|
@ -37,7 +37,7 @@ unsigned int usermode_away:1;
|
||||
unsigned int banned:1; /* not allowed to connect to this server */
|
||||
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 */
|
||||
int lag; /* server lag in milliseconds */
|
||||
|
||||
|
@ -65,7 +65,7 @@ int command_hide_output;
|
||||
the line had one or two command chars, and which one.. */
|
||||
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;
|
||||
|
||||
/* SYNTAX: ECHO [-window <name>] [-level <level>] <text> */
|
||||
@ -222,7 +222,7 @@ static void event_command(const char *data)
|
||||
time_command_last = time_command_now;
|
||||
last_command_cmd = command_cmd;
|
||||
|
||||
g_get_current_time(&time_command_now);
|
||||
time_command_now = g_get_real_time();
|
||||
command_cmd = *data != '\0' &&
|
||||
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
|
||||
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) {
|
||||
signal_emit("send text", 3, current_cmdline, active_win->active_server, active_win->active);
|
||||
command_cmd = FALSE;
|
||||
@ -334,7 +334,7 @@ void fe_core_commands_init(void)
|
||||
command_hide_output = 0;
|
||||
|
||||
command_cmd = FALSE;
|
||||
memset(&time_command_now, 0, sizeof(GTimeVal));
|
||||
time_command_now = 0;
|
||||
|
||||
command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo);
|
||||
command_bind("version", NULL, (SIGNAL_FUNC) cmd_version);
|
||||
|
@ -415,7 +415,7 @@ static void sig_server_lag_disconnected(SERVER_REC *server)
|
||||
|
||||
printformat(server, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
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)
|
||||
|
@ -123,22 +123,23 @@ static void ctcp_ping_reply(IRC_SERVER_REC *server, const char *data,
|
||||
const char *nick, const char *addr,
|
||||
const char *target)
|
||||
{
|
||||
GTimeVal tv, tv2;
|
||||
gint64 tv, tv2;
|
||||
long usecs;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (sscanf(data, "%ld %ld", &tv2.tv_sec, &tv2.tv_usec) < 1) {
|
||||
char *tmp = g_strconcat("PING ", data, NULL);
|
||||
if (sscanf(data, "%ld %ld", &tv, &tv2) < 1) {
|
||||
char *tmp = g_strconcat("PING ", data, NULL);
|
||||
ctcp_default_reply(server, tmp, nick, addr, target);
|
||||
g_free(tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
g_get_current_time(&tv);
|
||||
usecs = get_timeval_diff(&tv, &tv2);
|
||||
printformat(server, server_ischannel(SERVER(server), target) ? target : nick, MSGLEVEL_CTCPS,
|
||||
IRCTXT_CTCP_PING_REPLY, nick, usecs/1000, usecs%1000);
|
||||
tv2 += tv * G_TIME_SPAN_SECOND;
|
||||
tv = g_get_real_time();
|
||||
usecs = tv - tv2;
|
||||
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)
|
||||
|
@ -58,7 +58,7 @@ static int escape_next_key;
|
||||
|
||||
static int readtag;
|
||||
static unichar prev_key;
|
||||
static GTimeVal last_keypress;
|
||||
static gint64 last_keypress;
|
||||
|
||||
static int paste_detect_time, paste_verify_line_count;
|
||||
static char *paste_entry;
|
||||
@ -395,8 +395,8 @@ static void insert_paste_prompt(void)
|
||||
|
||||
static void sig_gui_key_pressed(gpointer keyp)
|
||||
{
|
||||
GTimeVal now;
|
||||
unichar key;
|
||||
gint64 now;
|
||||
unichar key;
|
||||
char str[20];
|
||||
int ret;
|
||||
|
||||
@ -407,7 +407,7 @@ static void sig_gui_key_pressed(gpointer keyp)
|
||||
return;
|
||||
}
|
||||
|
||||
g_get_current_time(&now);
|
||||
now = g_get_real_time();
|
||||
|
||||
if (key < 32) {
|
||||
/* control key */
|
||||
@ -875,7 +875,7 @@ static void key_paste_start(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)
|
||||
@ -1154,8 +1154,8 @@ void gui_readline_init(void)
|
||||
paste_old_prompt = NULL;
|
||||
paste_timeout_id = -1;
|
||||
paste_bracketed_mode = FALSE;
|
||||
g_get_current_time(&last_keypress);
|
||||
input_listen_init(STDIN_FILENO);
|
||||
last_keypress = g_get_real_time();
|
||||
input_listen_init(STDIN_FILENO);
|
||||
|
||||
settings_add_bool("lookandfeel", "term_appkey_mode", TRUE);
|
||||
settings_add_str("history", "scroll_page_count", "/2");
|
||||
|
@ -333,15 +333,15 @@ static int get_lag(SERVER_REC *server, int *unknown)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (server->lag_sent.tv_sec == 0) {
|
||||
if (server->lag_sent == 0) {
|
||||
/* no lag queries going on currently */
|
||||
return server->lag;
|
||||
}
|
||||
|
||||
/* we're not sure about our current lag.. */
|
||||
/* we're not sure about our current lag.. */
|
||||
*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) {
|
||||
/* we've been waiting the lag reply less time than
|
||||
what last known lag was -> use the last known lag */
|
||||
|
@ -528,7 +528,7 @@ static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
|
||||
/* SYNTAX: PING [<nick> | <channel> | *] */
|
||||
static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
GTimeVal tv;
|
||||
gint64 tv;
|
||||
char *str;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
g_free(str);
|
||||
}
|
||||
@ -616,13 +616,8 @@ static void cmd_wait(const char *data, IRC_SERVER_REC *server)
|
||||
|
||||
n = atoi(msecs);
|
||||
if (server != NULL && n > 0) {
|
||||
g_get_current_time(&server->wait_cmd);
|
||||
server->wait_cmd.tv_sec += n/1000;
|
||||
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;
|
||||
}
|
||||
server->wait_cmd = g_get_real_time();
|
||||
server->wait_cmd += n * G_TIME_SPAN_MILLISECOND;
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
@ -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 */
|
||||
/* this will reset to 1 sec after we get the 001 event */
|
||||
g_get_current_time(&server->wait_cmd);
|
||||
g_time_val_add(&server->wait_cmd, 120 * G_USEC_PER_SEC);
|
||||
server->wait_cmd = g_get_real_time();
|
||||
server->wait_cmd += 120 * G_USEC_PER_SEC;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
actually is 1sec / 100 bytes penalty, but we rather want to deal
|
||||
with the max. 1000 bytes input buffer problem. If we send more
|
||||
than that with the burst, we'll get excess flooded. */
|
||||
if (len < 100 || server->cmd_queue_speed <= 10)
|
||||
server->wait_cmd.tv_sec = 0;
|
||||
server->wait_cmd = 0;
|
||||
else {
|
||||
memcpy(&server->wait_cmd, &server->last_cmd, sizeof(GTimeVal));
|
||||
g_time_val_add(&server->wait_cmd, (2 + len/100) * G_USEC_PER_SEC);
|
||||
server->wait_cmd = server->last_cmd;
|
||||
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;
|
||||
GSList *link;
|
||||
@ -587,10 +587,10 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now)
|
||||
if (server->cmdcount == 0 && server->cmdqueue == NULL)
|
||||
return 0;
|
||||
|
||||
if (g_timeval_cmp(now, &server->wait_cmd) == -1)
|
||||
if (now < server->wait_cmd)
|
||||
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)
|
||||
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 */
|
||||
static int servers_cmd_timeout(void)
|
||||
{
|
||||
GTimeVal now;
|
||||
gint64 now;
|
||||
GSList *tmp;
|
||||
int keep = 0;
|
||||
|
||||
g_get_current_time(&now);
|
||||
now = g_get_real_time();
|
||||
for (tmp = servers; tmp != NULL; tmp = tmp->next) {
|
||||
keep |= server_cmd_timeout(tmp->data, &now);
|
||||
keep |= server_cmd_timeout(tmp->data, now);
|
||||
}
|
||||
if (keep)
|
||||
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);
|
||||
|
||||
/* 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) {
|
||||
/* Send the user mode, before the autosendcmd.
|
||||
|
@ -113,8 +113,8 @@ struct _IRC_SERVER_REC {
|
||||
how many messages can be sent before starting the
|
||||
flood control */
|
||||
GSList *cmdqueue; /* command, redirection, ... */
|
||||
GTimeVal wait_cmd; /* don't send anything to server before this */
|
||||
GTimeVal last_cmd; /* last time command was sent to server */
|
||||
gint64 wait_cmd; /* don't send anything to server before this */
|
||||
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 cmd_queue_speed; /* Timeout between sending commands */
|
||||
|
@ -140,15 +140,15 @@ void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd,
|
||||
/* Send command to IRC server */
|
||||
void irc_send_cmd(IRC_SERVER_REC *server, const char *cmd)
|
||||
{
|
||||
GTimeVal now;
|
||||
gint64 now;
|
||||
int send_now;
|
||||
|
||||
g_get_current_time(&now);
|
||||
send_now = g_timeval_cmp(&now, &server->wait_cmd) >= 0 &&
|
||||
(server->cmdcount < server->max_cmds_at_once ||
|
||||
server->cmd_queue_speed <= 0);
|
||||
now = g_get_real_time();
|
||||
send_now = now >= server->wait_cmd &&
|
||||
(server->cmdcount < server->max_cmds_at_once ||
|
||||
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 */
|
||||
|
@ -30,7 +30,7 @@ static int timeout_tag;
|
||||
|
||||
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_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,
|
||||
const char *nick, const char *addr)
|
||||
{
|
||||
GTimeVal now;
|
||||
gint64 now;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (server->lag_sent.tv_sec == 0) {
|
||||
if (server->lag_sent == 0) {
|
||||
/* not expecting lag reply.. */
|
||||
return;
|
||||
}
|
||||
|
||||
g_get_current_time(&now);
|
||||
server->lag = (int) get_timeval_diff(&now, &server->lag_sent);
|
||||
memset(&server->lag_sent, 0, sizeof(server->lag_sent));
|
||||
now = g_get_real_time();
|
||||
server->lag = (now - server->lag_sent) / G_TIME_SPAN_MILLISECOND;
|
||||
server->lag_sent = 0;
|
||||
|
||||
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
|
||||
servers. */
|
||||
server->disable_lag = TRUE;
|
||||
server->lag_sent.tv_sec = 0;
|
||||
server->lag = 0;
|
||||
server->lag_sent = 0;
|
||||
server->lag = 0;
|
||||
}
|
||||
g_free(params);
|
||||
}
|
||||
@ -102,16 +102,16 @@ static int sig_check_lag(void)
|
||||
if (!IS_IRC_SERVER(rec) || rec->disable_lag)
|
||||
continue;
|
||||
|
||||
if (rec->lag_sent.tv_sec != 0) {
|
||||
if (rec->lag_sent != 0) {
|
||||
/* 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 */
|
||||
signal_emit("server lag disconnect", 1, rec);
|
||||
rec->connection_lost = TRUE;
|
||||
server_disconnect((SERVER_REC *) rec);
|
||||
}
|
||||
} else if (rec->lag_last_check+lag_check_time < now &&
|
||||
rec->cmdcount == 0 && rec->connected) {
|
||||
} else if (rec->lag_last_check + lag_check_time < now && rec->cmdcount == 0 &&
|
||||
rec->connected) {
|
||||
/* no commands in buffer - get the lag */
|
||||
lag_get(rec);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user