1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 01:25:42 +02:00

Fix data sent to callback of hook_process, improve hook_process by using buffer

Fix: some data was sometimes missing (not sent to callback).
Improvement: use a 64KB buffer for child output and send data to callback only
when buffer is full.
This commit is contained in:
Sebastien Helleu
2010-11-14 16:22:31 +01:00
parent 2f45cbfb02
commit 4d1c9a8315
6 changed files with 203 additions and 82 deletions
+4 -1
View File
@@ -1,12 +1,15 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.3.4-dev, 2010-11-12
v0.3.4-dev, 2010-11-14
Version 0.3.4 (under dev!)
--------------------------
* core: fix data sent to callback of hook_process (some data was sometimes
missing), use a 64KB buffer for child output and send data to callback only
when buffer is full
* core: fix crash when displaying groups in buffer nicklist
* core: fix bug with message "day changed to", sometimes displayed several
times wrongly
+11
View File
@@ -6165,6 +6165,17 @@ Return value:
* pointer to new hook, NULL if error occured
[NOTE]
Buffer size for sending data to callback is 64KB (there are 2 buffers: one for
stdout and one for stderr).
If output from child process (stdout or stderr) is longer than 64KB, callback
will be called more than one time.
[IMPORTANT]
Even if most of times your callback is called only once, you must ensure that
many calls to callback are ok in your code: you must concatenate data issued by
many calls and use data only when return code is nonnegative.
C example:
[source,C]
+12
View File
@@ -6242,6 +6242,18 @@ Valeur de retour :
* pointeur vers le nouveau "hook", NULL en cas d'erreur
[NOTE]
La taille du tampon pour l'envoi des données au "callback" est de 64 Ko (il y a
2 tampons: un pour stdout et un pour stderr).
Si la sortie du processus fils (stdout ou stderr) est plus longue que 64 Ko, le
"callback" sera appelé plusieurs fois.
[IMPORTANT]
Même si la plupart du temps le "callback" n'est appelé qu'une seule fois, vous
devez vous assurer que plusieurs appels au "callback" sont ok dans votre code :
vous devez concaténer les données issues de plusieurs appels et n'utiliser les
données que lorsque le code retour est positif ou nul.
Exemple en C :
[source,C]
+13
View File
@@ -6217,6 +6217,19 @@ Valore restituito:
* puntatore al nuovo hook, NULL in caso di errore
// TRANSLATION MISSING
[NOTE]
Buffer size for sending data to callback is 64KB (there are 2 buffers: one for
stdout and one for stderr).
If output from child process (stdout or stderr) is longer than 64KB, callback
will be called more than one time.
// TRANSLATION MISSING
[IMPORTANT]
Even if most of times your callback is called only once, you must ensure that
many calls to callback are ok in your code: you must concatenate data issued by
many calls and use data only when return code is nonnegative.
Esempio in C:
[source,C]
+153 -75
View File
File diff suppressed because it is too large Load Diff
+10 -6
View File
@@ -68,6 +68,11 @@ enum t_hook_type
#define HOOK_FD_FLAG_WRITE 2
#define HOOK_FD_FLAG_EXCEPTION 4
/* constants for hook process */
#define HOOK_PROCESS_STDOUT 0
#define HOOK_PROCESS_STDERR 1
#define HOOK_PROCESS_BUFFER_SIZE 65536
/* macros to access hook specific data */
#define HOOK_COMMAND(hook, var) (((struct t_hook_command *)hook->hook_data)->var)
#define HOOK_COMMAND_RUN(hook, var) (((struct t_hook_command_run *)hook->hook_data)->var)
@@ -180,14 +185,13 @@ struct t_hook_process
t_hook_callback_process *callback; /* process callback (after child end)*/
char *command; /* command executed by child */
long timeout; /* timeout (ms) (0 = no timeout) */
int child_stdout_read; /* to read data in pipe from child */
int child_stdout_write; /* to write data in pipe for child */
int child_stderr_read; /* to read data in pipe from child */
int child_stderr_write; /* to write data in pipe for child */
int child_read[2]; /* to read data in pipe from child */
int child_write[2]; /* to write data in pipe for child */
pid_t child_pid; /* pid of child process */
struct t_hook *hook_fd_stdout; /* hook fd for stdout */
struct t_hook *hook_fd_stderr; /* hook fd for stderr */
struct t_hook *hook_fd[2]; /* hook fd for stdout/stderr */
struct t_hook *hook_timer; /* timer to check if child has died */
char *buffer[2]; /* buffers for child stdout/stderr */
int buffer_size[2]; /* size of child stdout/stderr */
};
/* hook connect */