comparison recpt1/recpt1.c @ 139:61ff9cabf962

fix for split buffer shortage
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 25 Apr 2013 15:08:35 +0900
parents 2b057f249811
children c9b1d21c5035
comparison
equal deleted inserted replaced
138:45b4afa656d2 139:61ff9cabf962
373 int code; 373 int code;
374 int split_select_finish = TSS_ERROR; 374 int split_select_finish = TSS_ERROR;
375 375
376 buf.size = 0; 376 buf.size = 0;
377 buf.data = NULL; 377 buf.data = NULL;
378 splitbuf.size = 0; 378 splitbuf.buffer_size = 0;
379 splitbuf.buffer = NULL;
379 380
380 if(wfd == -1) 381 if(wfd == -1)
381 fileless = TRUE; 382 fileless = TRUE;
382 383
383 if(use_udp) { 384 if(use_udp) {
409 buf = dbuf; 410 buf = dbuf;
410 } 411 }
411 412
412 413
413 if(use_splitter) { 414 if(use_splitter) {
414 splitbuf.size = 0; 415 splitbuf.buffer_filled = 0;
416
417 /* allocate split buffer */
418 if(splitbuf.buffer_size < buf.size && buf.size > 0) {
419 splitbuf.buffer = realloc(splitbuf.buffer, buf.size);
420 if(splitbuf.buffer == NULL) {
421 fprintf(stderr, "split buffer allocation failed\n");
422 use_splitter = FALSE;
423 goto fin;
424 }
425 }
415 426
416 while(buf.size) { 427 while(buf.size) {
417 /* $BJ,N%BP>](BPID$B$NCj=P(B */ 428 /* $BJ,N%BP>](BPID$B$NCj=P(B */
418 if(split_select_finish != TSS_SUCCESS) { 429 if(split_select_finish != TSS_SUCCESS) {
419 split_select_finish = split_select(splitter, &buf); 430 split_select_finish = split_select(splitter, &buf);
434 goto fin; 445 goto fin;
435 } 446 }
436 break; 447 break;
437 } 448 }
438 } 449 }
450
439 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ 451 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
440 code = split_ts(splitter, &buf, &splitbuf); 452 code = split_ts(splitter, &buf, &splitbuf);
441 if(code == TSS_NULL) { 453 if(code == TSS_NULL) {
442 fprintf(stderr, "PMT reading..\n"); 454 fprintf(stderr, "PMT reading..\n");
443 } 455 }
447 } 459 }
448 460
449 break; 461 break;
450 } /* while */ 462 } /* while */
451 463
452 buf.size = splitbuf.size; 464 buf.size = splitbuf.buffer_filled;
453 buf.data = splitbuf.buffer; 465 buf.data = splitbuf.buffer;
454 fin: 466 fin:
455 ; 467 ;
456 } /* if */ 468 } /* if */
457 469
521 fprintf(stderr, "split_ts failed\n"); 533 fprintf(stderr, "split_ts failed\n");
522 break; 534 break;
523 } 535 }
524 536
525 buf.data = splitbuf.buffer; 537 buf.data = splitbuf.buffer;
526 buf.size = splitbuf.size; 538 buf.size = splitbuf.buffer_size;
527 } 539 }
528 540
529 if(!fileless && !file_err) { 541 if(!fileless && !file_err) {
530 wc = write(wfd, buf.data, buf.size); 542 wc = write(wfd, buf.data, buf.size);
531 if(wc < 0) { 543 if(wc < 0) {
540 wc = write(sfd, buf.data, buf.size); 552 wc = write(sfd, buf.data, buf.size);
541 if(wc < 0) { 553 if(wc < 0) {
542 if(errno == EPIPE) 554 if(errno == EPIPE)
543 pthread_kill(signal_thread, SIGPIPE); 555 pthread_kill(signal_thread, SIGPIPE);
544 } 556 }
557 }
558
559 if(use_splitter) {
560 free(splitbuf.buffer);
561 splitbuf.buffer = NULL;
562 splitbuf.buffer_size = 0;
545 } 563 }
546 564
547 break; 565 break;
548 } 566 }
549 } 567 }