Merge pull request #33 from Lindenk/bigger_blk_buffer

Increase buffer size to 4096 & omit clearing buffer using memset
This commit is contained in:
George Badawi 2016-03-26 19:56:32 +02:00
commit a40894b8f2
2 changed files with 26 additions and 11 deletions

View file

@ -22,11 +22,12 @@ static void ya_exec_redir_once(ya_block_t *blk) {
execl(yashell, yashell, "-c", blk->cmd, (char *) NULL); execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
else {
wait(NULL); ssize_t read_ret = read(opipe[0], blk->buf, BUFSIZE);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) { if (read_ret < 0) {
ya_draw_pango_text(blk); fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
} } else if (read_ret > 0) {
ya_draw_pango_text(blk);
} }
} }
@ -47,9 +48,12 @@ static void ya_exec_redir_period(ya_block_t *blk) {
blk->pid = pid; blk->pid = pid;
//close(opipe[1]); //close(opipe[1]);
wait(NULL); wait(NULL);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) { ssize_t read_ret = read(opipe[0], blk->buf, BUFSIZE);
if (read_ret < 0) {
fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
} else if (read_ret > 0) {
blk->buf[read_ret] = '\0';
ya_draw_pango_text(blk); ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
} }
sleep(blk->sleep); sleep(blk->sleep);
} }
@ -69,9 +73,19 @@ static void ya_exec_redir_persist(ya_block_t *blk) {
} }
blk->pid = pid; blk->pid = pid;
close(opipe[1]); close(opipe[1]);
while (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk); ssize_t read_ret;
memset(blk->buf, '\0', BUFSIZE); while (1) {
read_ret = read(opipe[0], blk->buf, BUFSIZE);
if(read_ret == 0) {
break;
} else if (read_ret < 0) {
fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
continue;
} else {
blk->buf[read_ret] = '\0';
ya_draw_pango_text(blk);
}
} }
} }

View file

@ -10,6 +10,7 @@
#define YABAR_H #define YABAR_H
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#define __USE_XOPEN2K //for setenv implicit function decleration warning #define __USE_XOPEN2K //for setenv implicit function decleration warning
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -39,7 +40,7 @@
extern char *strdup(const char *s); //to suppress implicit decleration warning for strdup extern char *strdup(const char *s); //to suppress implicit decleration warning for strdup
#define BUFSIZE 512 #define BUFSIZE 4096
#define CFILELEN 256 #define CFILELEN 256
#define YA_DEF_FONT "sans bold 9" #define YA_DEF_FONT "sans bold 9"