... | ... |
@@ -208,7 +208,14 @@ void do_free() |
208 | 208 |
|
209 | 209 |
void do_recv() |
210 | 210 |
{ |
211 |
- mrecv(); |
|
211 |
+ mhost *t = members; |
|
212 |
+ while(mrecv()){ |
|
213 |
+ if(t){ |
|
214 |
+ t=t->next; |
|
215 |
+ }else{ |
|
216 |
+ break; |
|
217 |
+ } |
|
218 |
+ } |
|
212 | 219 |
} |
213 | 220 |
|
214 | 221 |
void do_send() |
... | ... |
@@ -274,6 +281,9 @@ int do_accept(mcomm *c, fd_set *fds) |
274 | 274 |
break; |
275 | 275 |
} |
276 | 276 |
c[i].working = 1; |
277 |
+ if(fcntl(c[i].fd[0], F_SETFL , O_NONBLOCK)){ |
|
278 |
+ lprintf(0, "[error] %s: fcntl: %s\n", __func__, strerror(errno)); |
|
279 |
+ } |
|
277 | 280 |
return(0); |
278 | 281 |
} |
279 | 282 |
|
... | ... |
@@ -179,19 +179,46 @@ void lprintf(int l, char *fmt, ...) |
179 | 179 |
|
180 | 180 |
void cprintf(int l, mcomm *c, char *fmt, ...) |
181 | 181 |
{ |
182 |
+ int r; |
|
183 |
+ int n; |
|
184 |
+ fd_set wfds; |
|
185 |
+ struct timeval tv; |
|
182 | 186 |
char m[2048]; |
183 | 187 |
va_list arg; |
184 |
- if(!c) |
|
188 |
+ if(!c){ |
|
185 | 189 |
return; |
186 |
- if(c->fd[0] == -1) |
|
190 |
+ } |
|
191 |
+ if(c->fd[0] == -1){ |
|
187 | 192 |
return; |
188 |
- if(c->loglevel >= l){ |
|
189 |
- va_start(arg, fmt); |
|
190 |
- vsnprintf(m, sizeof(m), fmt, arg); |
|
191 |
- va_end(arg); |
|
192 |
- m[sizeof(m) - 1] = 0; |
|
193 |
- write(c->fd[0], m, strlen(m)); |
|
194 |
- fsync(c->fd[0]); |
|
193 |
+ } |
|
194 |
+ if(c->loglevel < l){ |
|
195 |
+ return; |
|
196 |
+ } |
|
197 |
+ va_start(arg, fmt); |
|
198 |
+ vsnprintf(m, sizeof(m), fmt, arg); |
|
199 |
+ va_end(arg); |
|
200 |
+ m[sizeof(m) - 1] = 0; |
|
201 |
+ FD_ZERO(&wfds); |
|
202 |
+ FD_SET(c->fd[0], &wfds); |
|
203 |
+ tv.tv_sec = 0; |
|
204 |
+ tv.tv_usec = 100000; |
|
205 |
+ if(select(1024, NULL, &wfds, NULL, &tv) <= 0){ |
|
206 |
+ c->logover++; |
|
207 |
+ lprintf(0, "[error] %s: client busy: %s", __func__, m); |
|
208 |
+ }else{ |
|
209 |
+ n = strlen(m); |
|
210 |
+ r = write(c->fd[0], m, n); |
|
211 |
+ if(r == -1){ |
|
212 |
+ c->logover++; |
|
213 |
+ lprintf(0, "[error] %s: write: %s fd=%d", __func__, strerror(errno), c->fd[0]); |
|
214 |
+ }else{ |
|
215 |
+ if(r < n){ |
|
216 |
+ c->logover++; |
|
217 |
+ lprintf(0, "[error] %s: over fllow: %s", __func__, m); |
|
218 |
+ }else{ |
|
219 |
+ fsync(c->fd[0]); |
|
220 |
+ } |
|
221 |
+ } |
|
195 | 222 |
} |
196 | 223 |
} |
197 | 224 |
|