diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2018-12-09 16:09:03 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2018-12-09 18:51:50 +0300 |
commit | 4b5e8e0b45cde5f80f160d1abd42e604503b3544 (patch) | |
tree | 41468ecbf92a462a8d1b6e66927859ce9a1eeb79 | |
parent | 1616caa17764c878bc18c6344a0f7f60b2cb596c (diff) | |
download | libmicrohttpd-4b5e8e0b45cde5f80f160d1abd42e604503b3544.tar.gz libmicrohttpd-4b5e8e0b45cde5f80f160d1abd42e604503b3544.zip |
connection.c: updated connection buffer control function to use
bool as return value. No change in processing logic.
-rw-r--r-- | src/microhttpd/connection.c | 106 |
1 files changed, 49 insertions, 57 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 542c5a40..4d2f49b5 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -472,16 +472,16 @@ sendfile_adapter (struct MHD_Connection *connection) | |||
472 | * buffering. | 472 | * buffering. |
473 | * | 473 | * |
474 | * @param connection connection to check | 474 | * @param connection connection to check |
475 | * @return #MHD_YES if force push is possible, #MHD_NO otherwise | 475 | * @return true if force push is possible, false otherwise |
476 | */ | 476 | */ |
477 | static int | 477 | _MHD_static_inline bool |
478 | socket_flush_possible(struct MHD_Connection *connection) | 478 | socket_flush_possible(struct MHD_Connection *connection) |
479 | { | 479 | { |
480 | (void)connection; /* Mute compiler warning. */ | 480 | (void)connection; /* Mute compiler warning. */ |
481 | #if defined(TCP_CORK) || defined(TCP_PUSH) | 481 | #if defined(TCP_CORK) || defined(TCP_PUSH) |
482 | return MHD_YES; | 482 | return true; |
483 | #else /* !TCP_CORK && !TCP_PUSH */ | 483 | #else /* !TCP_CORK && !TCP_PUSH */ |
484 | return MHD_NO; | 484 | return false; |
485 | #endif /* !TCP_CORK && !TCP_PUSH */ | 485 | #endif /* !TCP_CORK && !TCP_PUSH */ |
486 | } | 486 | } |
487 | 487 | ||
@@ -491,12 +491,12 @@ socket_flush_possible(struct MHD_Connection *connection) | |||
491 | * sending of partial packets. | 491 | * sending of partial packets. |
492 | * | 492 | * |
493 | * @param connection connection to be processed | 493 | * @param connection connection to be processed |
494 | * @return #MHD_YES on success, #MHD_NO otherwise | 494 | * @return true on success, false otherwise |
495 | */ | 495 | */ |
496 | static int | 496 | _MHD_static_inline bool |
497 | socket_start_extra_buffering (struct MHD_Connection *connection) | 497 | socket_start_extra_buffering (struct MHD_Connection *connection) |
498 | { | 498 | { |
499 | int res = MHD_NO; | 499 | bool res = false; |
500 | #if defined(TCP_CORK) || defined(TCP_NOPUSH) | 500 | #if defined(TCP_CORK) || defined(TCP_NOPUSH) |
501 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 501 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
502 | #if defined(TCP_NODELAY) | 502 | #if defined(TCP_NODELAY) |
@@ -511,17 +511,15 @@ socket_start_extra_buffering (struct MHD_Connection *connection) | |||
511 | IPPROTO_TCP, | 511 | IPPROTO_TCP, |
512 | TCP_NOPUSH, | 512 | TCP_NOPUSH, |
513 | (const void *) &on_val, | 513 | (const void *) &on_val, |
514 | sizeof (on_val))) | 514 | sizeof (on_val))); |
515 | ? MHD_YES : MHD_NO; | ||
516 | #if defined(TCP_NODELAY) | 515 | #if defined(TCP_NODELAY) |
517 | /* Enable Nagle's algorithm */ | 516 | /* Enable Nagle's algorithm */ |
518 | /* TCP_NODELAY may interfere with TCP_NOPUSH */ | 517 | /* TCP_NODELAY may interfere with TCP_NOPUSH */ |
519 | res &= (0 == setsockopt (connection->socket_fd, | 518 | res = (0 == setsockopt (connection->socket_fd, |
520 | IPPROTO_TCP, | 519 | IPPROTO_TCP, |
521 | TCP_NODELAY, | 520 | TCP_NODELAY, |
522 | (const void *) &off_val, | 521 | (const void *) &off_val, |
523 | sizeof (off_val))) | 522 | sizeof (off_val))) && res; |
524 | ? MHD_YES : MHD_NO; | ||
525 | #endif /* TCP_NODELAY */ | 523 | #endif /* TCP_NODELAY */ |
526 | #else /* TCP_CORK */ | 524 | #else /* TCP_CORK */ |
527 | #if defined(TCP_NODELAY) | 525 | #if defined(TCP_NODELAY) |
@@ -539,8 +537,7 @@ socket_start_extra_buffering (struct MHD_Connection *connection) | |||
539 | IPPROTO_TCP, | 537 | IPPROTO_TCP, |
540 | TCP_CORK, | 538 | TCP_CORK, |
541 | (const void *) &on_val, | 539 | (const void *) &on_val, |
542 | sizeof (on_val))) | 540 | sizeof (on_val))); |
543 | ? MHD_YES : MHD_NO; | ||
544 | #endif /* TCP_CORK */ | 541 | #endif /* TCP_CORK */ |
545 | #endif /* TCP_CORK || TCP_NOPUSH */ | 542 | #endif /* TCP_CORK || TCP_NOPUSH */ |
546 | return res; | 543 | return res; |
@@ -551,13 +548,13 @@ socket_start_extra_buffering (struct MHD_Connection *connection) | |||
551 | * Activate no buffering mode (no delay sending) on connection socket. | 548 | * Activate no buffering mode (no delay sending) on connection socket. |
552 | * | 549 | * |
553 | * @param connection connection to be processed | 550 | * @param connection connection to be processed |
554 | * @return #MHD_YES on success, #MHD_NO otherwise | 551 | * @return true on success, false otherwise |
555 | */ | 552 | */ |
556 | static int | 553 | _MHD_static_inline bool |
557 | socket_start_no_buffering (struct MHD_Connection *connection) | 554 | socket_start_no_buffering (struct MHD_Connection *connection) |
558 | { | 555 | { |
559 | #if defined(TCP_NODELAY) | 556 | #if defined(TCP_NODELAY) |
560 | int res = MHD_YES; | 557 | bool res = true; |
561 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 558 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
562 | #if defined(TCP_CORK) || defined(TCP_NOPUSH) | 559 | #if defined(TCP_CORK) || defined(TCP_NOPUSH) |
563 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 560 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
@@ -567,34 +564,31 @@ socket_start_no_buffering (struct MHD_Connection *connection) | |||
567 | mhd_assert(NULL != connection); | 564 | mhd_assert(NULL != connection); |
568 | #if defined(TCP_CORK) | 565 | #if defined(TCP_CORK) |
569 | /* Allow partial packets */ | 566 | /* Allow partial packets */ |
570 | res &= (0 == setsockopt (connection->socket_fd, | 567 | res = (0 == setsockopt (connection->socket_fd, |
571 | IPPROTO_TCP, | 568 | IPPROTO_TCP, |
572 | TCP_CORK, | 569 | TCP_CORK, |
573 | (const void *) &off_val, | 570 | (const void *) &off_val, |
574 | sizeof (off_val))) | 571 | sizeof (off_val))) && res; |
575 | ? MHD_YES : MHD_NO; | ||
576 | #endif /* TCP_CORK */ | 572 | #endif /* TCP_CORK */ |
577 | #if defined(TCP_NODELAY) | 573 | #if defined(TCP_NODELAY) |
578 | /* Disable Nagle's algorithm for sending packets without delay */ | 574 | /* Disable Nagle's algorithm for sending packets without delay */ |
579 | res &= (0 == setsockopt (connection->socket_fd, | 575 | res = (0 == setsockopt (connection->socket_fd, |
580 | IPPROTO_TCP, | 576 | IPPROTO_TCP, |
581 | TCP_NODELAY, | 577 | TCP_NODELAY, |
582 | (const void *) &on_val, | 578 | (const void *) &on_val, |
583 | sizeof (on_val))) | 579 | sizeof (on_val))) && res; |
584 | ? MHD_YES : MHD_NO; | ||
585 | #endif /* TCP_NODELAY */ | 580 | #endif /* TCP_NODELAY */ |
586 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) | 581 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) |
587 | /* Disable extra buffering */ | 582 | /* Disable extra buffering */ |
588 | res &= (0 == setsockopt (connection->socket_fd, | 583 | res = (0 == setsockopt (connection->socket_fd, |
589 | IPPROTO_TCP, | 584 | IPPROTO_TCP, |
590 | TCP_NOPUSH, | 585 | TCP_NOPUSH, |
591 | (const void *) &off_val, | 586 | (const void *) &off_val, |
592 | sizeof (off_val))) | 587 | sizeof (off_val))) && res; |
593 | ? MHD_YES : MHD_NO; | ||
594 | #endif /* TCP_NOPUSH && !TCP_CORK */ | 588 | #endif /* TCP_NOPUSH && !TCP_CORK */ |
595 | return res; | 589 | return res; |
596 | #else /* !TCP_NODELAY */ | 590 | #else /* !TCP_NODELAY */ |
597 | return MHD_NO; | 591 | return false; |
598 | #endif /* !TCP_NODELAY */ | 592 | #endif /* !TCP_NODELAY */ |
599 | } | 593 | } |
600 | 594 | ||
@@ -604,27 +598,27 @@ socket_start_no_buffering (struct MHD_Connection *connection) | |||
604 | * and push to client data pending in socket buffer. | 598 | * and push to client data pending in socket buffer. |
605 | * | 599 | * |
606 | * @param connection connection to be processed | 600 | * @param connection connection to be processed |
607 | * @return #MHD_YES on success, #MHD_NO otherwise | 601 | * @return true on success, false otherwise |
608 | */ | 602 | */ |
609 | static int | 603 | _MHD_static_inline bool |
610 | socket_start_no_buffering_flush (struct MHD_Connection *connection) | 604 | socket_start_no_buffering_flush (struct MHD_Connection *connection) |
611 | { | 605 | { |
612 | int res = MHD_YES; | 606 | bool res; |
613 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) | 607 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) |
614 | const int dummy = 0; | 608 | const int dummy = 0; |
615 | #endif /* !TCP_CORK */ | 609 | #endif /* !TCP_CORK */ |
616 | 610 | ||
617 | if (NULL == connection) | 611 | (void)connection; /* Mute compiler warning. */ |
618 | return MHD_NO; | 612 | mhd_assert(NULL != connection); |
613 | |||
619 | res = socket_start_no_buffering (connection); | 614 | res = socket_start_no_buffering (connection); |
620 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) | 615 | #if defined(TCP_NOPUSH) && !defined(TCP_CORK) |
621 | /* Force flush data with zero send otherwise Darwin and some BSD systems | 616 | /* Force flush data with zero send otherwise Darwin and some BSD systems |
622 | will add 5 seconds delay. Not required with TCP_CORK as switching off | 617 | will add 5 seconds delay. Not required with TCP_CORK as switching off |
623 | TCP_CORK always flushes socket buffer. */ | 618 | TCP_CORK always flushes socket buffer. */ |
624 | res &= (0 <= MHD_send_ (connection->socket_fd, | 619 | res = (0 <= MHD_send_ (connection->socket_fd, |
625 | &dummy, | 620 | &dummy, |
626 | 0)) | 621 | 0)) && res; |
627 | ? MHD_YES : MHD_NO; | ||
628 | #endif /* TCP_NOPUSH && !TCP_CORK*/ | 622 | #endif /* TCP_NOPUSH && !TCP_CORK*/ |
629 | return res; | 623 | return res; |
630 | } | 624 | } |
@@ -634,13 +628,13 @@ socket_start_no_buffering_flush (struct MHD_Connection *connection) | |||
634 | * Activate normal buffering mode on connection socket. | 628 | * Activate normal buffering mode on connection socket. |
635 | * | 629 | * |
636 | * @param connection connection to be processed | 630 | * @param connection connection to be processed |
637 | * @return #MHD_YES on success, #MHD_NO otherwise | 631 | * @return true on success, false otherwise |
638 | */ | 632 | */ |
639 | static int | 633 | _MHD_static_inline bool |
640 | socket_start_normal_buffering (struct MHD_Connection *connection) | 634 | socket_start_normal_buffering (struct MHD_Connection *connection) |
641 | { | 635 | { |
642 | #if defined(TCP_NODELAY) | 636 | #if defined(TCP_NODELAY) |
643 | int res = MHD_YES; | 637 | bool res = true; |
644 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 638 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
645 | #if defined(TCP_CORK) | 639 | #if defined(TCP_CORK) |
646 | MHD_SCKT_OPT_BOOL_ cork_val = 0; | 640 | MHD_SCKT_OPT_BOOL_ cork_val = 0; |
@@ -657,33 +651,31 @@ socket_start_normal_buffering (struct MHD_Connection *connection) | |||
657 | (void*)&cork_val, | 651 | (void*)&cork_val, |
658 | ¶m_size)) || | 652 | ¶m_size)) || |
659 | (0 != cork_val)) | 653 | (0 != cork_val)) |
660 | res &= (0 == setsockopt (connection->socket_fd, | 654 | res = (0 == setsockopt (connection->socket_fd, |
661 | IPPROTO_TCP, | 655 | IPPROTO_TCP, |
662 | TCP_CORK, | 656 | TCP_CORK, |
663 | (const void *) &off_val, | 657 | (const void *) &off_val, |
664 | sizeof (off_val))) | 658 | sizeof (off_val))) && res; |
665 | ? MHD_YES : MHD_NO; | ||
666 | #elif defined(TCP_NOPUSH) | 659 | #elif defined(TCP_NOPUSH) |
667 | /* Disable extra buffering */ | 660 | /* Disable extra buffering */ |
668 | /* No need to check current value as disabling TCP_NOPUSH will not flush partial | 661 | /* No need to check current value as disabling TCP_NOPUSH will not flush partial |
669 | packet if TCP_NOPUSH wasn't enabled before */ | 662 | packet if TCP_NOPUSH wasn't enabled before */ |
670 | res &= (0 == setsockopt (connection->socket_fd, | 663 | res = (0 == setsockopt (connection->socket_fd, |
671 | IPPROTO_TCP, | 664 | IPPROTO_TCP, |
672 | TCP_NOPUSH, | 665 | TCP_NOPUSH, |
673 | (const void *) &off_val, | 666 | (const void *) &off_val, |
674 | sizeof (off_val))) | 667 | sizeof (off_val))) && res; |
675 | ? MHD_YES : MHD_NO; | ||
676 | #endif /* TCP_NOPUSH && !TCP_CORK */ | 668 | #endif /* TCP_NOPUSH && !TCP_CORK */ |
677 | /* Enable Nagle's algorithm for normal buffering */ | 669 | /* Enable Nagle's algorithm for normal buffering */ |
678 | res &= (0 == setsockopt (connection->socket_fd, | 670 | res = (0 == setsockopt (connection->socket_fd, |
679 | IPPROTO_TCP, | 671 | IPPROTO_TCP, |
680 | TCP_NODELAY, | 672 | TCP_NODELAY, |
681 | (const void *) &off_val, | 673 | (const void *) &off_val, |
682 | sizeof (off_val))) | 674 | sizeof (off_val))) && res; |
683 | ? MHD_YES : MHD_NO; | ||
684 | return res; | 675 | return res; |
685 | #else /* !TCP_NODELAY */ | 676 | #else /* !TCP_NODELAY */ |
686 | return MHD_NO; | 677 | (void) connection; |
678 | return false; | ||
687 | #endif /* !TCP_NODELAY */ | 679 | #endif /* !TCP_NODELAY */ |
688 | } | 680 | } |
689 | 681 | ||
@@ -3448,7 +3440,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3448 | if (need_100_continue (connection)) | 3440 | if (need_100_continue (connection)) |
3449 | { | 3441 | { |
3450 | connection->state = MHD_CONNECTION_CONTINUE_SENDING; | 3442 | connection->state = MHD_CONNECTION_CONTINUE_SENDING; |
3451 | if (MHD_NO != socket_flush_possible (connection)) | 3443 | if (socket_flush_possible (connection)) |
3452 | socket_start_extra_buffering (connection); | 3444 | socket_start_extra_buffering (connection); |
3453 | else | 3445 | else |
3454 | socket_start_no_buffering (connection); | 3446 | socket_start_no_buffering (connection); |
@@ -3476,7 +3468,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3476 | MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) | 3468 | MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) |
3477 | { | 3469 | { |
3478 | connection->state = MHD_CONNECTION_CONTINUE_SENT; | 3470 | connection->state = MHD_CONNECTION_CONTINUE_SENT; |
3479 | if (MHD_NO != socket_flush_possible (connection)) | 3471 | if (socket_flush_possible (connection)) |
3480 | socket_start_no_buffering_flush (connection); | 3472 | socket_start_no_buffering_flush (connection); |
3481 | else | 3473 | else |
3482 | socket_start_normal_buffering (connection); | 3474 | socket_start_normal_buffering (connection); |
@@ -3580,7 +3572,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3580 | continue; | 3572 | continue; |
3581 | } | 3573 | } |
3582 | connection->state = MHD_CONNECTION_HEADERS_SENDING; | 3574 | connection->state = MHD_CONNECTION_HEADERS_SENDING; |
3583 | if (MHD_NO != socket_flush_possible (connection)) | 3575 | if (socket_flush_possible (connection)) |
3584 | socket_start_extra_buffering (connection); | 3576 | socket_start_extra_buffering (connection); |
3585 | else | 3577 | else |
3586 | socket_start_no_buffering (connection); | 3578 | socket_start_no_buffering (connection); |
@@ -3591,7 +3583,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3591 | break; | 3583 | break; |
3592 | case MHD_CONNECTION_HEADERS_SENT: | 3584 | case MHD_CONNECTION_HEADERS_SENT: |
3593 | /* Some clients may take some actions right after header receive */ | 3585 | /* Some clients may take some actions right after header receive */ |
3594 | if (MHD_NO != socket_flush_possible (connection)) | 3586 | if (socket_flush_possible (connection)) |
3595 | socket_start_no_buffering_flush (connection); | 3587 | socket_start_no_buffering_flush (connection); |
3596 | 3588 | ||
3597 | #ifdef UPGRADE_SUPPORT | 3589 | #ifdef UPGRADE_SUPPORT |
@@ -3619,7 +3611,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3619 | continue; | 3611 | continue; |
3620 | } | 3612 | } |
3621 | #endif /* UPGRADE_SUPPORT */ | 3613 | #endif /* UPGRADE_SUPPORT */ |
3622 | if (MHD_NO != socket_flush_possible (connection)) | 3614 | if (socket_flush_possible (connection)) |
3623 | socket_start_extra_buffering (connection); | 3615 | socket_start_extra_buffering (connection); |
3624 | else | 3616 | else |
3625 | socket_start_normal_buffering (connection); | 3617 | socket_start_normal_buffering (connection); |
@@ -3654,7 +3646,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3654 | #endif | 3646 | #endif |
3655 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; | 3647 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; |
3656 | /* Buffering for flushable socket was already enabled*/ | 3648 | /* Buffering for flushable socket was already enabled*/ |
3657 | if (MHD_NO == socket_flush_possible (connection)) | 3649 | if (socket_flush_possible (connection)) |
3658 | socket_start_no_buffering (connection); | 3650 | socket_start_no_buffering (connection); |
3659 | break; | 3651 | break; |
3660 | } | 3652 | } |
@@ -3688,7 +3680,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3688 | #endif | 3680 | #endif |
3689 | connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; | 3681 | connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; |
3690 | /* Buffering for flushable socket was already enabled */ | 3682 | /* Buffering for flushable socket was already enabled */ |
3691 | if (MHD_NO == socket_flush_possible (connection)) | 3683 | if (socket_flush_possible (connection)) |
3692 | socket_start_no_buffering (connection); | 3684 | socket_start_no_buffering (connection); |
3693 | continue; | 3685 | continue; |
3694 | } | 3686 | } |
@@ -3722,7 +3714,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3722 | /* FIXME: maybe partially reset memory pool? */ | 3714 | /* FIXME: maybe partially reset memory pool? */ |
3723 | continue; | 3715 | continue; |
3724 | } | 3716 | } |
3725 | if (MHD_NO != socket_flush_possible (connection)) | 3717 | if (socket_flush_possible (connection)) |
3726 | socket_start_no_buffering_flush (connection); | 3718 | socket_start_no_buffering_flush (connection); |
3727 | else | 3719 | else |
3728 | socket_start_normal_buffering (connection); | 3720 | socket_start_normal_buffering (connection); |
@@ -3753,7 +3745,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3753 | else | 3745 | else |
3754 | { | 3746 | { |
3755 | /* can try to keep-alive */ | 3747 | /* can try to keep-alive */ |
3756 | if (MHD_NO != socket_flush_possible (connection)) | 3748 | if (socket_flush_possible (connection)) |
3757 | socket_start_normal_buffering (connection); | 3749 | socket_start_normal_buffering (connection); |
3758 | connection->version = NULL; | 3750 | connection->version = NULL; |
3759 | connection->state = MHD_CONNECTION_INIT; | 3751 | connection->state = MHD_CONNECTION_INIT; |