Mercurial > pt1.oyama
comparison recpt1/recpt1.c @ 39:b03685d25fee
recpt1 now shows error explanation when write() fails.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 17 Apr 2009 22:52:35 +0900 |
parents | 3228f5cde349 |
children | a35e352f6c4a |
comparison
equal
deleted
inserted
replaced
38:3228f5cde349 | 39:b03685d25fee |
---|---|
206 addr = &data->sock_data->addr; | 206 addr = &data->sock_data->addr; |
207 } | 207 } |
208 | 208 |
209 while(1) { | 209 while(1) { |
210 ssize_t wc = 0; | 210 ssize_t wc = 0; |
211 int file_err = 0; | |
211 qbuf = dequeue(p_queue); | 212 qbuf = dequeue(p_queue); |
212 /* no entry in the queue */ | 213 /* no entry in the queue */ |
213 if(qbuf == NULL) { | 214 if(qbuf == NULL) { |
214 break; | 215 break; |
215 } | 216 } |
233 int offset = 0; | 234 int offset = 0; |
234 while(size_remain > 0) { | 235 while(size_remain > 0) { |
235 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; | 236 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; |
236 wc = write(wfd, buf.data + offset, ws); | 237 wc = write(wfd, buf.data + offset, ws); |
237 if(wc < 0) { | 238 if(wc < 0) { |
238 if(errno == EPIPE) | 239 perror("write"); |
239 pthread_kill(signal_thread, SIGPIPE); | 240 file_err = 1; |
240 else | 241 pthread_kill(signal_thread, |
241 pthread_kill(signal_thread, SIGUSR2); | 242 errno == EPIPE ? SIGPIPE : SIGUSR2); |
242 break; | 243 break; |
243 } | 244 } |
244 size_remain -= wc; | 245 size_remain -= wc; |
245 offset += wc; | 246 offset += wc; |
246 } | 247 } |
264 } | 265 } |
265 | 266 |
266 free(qbuf); | 267 free(qbuf); |
267 | 268 |
268 /* normal exit */ | 269 /* normal exit */ |
269 if((f_exit) && (!p_queue->num_used)) { | 270 if(f_exit && !p_queue->num_used && !file_err) { |
270 | 271 |
271 buf = sbuf; /* default */ | 272 buf = sbuf; /* default */ |
272 | 273 |
273 if(use_b25) { | 274 if(use_b25) { |
274 code = b25_finish(dec, &sbuf, &dbuf); | 275 code = b25_finish(dec, &sbuf, &dbuf); |
279 } | 280 } |
280 | 281 |
281 if(!fileless) { | 282 if(!fileless) { |
282 wc = write(wfd, buf.data, buf.size); | 283 wc = write(wfd, buf.data, buf.size); |
283 if(wc < 0) { | 284 if(wc < 0) { |
284 if(errno == EPIPE) | 285 perror("write"); |
285 pthread_kill(signal_thread, SIGPIPE); | 286 file_err = 1; |
286 else | 287 pthread_kill(signal_thread, |
287 pthread_kill(signal_thread, SIGUSR2); | 288 errno == EPIPE ? SIGPIPE : SIGUSR2); |
288 } | 289 } |
289 } | 290 } |
290 | 291 |
291 if(use_udp && sfd != -1) { | 292 if(use_udp && sfd != -1) { |
292 wc = write(sfd, buf.data, buf.size); | 293 wc = write(sfd, buf.data, buf.size); |
474 break; | 475 break; |
475 case SIGUSR1: /* normal exit*/ | 476 case SIGUSR1: /* normal exit*/ |
476 cleanup(sdata); | 477 cleanup(sdata); |
477 break; | 478 break; |
478 case SIGUSR2: /* error */ | 479 case SIGUSR2: /* error */ |
479 fprintf(stderr, "\nSomething is wrong. cleaning up...\n"); | 480 fprintf(stderr, "Detected an error. cleaning up...\n"); |
480 cleanup(sdata); | 481 cleanup(sdata); |
481 break; | 482 break; |
482 } | 483 } |
483 | 484 |
484 return NULL; /* dummy */ | 485 return NULL; /* dummy */ |