diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-02-16 16:27:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-02-16 16:51:18 +0100 |
commit | 0ec4d08ea357e680506d9f7df90fa1e53a180509 (patch) | |
tree | 15f4db9dd6b089adfe3e3efdf5831c8ea25aa0d9 /networking/tls.c | |
parent | c39ee047051fb36f4db907c037e22db586490f42 (diff) | |
download | busybox-w32-0ec4d08ea357e680506d9f7df90fa1e53a180509.tar.gz busybox-w32-0ec4d08ea357e680506d9f7df90fa1e53a180509.tar.bz2 busybox-w32-0ec4d08ea357e680506d9f7df90fa1e53a180509.zip |
tls: covert i/o loop from using select() to poll()
function old new delta
tls_run_copy_loop 377 282 -95
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/tls.c')
-rw-r--r-- | networking/tls.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/networking/tls.c b/networking/tls.c index 30afd9ea9..cb6b09476 100644 --- a/networking/tls.c +++ b/networking/tls.c | |||
@@ -1740,26 +1740,23 @@ static void tls_xwrite(tls_state_t *tls, int len) | |||
1740 | 1740 | ||
1741 | void FAST_FUNC tls_run_copy_loop(tls_state_t *tls) | 1741 | void FAST_FUNC tls_run_copy_loop(tls_state_t *tls) |
1742 | { | 1742 | { |
1743 | fd_set readfds; | ||
1744 | int inbuf_size; | 1743 | int inbuf_size; |
1745 | const int INBUF_STEP = 4 * 1024; | 1744 | const int INBUF_STEP = 4 * 1024; |
1745 | struct pollfd pfds[2]; | ||
1746 | 1746 | ||
1747 | //TODO: convert to poll | 1747 | pfds[0].fd = STDIN_FILENO; |
1748 | /* Select loop copying stdin to ofd, and ifd to stdout */ | 1748 | pfds[0].events = POLLIN; |
1749 | FD_ZERO(&readfds); | 1749 | pfds[1].fd = tls->ifd; |
1750 | FD_SET(tls->ifd, &readfds); | 1750 | pfds[1].events = POLLIN; |
1751 | FD_SET(STDIN_FILENO, &readfds); | ||
1752 | 1751 | ||
1753 | inbuf_size = INBUF_STEP; | 1752 | inbuf_size = INBUF_STEP; |
1754 | for (;;) { | 1753 | for (;;) { |
1755 | fd_set testfds; | ||
1756 | int nread; | 1754 | int nread; |
1757 | 1755 | ||
1758 | testfds = readfds; | 1756 | if (safe_poll(pfds, 2, -1) < 0) |
1759 | if (select(tls->ifd + 1, &testfds, NULL, NULL, NULL) < 0) | 1757 | bb_perror_msg_and_die("poll"); |
1760 | bb_perror_msg_and_die("select"); | ||
1761 | 1758 | ||
1762 | if (FD_ISSET(STDIN_FILENO, &testfds)) { | 1759 | if (pfds[0].revents) { |
1763 | void *buf; | 1760 | void *buf; |
1764 | 1761 | ||
1765 | dbg("STDIN HAS DATA\n"); | 1762 | dbg("STDIN HAS DATA\n"); |
@@ -1774,7 +1771,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls) | |||
1774 | /* But TLS has no way to encode this, | 1771 | /* But TLS has no way to encode this, |
1775 | * doubt it's ok to do it "raw" | 1772 | * doubt it's ok to do it "raw" |
1776 | */ | 1773 | */ |
1777 | FD_CLR(STDIN_FILENO, &readfds); | 1774 | pfds[0].fd = -1; |
1778 | tls_free_outbuf(tls); /* mem usage optimization */ | 1775 | tls_free_outbuf(tls); /* mem usage optimization */ |
1779 | } else { | 1776 | } else { |
1780 | if (nread == inbuf_size) { | 1777 | if (nread == inbuf_size) { |
@@ -1788,7 +1785,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls) | |||
1788 | tls_xwrite(tls, nread); | 1785 | tls_xwrite(tls, nread); |
1789 | } | 1786 | } |
1790 | } | 1787 | } |
1791 | if (FD_ISSET(tls->ifd, &testfds)) { | 1788 | if (pfds[1].revents) { |
1792 | dbg("NETWORK HAS DATA\n"); | 1789 | dbg("NETWORK HAS DATA\n"); |
1793 | read_record: | 1790 | read_record: |
1794 | nread = tls_xread_record(tls); | 1791 | nread = tls_xread_record(tls); |
@@ -1796,7 +1793,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls) | |||
1796 | /* TLS protocol has no real concept of one-sided shutdowns: | 1793 | /* TLS protocol has no real concept of one-sided shutdowns: |
1797 | * if we get "TLS EOF" from the peer, writes will fail too | 1794 | * if we get "TLS EOF" from the peer, writes will fail too |
1798 | */ | 1795 | */ |
1799 | //FD_CLR(tls->ifd, &readfds); | 1796 | //pfds[1].fd = -1; |
1800 | //close(STDOUT_FILENO); | 1797 | //close(STDOUT_FILENO); |
1801 | //tls_free_inbuf(tls); /* mem usage optimization */ | 1798 | //tls_free_inbuf(tls); /* mem usage optimization */ |
1802 | //continue; | 1799 | //continue; |