Rev 8195 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8195 | Rev 8849 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | if(answerlen<0) l=strlen(textbuf); else l=answerlen; |
43 | if(answerlen<0) l=strlen(textbuf); else l=answerlen; |
44 | ip=(int *) commbuf; *ip=l; |
44 | ip=(int *) commbuf; *ip=l; |
45 | (void)write(fh,commbuf,l+sizeof(int)); |
45 | (void)write(fh,commbuf,l+sizeof(int)); |
46 | close(fh); |
46 | close(fh); |
47 | if(debugging) { |
47 | if(debugging) { |
48 |
|
48 | if(textbuf[0]=='O') debug("%.2s %d bytes.",textbuf,l); |
49 |
|
49 | else debug("%s",textbuf); |
50 | } |
50 | } |
51 | } |
51 | } |
52 | 52 | ||
53 | void sockerror(int type, char *p,...) |
53 | void sockerror(int type, char *p,...) |
54 | { |
54 | { |
Line 69... | Line 69... | ||
69 | void answer(int fh) |
69 | void answer(int fh) |
70 | { |
70 | { |
71 | int t,l, *ip; |
71 | int t,l, *ip; |
72 | 72 | ||
73 | t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) { |
73 | t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) { |
74 |
|
74 | bad: sockerror(3,"Daemon socket read error."); |
75 |
|
75 | goto end; |
76 | } |
76 | } |
77 | ip=(int *) commbuf; l=*ip; |
77 | ip=(int *) commbuf; l=*ip; |
78 | if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad; |
78 | if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad; |
79 | while(t<l+sizeof(int)) { |
79 | while(t<l+sizeof(int)) { |
80 |
|
80 | struct timeval tv; |
81 |
|
81 | fd_set rset; |
82 |
|
82 | int t2; |
83 |
|
83 | tv.tv_sec=0; tv.tv_usec=20*1000; |
84 |
|
84 | FD_ZERO(&rset); FD_SET(fh,&rset); |
85 |
|
85 | if(select(fh+1,&rset,NULL,NULL,&tv)<=0) goto bad; |
86 |
|
86 | t2=read(fh,commbuf+t,l+sizeof(int)-t); |
87 |
|
87 | if(t2<=0 || t2>l+sizeof(int)-t) goto bad; |
88 |
|
88 | t+=t2; |
89 | } |
89 | } |
90 | textbuf[l]=0; textptr=textbuf; |
90 | textbuf[l]=0; textptr=textbuf; |
91 | answerlen=-1; |
91 | answerlen=-1; |
92 | if(debugging) debug("> %s",textbuf); |
92 | if(debugging) debug("> %s",textbuf); |
93 | if(options()>=0) cmd(); |
93 | if(options()>=0) cmd(); |