summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/console.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/plugins/console.c b/src/plugins/console.c
index 673a30e78..fc883a9f3 100644
--- a/src/plugins/console.c
+++ b/src/plugins/console.c
@@ -273,31 +273,27 @@ int input_final(void)
#define input_getstate() buf.state
/// Sets the state of the input
-void input_setstate(char state)
-{
- if( state == INPUT_READY && input_getstate() == INPUT_READING )
- {// send data from the worker to the main process
- write(buf.data_pipe[PIPE_WRITE], &buf.len, sizeof(buf.len));
- write(buf.data_pipe[PIPE_WRITE], &buf.arr, buf.len);
- } else if( state == INPUT_WAITING ){
- if( buf.close_unused_flag == 0 )
- {// close unused pipe sides in the main process
+void input_setstate(char state) {
+ size_t fileReadCount = 0;
+ if( state == INPUT_READY && input_getstate() == INPUT_READING ) {// send data from the worker to the main process
+ fileReadCount = write(buf.data_pipe[PIPE_WRITE], &buf.len, sizeof(buf.len));
+ fileReadCount = write(buf.data_pipe[PIPE_WRITE], &buf.arr, buf.len);
+ } else if( state == INPUT_WAITING ) {
+ if( buf.close_unused_flag == 0 ) {// close unused pipe sides in the main process
close(buf.data_pipe[PIPE_WRITE]);
close(buf.state_pipe[PIPE_READ]);
buf.close_unused_flag = 1;
}
// send the next state
- write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
- } else if( state == INPUT_READING ){
- if( buf.close_unused_flag == 0 )
- {// close unused pipe sides in the worker process
+ fileReadCount = write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
+ } else if( state == INPUT_READING ) {
+ if( buf.close_unused_flag == 0 ) {// close unused pipe sides in the worker process
close(buf.data_pipe[PIPE_READ]);
close(buf.state_pipe[PIPE_WRITE]);
buf.close_unused_flag = 1;
}
- } else if( state == INPUT_CLOSED )
- {// send next state to the worker and close the pipes
- write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
+ } else if( state == INPUT_CLOSED ) {// send next state to the worker and close the pipes
+ fileReadCount = write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
close(buf.data_pipe[PIPE_WRITE]);
close(buf.data_pipe[PIPE_READ]);
close(buf.state_pipe[PIPE_WRITE]);
@@ -327,9 +323,10 @@ int input_hasdata()
{
struct pollfd fds;
int hasData;
-
- if( input_getstate() == INPUT_READY )
- {// start getting data
+ size_t fileReadCount;
+
+
+ if( input_getstate() == INPUT_READY ) {// start getting data
input_setstate(INPUT_WAITING);
return 0;
}
@@ -337,10 +334,9 @@ int input_hasdata()
fds.fd = buf.data_pipe[PIPE_READ];
fds.events = POLLRDNORM;
hasData = ( poll(&fds,1,0) > 0 );
- if( hasData )
- {// read the data from the pipe
- read(buf.data_pipe[PIPE_READ], &buf.len, sizeof(buf.len));
- read(buf.data_pipe[PIPE_READ], buf.arr, buf.len);
+ if( hasData ) {// read the data from the pipe
+ fileReadCount = read(buf.data_pipe[PIPE_READ], &buf.len, sizeof(buf.len));
+ fileReadCount = read(buf.data_pipe[PIPE_READ], buf.arr, buf.len);
input_setstate(INPUT_READY);
}
@@ -405,8 +401,8 @@ WORKER_FUNC_START(getinput)
{// get input
input_setstate(INPUT_READING);
buf.arr[0] = '\0';
- fgets(buf.arr, INPUT_BUFSIZE, stdin);
- buf.len = strlen(buf.arr);
+ if( fgets(buf.arr, INPUT_BUFSIZE, stdin) != NULL )
+ buf.len = strlen(buf.arr);
input_setstate(INPUT_READY);
}
WORKER_FUNC_END(getinput)