From 13c5de5531f00e33aefe44bbb4d79e58f6553511 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 10 Sep 2014 16:18:37 -0400 Subject: [PATCH] increase time between message send retries --- src/line_info.c | 9 +++++---- src/line_info.h | 3 +-- src/log.c | 2 ++ src/log.h | 2 -- src/message_queue.c | 29 ++++++++++++++++------------- src/message_queue.h | 4 +--- src/toxic.c | 2 +- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/line_info.c b/src/line_info.c index c83e4b3..575fabf 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -129,8 +129,7 @@ static struct line_info *line_info_ret_queue(struct history *hst) return ret; } -/* creates new line_info line and puts it in the queue. - SYS_MSG lines may contain an arbitrary number of arguments for string formatting */ +/* creates new line_info line and puts it in the queue. */ void line_info_add(ToxWindow *self, char *timestr, char *name1, char *name2, uint8_t type, uint8_t bold, uint8_t colour, const char *msg, ...) { @@ -257,6 +256,8 @@ static void line_info_check_queue(ToxWindow *self) } } +#define NOREAD_FLAG_TIMEOUT 5 /* seconds before a sent message with no read receipt is flagged as unread */ + void line_info_print(ToxWindow *self) { ChatContext *ctx = self->chatwin; @@ -315,7 +316,7 @@ void line_info_print(ToxWindow *self) if (line->msg[0] == '>') wattroff(win, COLOR_PAIR(GREEN)); - if (type == OUT_MSG && timed_out(line->timestamp, get_unix_time(), CQUEUE_TRY_SEND_INTERVAL)) { + if (type == OUT_MSG && timed_out(line->timestamp, get_unix_time(), NOREAD_FLAG_TIMEOUT)) { wattron(win, COLOR_PAIR(RED)); wprintw(win, " x", line->msg); wattroff(win, COLOR_PAIR(RED)); @@ -340,7 +341,7 @@ void line_info_print(ToxWindow *self) wprintw(win, "* %s %s", line->name1, line->msg); wattroff(win, COLOR_PAIR(YELLOW)); - if (type == OUT_ACTION && timed_out(line->timestamp, get_unix_time(), CQUEUE_TRY_SEND_INTERVAL)) { + if (type == OUT_ACTION && timed_out(line->timestamp, get_unix_time(), NOREAD_FLAG_TIMEOUT)) { wattron(win, COLOR_PAIR(RED)); wprintw(win, " x", line->msg); wattroff(win, COLOR_PAIR(RED)); diff --git a/src/line_info.h b/src/line_info.h index 7f1b262..0524958 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -72,8 +72,7 @@ struct history { int queue_sz; }; -/* creates new line_info line and puts it in the queue. - SYS_MSG lines may contain an arbitrary number of arguments for string formatting */ +/* creates new line_info line and puts it in the queue. */ void line_info_add(ToxWindow *self, char *timestr, char *name1, char *name2, uint8_t type, uint8_t bold, uint8_t colour, const char *msg, ...); diff --git a/src/log.c b/src/log.c index 69d9eb4..2819071 100644 --- a/src/log.c +++ b/src/log.c @@ -86,6 +86,8 @@ void init_logging_session(char *name, const char *key, struct chatlog *log) fprintf(log->file, "\n*** NEW SESSION ***\n\n"); } +#define LOG_FLUSH_LIMIT 2 /* limits calls to fflush to a max of one per LOG_FLUSH_LIMIT seconds */ + void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event) { if (!log->log_on) diff --git a/src/log.h b/src/log.h index f3e2e6d..430705c 100644 --- a/src/log.h +++ b/src/log.h @@ -23,8 +23,6 @@ #ifndef _log_h #define _log_h -#define LOG_FLUSH_LIMIT 2 /* limits calls to fflush(logfile) to a max of one per LOG_FLUSH_LIMIT seconds */ - struct chatlog { FILE *file; uint64_t lastwrite; diff --git a/src/message_queue.c b/src/message_queue.c index ae3ce62..6b18a6f 100644 --- a/src/message_queue.c +++ b/src/message_queue.c @@ -73,18 +73,19 @@ static void cqueue_mark_read(ToxWindow *self, uint32_t id, uint8_t type) struct line_info *line = self->chatwin->hst->line_end; while (line) { - if (line->id == id) { - line->type = type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ; - - if (line->noread_flag == true) { - line->len -= 2; - line->noread_flag = false; - } - - return; + if (line->id != id) { + line = line->prev; + continue; } - line = line->prev; + line->type = type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ; + + if (line->noread_flag == true) { + line->len -= 2; + line->noread_flag = false; + } + + return; } } @@ -118,8 +119,10 @@ void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt) } } +#define CQUEUE_TRY_SEND_INTERVAL 10 + /* Tries to send the oldest unsent message in queue. */ -void cqueue_try_send(ToxWindow *self, Tox *m, int32_t friendnum) +void cqueue_try_send(ToxWindow *self, Tox *m) { struct chat_queue *q = self->chatwin->cqueue; struct cqueue_msg *msg = q->root; @@ -134,9 +137,9 @@ void cqueue_try_send(ToxWindow *self, Tox *m, int32_t friendnum) uint32_t receipt = 0; if (msg->type == OUT_MSG) - receipt = tox_send_message(m, friendnum, (uint8_t *) msg->message, msg->len); + receipt = tox_send_message(m, self->num, (uint8_t *) msg->message, msg->len); else - receipt = tox_send_action(m, friendnum, (uint8_t *) msg->message, msg->len); + receipt = tox_send_action(m, self->num, (uint8_t *) msg->message, msg->len); msg->last_send_try = curtime; msg->receipt = receipt; diff --git a/src/message_queue.h b/src/message_queue.h index 28adb9b..9831629 100644 --- a/src/message_queue.h +++ b/src/message_queue.h @@ -20,8 +20,6 @@ * */ -#define CQUEUE_TRY_SEND_INTERVAL 5 - struct cqueue_msg { char message[MAX_STR_SIZE]; int len; @@ -42,7 +40,7 @@ void cqueue_cleanup(struct chat_queue *q); void cqueue_add(struct chat_queue *q, const char *msg, int len, uint8_t type, uint32_t line_id); /* Tries to send the oldest unsent message in queue. */ -void cqueue_try_send(ToxWindow *self, Tox *m, int32_t friendnum); +void cqueue_try_send(ToxWindow *self, Tox *m); /* removes message with matching receipt from queue and updates line to show the message was received. */ void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt); diff --git a/src/toxic.c b/src/toxic.c index 86ad239..d32cd77 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -588,7 +588,7 @@ void *thread_cqueue(void *data) ToxWindow *toxwin = get_window_ptr(i); if (toxwin != NULL && toxwin->is_chat && tox_get_friend_connection_status(m, toxwin->num) == 1) - cqueue_try_send(toxwin, m, toxwin->num); + cqueue_try_send(toxwin, m); } pthread_mutex_unlock(&Winthread.lock);