mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 14:26:39 +02:00
Added transfer rate for DCC files
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-04-19
|
||||
ChangeLog - 2005-04-23
|
||||
|
||||
|
||||
Version 0.1.2 (under dev!):
|
||||
* added transfer rate for DCC files
|
||||
* added "-all" option for /nick command
|
||||
* buffers timestamp can now be changed (new option in config file)
|
||||
* fixed crash when purging old DCC
|
||||
|
||||
@@ -765,6 +765,7 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_chat, ">");
|
||||
for (j = 0; j < 10 - num_bars; j++)
|
||||
wprintw (ptr_win->win_chat, " ");
|
||||
|
||||
if (ptr_dcc->size < 1024*10)
|
||||
num_unit = 0;
|
||||
else if (ptr_dcc->size < 1024*1024)
|
||||
@@ -779,20 +780,31 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
unit_format[num_unit],
|
||||
unit_format[num_unit]);
|
||||
wprintw (ptr_win->win_chat, format,
|
||||
((long double) ptr_dcc->pos) / ((long double)(unit_divide[num_unit])),
|
||||
((long double)(ptr_dcc->pos)) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit],
|
||||
((long double) ptr_dcc->size) / ((long double)(unit_divide[num_unit])),
|
||||
((long double)(ptr_dcc->size)) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit]);
|
||||
|
||||
if (ptr_dcc->bytes_per_sec < 1024*1024)
|
||||
num_unit = 1;
|
||||
else if (ptr_dcc->bytes_per_sec < 1024*1024*1024)
|
||||
num_unit = 2;
|
||||
else
|
||||
num_unit = 3;
|
||||
sprintf (format, " (%s %%s/s)", unit_format[num_unit]);
|
||||
wprintw (ptr_win->win_chat, format,
|
||||
((long double) ptr_dcc->bytes_per_sec) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit]);
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
}
|
||||
else
|
||||
{
|
||||
date_tmp = localtime (&(ptr_dcc->start_time));
|
||||
strftime (date, sizeof (date) - 1, "%a, %d %b %Y %H:%M:%S", date_tmp);
|
||||
wprintw (ptr_win->win_chat, " %s", date);
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
}
|
||||
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
|
||||
ptr_win->dcc_last_displayed = ptr_dcc;
|
||||
i += 2;
|
||||
}
|
||||
|
||||
+46
-1
@@ -63,6 +63,40 @@ dcc_redraw (int highlight)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_calculate_speed: calculate DCC speed (for files only)
|
||||
*/
|
||||
|
||||
void
|
||||
dcc_calculate_speed (t_irc_dcc *ptr_dcc, int ended)
|
||||
{
|
||||
time_t local_time, elapsed;
|
||||
|
||||
local_time = time (NULL);
|
||||
if (ended || local_time > ptr_dcc->last_check_time)
|
||||
{
|
||||
|
||||
if (ended)
|
||||
{
|
||||
elapsed = local_time - ptr_dcc->start_transfer;
|
||||
if (elapsed == 0)
|
||||
elapsed = 1;
|
||||
ptr_dcc->bytes_per_sec = ptr_dcc->pos / elapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsed = local_time - ptr_dcc->last_check_time;
|
||||
if (elapsed == 0)
|
||||
elapsed = 1;
|
||||
ptr_dcc->bytes_per_sec = (ptr_dcc->pos - ptr_dcc->last_check_pos) / elapsed;
|
||||
}
|
||||
ptr_dcc->last_check_time = local_time;
|
||||
ptr_dcc->last_check_pos = ptr_dcc->pos;
|
||||
wee_log_printf ("bytes per sec calculé: %lu\n", ptr_dcc->bytes_per_sec);
|
||||
}
|
||||
wee_log_printf ("bytes per sec calculé pas bon !!!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_connect: connect to another host
|
||||
*/
|
||||
@@ -200,6 +234,9 @@ dcc_close (t_irc_dcc *ptr_dcc, int status)
|
||||
if (DCC_IS_CHAT(ptr_dcc->type))
|
||||
channel_remove_dcc (ptr_dcc);
|
||||
|
||||
if (DCC_IS_FILE(ptr_dcc->type))
|
||||
dcc_calculate_speed (ptr_dcc, 1);
|
||||
|
||||
if (ptr_dcc->sock != -1)
|
||||
{
|
||||
close (ptr_dcc->sock);
|
||||
@@ -327,6 +364,7 @@ dcc_accept (t_irc_dcc *ptr_dcc)
|
||||
ptr_dcc->file = open (ptr_dcc->local_filename,
|
||||
O_CREAT | O_TRUNC | O_WRONLY | O_NONBLOCK,
|
||||
0644);
|
||||
ptr_dcc->start_transfer = time (NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -363,6 +401,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
|
||||
new_dcc->type = type;
|
||||
new_dcc->status = DCC_WAITING;
|
||||
new_dcc->start_time = time (NULL);
|
||||
new_dcc->start_transfer = time (NULL);
|
||||
new_dcc->addr = addr;
|
||||
new_dcc->port = port;
|
||||
new_dcc->nick = strdup (nick);
|
||||
@@ -378,6 +417,9 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
|
||||
new_dcc->size = size;
|
||||
new_dcc->pos = 0;
|
||||
new_dcc->ack = 0;
|
||||
new_dcc->last_check_time = 0;
|
||||
new_dcc->last_check_pos = 0;
|
||||
new_dcc->bytes_per_sec = 0;
|
||||
new_dcc->prev_dcc = NULL;
|
||||
new_dcc->next_dcc = dcc_list;
|
||||
if (dcc_list)
|
||||
@@ -786,7 +828,7 @@ dcc_chat_recv (t_irc_dcc *ptr_dcc)
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_handle: receive/send data for each active DCC (files only)
|
||||
* dcc_handle: receive/send data for all active DCC
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -838,6 +880,7 @@ dcc_handle ()
|
||||
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
|
||||
ptr_dcc->status = DCC_ACTIVE;
|
||||
ptr_dcc->file = open (ptr_dcc->local_filename, O_RDONLY | O_NONBLOCK, 0644);
|
||||
ptr_dcc->start_transfer = time (NULL);
|
||||
dcc_redraw (1);
|
||||
}
|
||||
}
|
||||
@@ -921,6 +964,7 @@ dcc_handle ()
|
||||
ptr_dcc->pos += (unsigned long) num_read;
|
||||
pos = htonl (ptr_dcc->pos);
|
||||
send (ptr_dcc->sock, (char *) &pos, 4, 0);
|
||||
dcc_calculate_speed (ptr_dcc, 0);
|
||||
if (ptr_dcc->pos >= ptr_dcc->size)
|
||||
{
|
||||
dcc_close (ptr_dcc, DCC_DONE);
|
||||
@@ -987,6 +1031,7 @@ dcc_handle ()
|
||||
return;
|
||||
}
|
||||
ptr_dcc->pos += (unsigned long) num_sent;
|
||||
dcc_calculate_speed (ptr_dcc, 0);
|
||||
dcc_redraw (0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ struct t_irc_dcc
|
||||
int type; /* DCC type (send or receive) */
|
||||
int status; /* DCC status (waiting, sending, ..) */
|
||||
time_t start_time; /* the time when DCC started */
|
||||
time_t start_transfer; /* the time when DCC transfer started */
|
||||
unsigned long addr; /* IP address */
|
||||
int port; /* port */
|
||||
char *nick; /* remote nick */
|
||||
@@ -224,6 +225,9 @@ struct t_irc_dcc
|
||||
unsigned long size; /* file size */
|
||||
unsigned long pos; /* number of bytes received/sent */
|
||||
unsigned long ack; /* number of bytes received OK */
|
||||
time_t last_check_time; /* last time we looked at bytes sent/rcv*/
|
||||
unsigned long last_check_pos; /* bytes sent/recv at last check */
|
||||
unsigned long bytes_per_sec; /* bytes per second */
|
||||
t_irc_dcc *prev_dcc; /* link to previous dcc file/chat */
|
||||
t_irc_dcc *next_dcc; /* link to next dcc file/chat */
|
||||
};
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-04-19
|
||||
ChangeLog - 2005-04-23
|
||||
|
||||
|
||||
Version 0.1.2 (under dev!):
|
||||
* added transfer rate for DCC files
|
||||
* added "-all" option for /nick command
|
||||
* buffers timestamp can now be changed (new option in config file)
|
||||
* fixed crash when purging old DCC
|
||||
|
||||
@@ -765,6 +765,7 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_chat, ">");
|
||||
for (j = 0; j < 10 - num_bars; j++)
|
||||
wprintw (ptr_win->win_chat, " ");
|
||||
|
||||
if (ptr_dcc->size < 1024*10)
|
||||
num_unit = 0;
|
||||
else if (ptr_dcc->size < 1024*1024)
|
||||
@@ -779,20 +780,31 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
unit_format[num_unit],
|
||||
unit_format[num_unit]);
|
||||
wprintw (ptr_win->win_chat, format,
|
||||
((long double) ptr_dcc->pos) / ((long double)(unit_divide[num_unit])),
|
||||
((long double)(ptr_dcc->pos)) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit],
|
||||
((long double) ptr_dcc->size) / ((long double)(unit_divide[num_unit])),
|
||||
((long double)(ptr_dcc->size)) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit]);
|
||||
|
||||
if (ptr_dcc->bytes_per_sec < 1024*1024)
|
||||
num_unit = 1;
|
||||
else if (ptr_dcc->bytes_per_sec < 1024*1024*1024)
|
||||
num_unit = 2;
|
||||
else
|
||||
num_unit = 3;
|
||||
sprintf (format, " (%s %%s/s)", unit_format[num_unit]);
|
||||
wprintw (ptr_win->win_chat, format,
|
||||
((long double) ptr_dcc->bytes_per_sec) / ((long double)(unit_divide[num_unit])),
|
||||
unit_name[num_unit]);
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
}
|
||||
else
|
||||
{
|
||||
date_tmp = localtime (&(ptr_dcc->start_time));
|
||||
strftime (date, sizeof (date) - 1, "%a, %d %b %Y %H:%M:%S", date_tmp);
|
||||
wprintw (ptr_win->win_chat, " %s", date);
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
}
|
||||
|
||||
wclrtoeol (ptr_win->win_chat);
|
||||
|
||||
ptr_win->dcc_last_displayed = ptr_dcc;
|
||||
i += 2;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,40 @@ dcc_redraw (int highlight)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_calculate_speed: calculate DCC speed (for files only)
|
||||
*/
|
||||
|
||||
void
|
||||
dcc_calculate_speed (t_irc_dcc *ptr_dcc, int ended)
|
||||
{
|
||||
time_t local_time, elapsed;
|
||||
|
||||
local_time = time (NULL);
|
||||
if (ended || local_time > ptr_dcc->last_check_time)
|
||||
{
|
||||
|
||||
if (ended)
|
||||
{
|
||||
elapsed = local_time - ptr_dcc->start_transfer;
|
||||
if (elapsed == 0)
|
||||
elapsed = 1;
|
||||
ptr_dcc->bytes_per_sec = ptr_dcc->pos / elapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsed = local_time - ptr_dcc->last_check_time;
|
||||
if (elapsed == 0)
|
||||
elapsed = 1;
|
||||
ptr_dcc->bytes_per_sec = (ptr_dcc->pos - ptr_dcc->last_check_pos) / elapsed;
|
||||
}
|
||||
ptr_dcc->last_check_time = local_time;
|
||||
ptr_dcc->last_check_pos = ptr_dcc->pos;
|
||||
wee_log_printf ("bytes per sec calculé: %lu\n", ptr_dcc->bytes_per_sec);
|
||||
}
|
||||
wee_log_printf ("bytes per sec calculé pas bon !!!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_connect: connect to another host
|
||||
*/
|
||||
@@ -200,6 +234,9 @@ dcc_close (t_irc_dcc *ptr_dcc, int status)
|
||||
if (DCC_IS_CHAT(ptr_dcc->type))
|
||||
channel_remove_dcc (ptr_dcc);
|
||||
|
||||
if (DCC_IS_FILE(ptr_dcc->type))
|
||||
dcc_calculate_speed (ptr_dcc, 1);
|
||||
|
||||
if (ptr_dcc->sock != -1)
|
||||
{
|
||||
close (ptr_dcc->sock);
|
||||
@@ -327,6 +364,7 @@ dcc_accept (t_irc_dcc *ptr_dcc)
|
||||
ptr_dcc->file = open (ptr_dcc->local_filename,
|
||||
O_CREAT | O_TRUNC | O_WRONLY | O_NONBLOCK,
|
||||
0644);
|
||||
ptr_dcc->start_transfer = time (NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -363,6 +401,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
|
||||
new_dcc->type = type;
|
||||
new_dcc->status = DCC_WAITING;
|
||||
new_dcc->start_time = time (NULL);
|
||||
new_dcc->start_transfer = time (NULL);
|
||||
new_dcc->addr = addr;
|
||||
new_dcc->port = port;
|
||||
new_dcc->nick = strdup (nick);
|
||||
@@ -378,6 +417,9 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
|
||||
new_dcc->size = size;
|
||||
new_dcc->pos = 0;
|
||||
new_dcc->ack = 0;
|
||||
new_dcc->last_check_time = 0;
|
||||
new_dcc->last_check_pos = 0;
|
||||
new_dcc->bytes_per_sec = 0;
|
||||
new_dcc->prev_dcc = NULL;
|
||||
new_dcc->next_dcc = dcc_list;
|
||||
if (dcc_list)
|
||||
@@ -786,7 +828,7 @@ dcc_chat_recv (t_irc_dcc *ptr_dcc)
|
||||
}
|
||||
|
||||
/*
|
||||
* dcc_handle: receive/send data for each active DCC (files only)
|
||||
* dcc_handle: receive/send data for all active DCC
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -838,6 +880,7 @@ dcc_handle ()
|
||||
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
|
||||
ptr_dcc->status = DCC_ACTIVE;
|
||||
ptr_dcc->file = open (ptr_dcc->local_filename, O_RDONLY | O_NONBLOCK, 0644);
|
||||
ptr_dcc->start_transfer = time (NULL);
|
||||
dcc_redraw (1);
|
||||
}
|
||||
}
|
||||
@@ -921,6 +964,7 @@ dcc_handle ()
|
||||
ptr_dcc->pos += (unsigned long) num_read;
|
||||
pos = htonl (ptr_dcc->pos);
|
||||
send (ptr_dcc->sock, (char *) &pos, 4, 0);
|
||||
dcc_calculate_speed (ptr_dcc, 0);
|
||||
if (ptr_dcc->pos >= ptr_dcc->size)
|
||||
{
|
||||
dcc_close (ptr_dcc, DCC_DONE);
|
||||
@@ -987,6 +1031,7 @@ dcc_handle ()
|
||||
return;
|
||||
}
|
||||
ptr_dcc->pos += (unsigned long) num_sent;
|
||||
dcc_calculate_speed (ptr_dcc, 0);
|
||||
dcc_redraw (0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ struct t_irc_dcc
|
||||
int type; /* DCC type (send or receive) */
|
||||
int status; /* DCC status (waiting, sending, ..) */
|
||||
time_t start_time; /* the time when DCC started */
|
||||
time_t start_transfer; /* the time when DCC transfer started */
|
||||
unsigned long addr; /* IP address */
|
||||
int port; /* port */
|
||||
char *nick; /* remote nick */
|
||||
@@ -224,6 +225,9 @@ struct t_irc_dcc
|
||||
unsigned long size; /* file size */
|
||||
unsigned long pos; /* number of bytes received/sent */
|
||||
unsigned long ack; /* number of bytes received OK */
|
||||
time_t last_check_time; /* last time we looked at bytes sent/rcv*/
|
||||
unsigned long last_check_pos; /* bytes sent/recv at last check */
|
||||
unsigned long bytes_per_sec; /* bytes per second */
|
||||
t_irc_dcc *prev_dcc; /* link to previous dcc file/chat */
|
||||
t_irc_dcc *next_dcc; /* link to next dcc file/chat */
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user