diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-03-21 18:11:21 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-03-21 18:11:21 +0100 |
commit | cf6aca1619c32422a43fa3d82e0674f6b7b49fe9 (patch) | |
tree | 65392ef12eab877f544fe306fe0abb98214ddebd /src/plugins/xfer/xfer-network.c | |
parent | 6d764b64c50adb19309a9de14bfeafac648ab47a (diff) | |
download | weechat-cf6aca1619c32422a43fa3d82e0674f6b7b49fe9.zip |
core: add pointer in some callbacks (closes #406)
This pointer is the first argument received by callbacks, and the
existing argument "data" is now automatically freed by WeeChat when the
object containing the callback is removed.
With this new pointer, the linked list of callbacks in scripts has been
removed. This will improve speed of scripts (using a lot of hooks),
reduce memory used by scripts and reduce time to unload scripts.
Following functions are affected in the C API:
* exec_on_files
* config_new
* config_new_section
* config_new_option
* hook_command
* hook_command_run
* hook_timer
* hook_fd
* hook_process
* hook_process_hashtable
* hook_connect
* hook_print
* hook_signal
* hook_hsignal
* hook_config
* hook_completion
* hook_modifier
* hook_info
* hook_info_hashtable
* hook_infolist
* hook_hdata
* hook_focus
* unhook_all_plugin
* buffer_new
* bar_item_new
* upgrade_new
* upgrade_read
Diffstat (limited to 'src/plugins/xfer/xfer-network.c')
-rw-r--r-- | src/plugins/xfer/xfer-network.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c index d536b4fb4..f52345dee 100644 --- a/src/plugins/xfer/xfer-network.c +++ b/src/plugins/xfer/xfer-network.c @@ -93,16 +93,17 @@ xfer_network_write_pipe (struct t_xfer *xfer, int status, int error) */ int -xfer_network_child_read_cb (void *arg_xfer, int fd) +xfer_network_child_read_cb (const void *pointer, void *data, int fd) { struct t_xfer *xfer; char bufpipe[1 + 1 + 32 + 1]; int num_read; /* make C compiler happy */ + (void) data; (void) fd; - xfer = (struct t_xfer *)arg_xfer; + xfer = (struct t_xfer *)pointer; num_read = read (xfer->child_read, bufpipe, sizeof (bufpipe)); if (num_read > 0) @@ -270,7 +271,7 @@ xfer_network_send_file_fork (struct t_xfer *xfer) xfer->hook_fd = weechat_hook_fd (xfer->child_read, 1, 0, 0, &xfer_network_child_read_cb, - xfer); + xfer, NULL); } /* @@ -328,7 +329,7 @@ xfer_network_recv_file_fork (struct t_xfer *xfer) xfer->hook_fd = weechat_hook_fd (xfer->child_read, 1, 0, 0, &xfer_network_child_read_cb, - xfer); + xfer, NULL); } /* @@ -364,7 +365,7 @@ xfer_network_child_kill (struct t_xfer *xfer) */ int -xfer_network_fd_cb (void *arg_xfer, int fd) +xfer_network_fd_cb (const void *pointer, void *data, int fd) { struct t_xfer *xfer; int sock, flags, error; @@ -373,11 +374,12 @@ xfer_network_fd_cb (void *arg_xfer, int fd) char str_address[NI_MAXHOST]; /* make C compiler happy */ + (void) data; (void) fd; length = sizeof (addr); memset (&addr, 0, length); - xfer = (struct t_xfer *)arg_xfer; + xfer = (struct t_xfer *)pointer; if (xfer->status == XFER_STATUS_CONNECTING) { @@ -484,7 +486,7 @@ xfer_network_fd_cb (void *arg_xfer, int fd) xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_chat_recv_cb, - xfer); + xfer, NULL); xfer_chat_open_buffer (xfer); } } @@ -498,14 +500,15 @@ xfer_network_fd_cb (void *arg_xfer, int fd) */ int -xfer_network_timer_cb (void *arg_xfer, int remaining_calls) +xfer_network_timer_cb (const void *pointer, void *data, int remaining_calls) { struct t_xfer *xfer; /* make C compiler happy */ + (void) data; (void) remaining_calls; - xfer = (struct t_xfer *)arg_xfer; + xfer = (struct t_xfer *)pointer; if ((xfer->status == XFER_STATUS_WAITING) || (xfer->status == XFER_STATUS_CONNECTING)) @@ -526,7 +529,8 @@ xfer_network_timer_cb (void *arg_xfer, int remaining_calls) */ int -xfer_network_connect_chat_recv_cb (void *data, int status, int gnutls_rc, +xfer_network_connect_chat_recv_cb (const void *pointer, void *data, + int status, int gnutls_rc, int sock, const char *error, const char *ip_address) { @@ -534,10 +538,11 @@ xfer_network_connect_chat_recv_cb (void *data, int status, int gnutls_rc, int flags; /* make C compiler happy */ + (void) data; (void) gnutls_rc; (void) ip_address; - xfer = (struct t_xfer*)data; + xfer = (struct t_xfer*)pointer; weechat_unhook (xfer->hook_connect); xfer->hook_connect = NULL; @@ -567,7 +572,7 @@ xfer_network_connect_chat_recv_cb (void *data, int status, int gnutls_rc, xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_chat_recv_cb, - xfer); + xfer, NULL); xfer_chat_open_buffer (xfer); xfer->status = XFER_STATUS_ACTIVE; @@ -691,7 +696,7 @@ xfer_network_connect (struct t_xfer *xfer) xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_network_fd_cb, - xfer); + xfer, NULL); /* add timeout */ if (weechat_config_integer (xfer_config_network_timeout) > 0) @@ -699,7 +704,7 @@ xfer_network_connect (struct t_xfer *xfer) xfer->hook_timer = weechat_hook_timer (weechat_config_integer (xfer_config_network_timeout) * 1000, 0, 1, &xfer_network_timer_cb, - xfer); + xfer, NULL); } } @@ -711,7 +716,7 @@ xfer_network_connect (struct t_xfer *xfer) xfer->port, 1, 0, NULL, NULL, 0, "NONE", NULL, &xfer_network_connect_chat_recv_cb, - xfer); + xfer, NULL); } /* for file receiving, connection is made in child process (blocking) */ |