Commit aff304f6ae6592908e05c95ee13146d2cf143df9
1 parent
2956d18a
small optimization on reading HTTP headers
Showing
1 changed file
with
38 additions
and
42 deletions
Show diff stats
calexium_lib/web/CXM_multihost_http_server.anubis
| @@ -733,13 +733,13 @@ define String | @@ -733,13 +733,13 @@ define String | ||
| 733 | "[" + virtual_machine_id + "] ". | 733 | "[" + virtual_machine_id + "] ". |
| 734 | 734 | ||
| 735 | define ReadResult | 735 | define ReadResult |
| 736 | - read | 736 | + read_from_connexion |
| 737 | ( | 737 | ( |
| 738 | BufferedConnection connection, | 738 | BufferedConnection connection, |
| 739 | Int32 size, | 739 | Int32 size, |
| 740 | Int32 time_out | 740 | Int32 time_out |
| 741 | ) = | 741 | ) = |
| 742 | - //println(pid + "read(" + size + ")"); | 742 | + //println(pid + "read_from_connexion(" + size + ")"); |
| 743 | 743 | ||
| 744 | if *connection.read_pos < length(*connection.buffer) then | 744 | if *connection.read_pos < length(*connection.buffer) then |
| 745 | //println(pid + " reading from buffer (size = " + length(*connection.buffer) + ", pos = " + *connection.read_pos); | 745 | //println(pid + " reading from buffer (size = " + length(*connection.buffer) + ", pos = " + *connection.read_pos); |
| @@ -751,7 +751,7 @@ define ReadResult | @@ -751,7 +751,7 @@ define ReadResult | ||
| 751 | if size > size_read | 751 | if size > size_read |
| 752 | then | 752 | then |
| 753 | //println("Wanted " + size + ", read only " + size_read); | 753 | //println("Wanted " + size + ", read only " + size_read); |
| 754 | - if read(connection, size - size_read, time_out) is | 754 | + if read_from_connexion(connection, size - size_read, time_out) is |
| 755 | { | 755 | { |
| 756 | error then error, | 756 | error then error, |
| 757 | timeout then ok(result), | 757 | timeout then ok(result), |
| @@ -769,41 +769,9 @@ define ReadResult | @@ -769,41 +769,9 @@ define ReadResult | ||
| 769 | connection.buffer <- ba; | 769 | connection.buffer <- ba; |
| 770 | connection.read_pos <- 0; | 770 | connection.read_pos <- 0; |
| 771 | //println(pid + "rb = " + length(*read_buffer)); | 771 | //println(pid + "rb = " + length(*read_buffer)); |
| 772 | - read(connection, size, time_out) | 772 | + read_from_connexion(connection, size, time_out) |
| 773 | }. | 773 | }. |
| 774 | 774 | ||
| 775 | - | ||
| 776 | -define Result(Error,Word8) | ||
| 777 | - read_one_byte | ||
| 778 | - ( | ||
| 779 | - BufferedConnection connection, | ||
| 780 | - Int32 dead_line, | ||
| 781 | - DenialOfService dos | ||
| 782 | - ) = | ||
| 783 | - //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else | ||
| 784 | - if nth(*connection.read_pos, *connection.buffer) is | ||
| 785 | - { | ||
| 786 | - failure then | ||
| 787 | - if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity | ||
| 788 | - { | ||
| 789 | - error then error(cannot_read_from_connection), | ||
| 790 | - timeout then error(timeout(600)), | ||
| 791 | - //record_dubious_connection(connection,dead_line,dos), | ||
| 792 | - ok(ba) then if nth(0,ba) is | ||
| 793 | - { | ||
| 794 | - failure then error(cannot_read_from_connection), | ||
| 795 | - success(c) then | ||
| 796 | - // println("-" + pid + "read [" + implode([c]) + "]\t"); | ||
| 797 | - ok(c) | ||
| 798 | - } | ||
| 799 | - }, | ||
| 800 | - success(c) then | ||
| 801 | - connection.read_pos <- *connection.read_pos + 1; | ||
| 802 | - ok(c) | ||
| 803 | - }. | ||
| 804 | - | ||
| 805 | - | ||
| 806 | - | ||
| 807 | define Result(Error,Word8) | 775 | define Result(Error,Word8) |
| 808 | next_char // reading a character (check the list first, and read on the connection | 776 | next_char // reading a character (check the list first, and read on the connection |
| 809 | // only when the list is empty). | 777 | // only when the list is empty). |
| @@ -812,10 +780,38 @@ define Result(Error,Word8) | @@ -812,10 +780,38 @@ define Result(Error,Word8) | ||
| 812 | Int32 dead_line, | 780 | Int32 dead_line, |
| 813 | DenialOfService dos | 781 | DenialOfService dos |
| 814 | ) = | 782 | ) = |
| 815 | - with t2_tmp = (UTime) now, | 783 | + //with t2_tmp = (UTime) now, |
| 816 | if *unput_chars is | 784 | if *unput_chars is |
| 817 | { | 785 | { |
| 818 | - [ ] then with ret = read_one_byte(connection,dead_line,dos), accumulate_t2(t2_tmp); ret, | 786 | + [ ] then |
| 787 | + // /////////////////// | ||
| 788 | + // Buffered reading | ||
| 789 | + //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else | ||
| 790 | + if nth(*connection.read_pos, *connection.buffer) is | ||
| 791 | + { | ||
| 792 | + failure then | ||
| 793 | + if read_from_connexion(connection,1,600) is // the connection is closed after 10 minutes of inactivity | ||
| 794 | + { | ||
| 795 | + error then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), | ||
| 796 | + timeout then /*accumulate_t2(t2_tmp);*/ error(timeout(600)), | ||
| 797 | + //record_dubious_connection(connection,dead_line,dos), | ||
| 798 | + ok(ba) then if nth(0,ba) is | ||
| 799 | + { | ||
| 800 | + failure then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), | ||
| 801 | + success(c) then | ||
| 802 | + //println("-" + pid + "read [" + implode([c]) + "]\t"); | ||
| 803 | + //accumulate_t2(t2_tmp); | ||
| 804 | + ok(c) | ||
| 805 | + } | ||
| 806 | + }, | ||
| 807 | + success(c) then | ||
| 808 | + connection.read_pos <- *connection.read_pos + 1; | ||
| 809 | + //accumulate_t2(t2_tmp); | ||
| 810 | + ok(c) | ||
| 811 | + }, | ||
| 812 | + | ||
| 813 | + // /////////////////// | ||
| 814 | + // standard reading | ||
| 819 | // if read(connection.conn, 1, 600) is // the connection is closed after 10 minutes of inactivity | 815 | // if read(connection.conn, 1, 600) is // the connection is closed after 10 minutes of inactivity |
| 820 | // { | 816 | // { |
| 821 | // error then accumulate_t2(t2_tmp); println(pid + "read failed)"); error(cannot_read_from_connection), | 817 | // error then accumulate_t2(t2_tmp); println(pid + "read failed)"); error(cannot_read_from_connection), |
| @@ -829,7 +825,7 @@ define Result(Error,Word8) | @@ -829,7 +825,7 @@ define Result(Error,Word8) | ||
| 829 | // }, | 825 | // }, |
| 830 | 826 | ||
| 831 | [h . t] then | 827 | [h . t] then |
| 832 | - unput_chars <- t; accumulate_t2(t2_tmp); | 828 | + unput_chars <- t; //accumulate_t2(t2_tmp); |
| 833 | ok(h) | 829 | ok(h) |
| 834 | }. | 830 | }. |
| 835 | 831 | ||
| @@ -1722,7 +1718,7 @@ define Result(Error,ByteArray) | @@ -1722,7 +1718,7 @@ define Result(Error,ByteArray) | ||
| 1722 | ) = | 1718 | ) = |
| 1723 | if body_size = 0 then ok(constant_byte_array(0,0)) else | 1719 | if body_size = 0 then ok(constant_byte_array(0,0)) else |
| 1724 | if retries =< 0 then error(cannot_read_from_connection) else | 1720 | if retries =< 0 then error(cannot_read_from_connection) else |
| 1725 | - if read(connection,body_size,60) is | 1721 | + if read_from_connexion(connection,body_size,60) is |
| 1726 | { | 1722 | { |
| 1727 | error then error(cannot_read_from_connection), | 1723 | error then error(cannot_read_from_connection), |
| 1728 | timeout then error(timeout(60)), | 1724 | timeout then error(timeout(60)), |
| @@ -3002,9 +2998,9 @@ define One | @@ -3002,9 +2998,9 @@ define One | ||
| 3002 | send_answer(host_name, desc,connection.conn, request_line, headers, body, | 2998 | send_answer(host_name, desc,connection.conn, request_line, headers, body, |
| 3003 | make_generate_trust_ticket(dos)); | 2999 | make_generate_trust_ticket(dos)); |
| 3004 | with duration = (UTime) now - *t0, | 3000 | with duration = (UTime) now - *t0, |
| 3005 | - println("Request duration: " + utime_to_string(duration)); | 3001 | + println("Request duration: " + utime_to_string(duration)) |
| 3006 | //println("BufferRead duration: " + utime_to_string(*t1)); | 3002 | //println("BufferRead duration: " + utime_to_string(*t1)); |
| 3007 | - println("next_char duration: " + utime_to_string(*t2)) | 3003 | + //println("next_char duration: " + utime_to_string(*t2)) |
| 3008 | } | 3004 | } |
| 3009 | } | 3005 | } |
| 3010 | } | 3006 | } |