diff options
author | albeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-10-25 16:06:25 +0000 |
---|---|---|
committer | albeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-10-25 16:06:25 +0000 |
commit | f8ce5ab876fcc40b01785c873688dff14f994848 (patch) | |
tree | 45ce1f58c233ea67c894751d25ac9df929359914 /input | |
parent | 16fca14336977c21bebaaf0225b6adb89abec4d6 (diff) |
Reverse Arpi's commit and put the right fix in place.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7913 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'input')
-rw-r--r-- | input/input.c | 44 | ||||
-rw-r--r-- | input/input.h | 2 |
2 files changed, 32 insertions, 14 deletions
diff --git a/input/input.c b/input/input.c index 5bcaa04779..5b4d408a0d 100644 --- a/input/input.c +++ b/input/input.c @@ -343,6 +343,9 @@ static config_t mp_input_opts[] = { static int mp_input_default_key_func(int fd); +static int +mp_input_default_cmd_func(int fd,char* buf, int l); + static char* mp_input_get_key_name(int key); @@ -356,7 +359,7 @@ mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t)); cmd_fds[num_cmd_fd].fd = fd; - cmd_fds[num_cmd_fd].read_func = read_func ? read_func : (mp_cmd_func_t)read; + cmd_fds[num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func; cmd_fds[num_cmd_fd].close_func = close_func; if(!select) cmd_fds[num_cmd_fd].flags = MP_FD_NO_SELECT; @@ -542,8 +545,6 @@ static int mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { char* end; (*ret) = NULL; - - if(mp_fd->flags & MP_FD_DEAD) return MP_INPUT_NOTHING; // Allocate the buffer if it dont exist if(!mp_fd->buffer) { @@ -556,21 +557,19 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { while( !(mp_fd->flags & MP_FD_GOT_CMD) && !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) { int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos); // Error ? - if(r == MP_INPUT_NOTHING) break; if(r < 0) { - if(errno == EINTR) - continue; - else if(errno == EAGAIN) - break; - mp_msg(MSGT_INPUT,MSGL_WARN,"Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno)); - return r; // MP_INPUT_ERROR or MP_INPUT_DEAD + switch(r) { + case MP_INPUT_ERROR: + case MP_INPUT_DEAD: + mp_msg(MSGT_INPUT,MSGL_ERR,"Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno)); + case MP_INPUT_NOTHING: + return r; + } // EOF ? - } - if(r == 0) { + } else if(r == 0) { mp_fd->flags |= MP_FD_EOF; break; } - // r > 0 mp_fd->pos += r; break; } @@ -620,6 +619,25 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { return MP_INPUT_NOTHING; } +static int +mp_input_default_cmd_func(int fd,char* buf, int l) { + + while(1) { + int r = read(fd,buf,l); + // Error ? + if(r < 0) { + if(errno == EINTR) + continue; + else if(errno == EAGAIN) + return MP_INPUT_NOTHING; + return MP_INPUT_ERROR; + // EOF ? + } + return r; + } + +} + static char* mp_input_find_bind_for_key(mp_cmd_bind_t* binds, int n,int* keys) { int j; diff --git a/input/input.h b/input/input.h index 27a73e62d3..d03b6d5aa5 100644 --- a/input/input.h +++ b/input/input.h @@ -117,7 +117,7 @@ typedef struct mp_key_name { // These functions should return the key code or one of the error code typedef int (*mp_key_func_t)(int fd); -// These functions should act like read +// These functions should act like read but they must use our error code (if needed ;-) typedef int (*mp_cmd_func_t)(int fd,char* dest,int size); // These are used to close the driver typedef void (*mp_close_func_t)(int fd); |