[lwatch-cvs] files/src control.c,1.3,1.4 control.h,1.4,1.5 lwatch.c,1.7,1.8
Brought to you by:
arturcz
|
From: <ar...@us...> - 2002-06-29 15:04:40
|
Update of /cvsroot/lwatch/files/src
In directory usw-pr-cvs1:/tmp/cvs-serv26084
Modified Files:
control.c control.h lwatch.c
Log Message:
Detect end of input data.
Better error messages.
Index: control.c
===================================================================
RCS file: /cvsroot/lwatch/files/src/control.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** control.c 29 Jun 2002 13:44:57 -0000 1.3
--- control.c 29 Jun 2002 15:04:37 -0000 1.4
***************
*** 35,38 ****
--- 35,40 ----
#include <stdlib.h>
+ #include <sys/poll.h>
+
#include "control.h"
***************
*** 67,68 ****
--- 69,82 ----
}
}
+
+ #ifdef DEBUG
+ void show_poll_res(int res, struct pollfd *ufds, int n) {
+ int i;
+ i=0;
+ while(i<n) {
+ printf("fd: %i res: %i\n",ufds[i].fd,res);
+ printf("watch: %i\n",ufds[i].events);
+ printf("return: %i\n",ufds[i++].revents);
+ }
+ }
+ #endif
Index: control.h
===================================================================
RCS file: /cvsroot/lwatch/files/src/control.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** control.h 29 Jun 2002 13:44:57 -0000 1.4
--- control.h 29 Jun 2002 15:04:37 -0000 1.5
***************
*** 34,44 ****
#include <string.h>
! #define io_check(res,str) if((res)==-1) die("%s[%i] %s\n",str,errno,strerror(errno))
! #define io_fcheck(res,str) if((res)==NULL) die("%s[%i] %s\n",str,errno,strerror(errno))
! #define sig_check(res,str) if((res)==SIG_ERR) die("%sCannot set signal handler\n",str);
void die(const char *s, ...);
void signal_handle(int i);
void set_handlers(void);
extern int loop;
--- 34,49 ----
#include <string.h>
! #include <sys/poll.h>
!
! #define io_check(res,str) if((res)==-1) die("%s%s[%i] %s\n",str,strlen(str)?": ":"",errno,strerror(errno))
! #define io_fcheck(res,str) if((res)==NULL) die("%s%s[%i] %s\n",str,strlen(str)?": ":"",errno,strerror(errno))
! #define sig_check(res,str) if((res)==SIG_ERR) die("%s%sCannot set signal handler\n",str,strlen(str)?": ":"");
void die(const char *s, ...);
void signal_handle(int i);
void set_handlers(void);
+ #ifdef DEBUG
+ void show_poll_res(int res, struct pollfd *ufds, int n);
+ #endif
extern int loop;
Index: lwatch.c
===================================================================
RCS file: /cvsroot/lwatch/files/src/lwatch.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** lwatch.c 29 Jun 2002 13:44:57 -0000 1.7
--- lwatch.c 29 Jun 2002 15:04:37 -0000 1.8
***************
*** 71,80 ****
pbuf=newstr("");
input.fd=fd;
! input.events=POLLIN;
while(loop) {
res=poll(&input,1,-1);
! if(errno!=EINTR) io_check(res,"poll: ");
if(res<1) continue;
! io_check(res=read(fd,(void*)rbuf,BUFSIZE),"read: ");
if(!res) continue;
rbuf[res]='\0';
--- 71,91 ----
pbuf=newstr("");
input.fd=fd;
! input.events=POLLIN|POLLHUP;
while(loop) {
+ input.revents=0;
res=poll(&input,1,-1);
! #ifdef DEBUG
! show_poll_res(res,&input,1);
! #endif
! if(errno!=EINTR) io_check(res,"poll");
! if(input.revents==POLLHUP) {
! loop=0; /* end of data */
! continue;
! }
if(res<1) continue;
! io_check(res=read(fd,(void*)rbuf,BUFSIZE),"read input");
! #ifdef DEBUG
! printf("Read %i byte(s)\n",res);
! #endif
if(!res) continue;
rbuf[res]='\0';
|