Commit 0af19e2519ee43ae9f1de97f9dec32a028fd6dcf

Authored by David RENE
1 parent 8817d087

optimization of read_from_connection,

Showing 1 changed file with 37 additions and 13 deletions   Show diff stats
calexium_lib/web/CXM_multihost_http_server.anubis
@@ -733,12 +733,33 @@ define String @@ -733,12 +733,33 @@ define String
733 = 733 =
734 "[" + virtual_machine_id + "] ". 734 "[" + virtual_machine_id + "] ".
735 735
  736 +
  737 +define One
  738 + put
  739 + (
  740 + ByteArray source,
  741 + ByteArray dest,
  742 + Int32 position,
  743 + Int32 i
  744 + ) =
  745 + if nth(i,source) is
  746 + {
  747 + failure then unique,
  748 + success(b) then if put(dest,position,b) is
  749 + {
  750 + failure then unique,
  751 + success(_) then put(source,dest,position+1,i+1)
  752 + }
  753 + }.
  754 +
736 define ReadResult 755 define ReadResult
737 read_from_connexion 756 read_from_connexion
738 ( 757 (
739 BufferedConnection connection, 758 BufferedConnection connection,
740 Int32 size, 759 Int32 size,
741 - Int32 time_out 760 + Int32 time_out,
  761 + ByteArray result_buffer,
  762 + Int32 position
742 ) = 763 ) =
743 //println(pid + "read_from_connexion(" + size + ")"); 764 //println(pid + "read_from_connexion(" + size + ")");
744 765
@@ -747,18 +768,20 @@ define ReadResult @@ -747,18 +768,20 @@ define ReadResult
747 //with t1_tmp = (UTime) now, 768 //with t1_tmp = (UTime) now,
748 with result = extract(*connection.buffer, *connection.read_pos, *connection.read_pos + size), 769 with result = extract(*connection.buffer, *connection.read_pos, *connection.read_pos + size),
749 size_read = length(result), 770 size_read = length(result),
  771 + put(result,result_buffer,position,0);
750 connection.read_pos <- *connection.read_pos + size_read; 772 connection.read_pos <- *connection.read_pos + size_read;
751 //accumulate_t1(t1_tmp); 773 //accumulate_t1(t1_tmp);
752 - if size > size_read  
753 - then 774 + if size > size_read then
754 //println("Wanted " + size + ", read only " + size_read); 775 //println("Wanted " + size + ", read only " + size_read);
755 - if read_from_connexion(connection, size - size_read, time_out) is  
756 - {  
757 - error then error,  
758 - timeout then ok(result),  
759 - ok(ba) then ok(result + ba)  
760 - }  
761 - else ok(result) 776 +
  777 + terminal read_from_connexion(connection, size - size_read, time_out, result_buffer,position+size_read)
  778 +// {
  779 +// error then error,
  780 +// timeout then ok(result),
  781 +// ok(ba) then ok(result + ba)
  782 +// }
  783 + else
  784 + ok(result_buffer)
762 else 785 else
763 //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else 786 //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else
764 if read(connection.conn, 16384, time_out) is // the connection is closed after 10 minutes of inactivity 787 if read(connection.conn, 16384, time_out) is // the connection is closed after 10 minutes of inactivity
@@ -770,7 +793,8 @@ define ReadResult @@ -770,7 +793,8 @@ define ReadResult
770 connection.buffer <- ba; 793 connection.buffer <- ba;
771 connection.read_pos <- 0; 794 connection.read_pos <- 0;
772 //println(pid + "rb = " + length(*read_buffer)); 795 //println(pid + "rb = " + length(*read_buffer));
773 - read_from_connexion(connection, size, time_out) 796 +
  797 + terminal read_from_connexion(connection, size, time_out, result_buffer,position)
774 }. 798 }.
775 799
776 define Result(Error,Word8) 800 define Result(Error,Word8)
@@ -791,7 +815,7 @@ define Result(Error,Word8) @@ -791,7 +815,7 @@ define Result(Error,Word8)
791 if nth(*connection.read_pos, *connection.buffer) is 815 if nth(*connection.read_pos, *connection.buffer) is
792 { 816 {
793 failure then 817 failure then
794 - if read_from_connexion(connection,1,600) is // the connection is closed after 10 minutes of inactivity 818 + if read_from_connexion(connection,1,600, constant_byte_array(1,0),0) is // the connection is closed after 10 minutes of inactivity
795 { 819 {
796 error then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), 820 error then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection),
797 timeout then /*accumulate_t2(t2_tmp);*/ error(timeout(600)), 821 timeout then /*accumulate_t2(t2_tmp);*/ error(timeout(600)),
@@ -1719,7 +1743,7 @@ define Result(Error,ByteArray) @@ -1719,7 +1743,7 @@ define Result(Error,ByteArray)
1719 ) = 1743 ) =
1720 if body_size = 0 then ok(constant_byte_array(0,0)) else 1744 if body_size = 0 then ok(constant_byte_array(0,0)) else
1721 if retries =< 0 then error(cannot_read_from_connection) else 1745 if retries =< 0 then error(cannot_read_from_connection) else
1722 - if read_from_connexion(connection,body_size,60) is 1746 + if read_from_connexion(connection,body_size,60,constant_byte_array(body_size,0),0) is
1723 { 1747 {
1724 error then error(cannot_read_from_connection), 1748 error then error(cannot_read_from_connection),
1725 timeout then error(timeout(60)), 1749 timeout then error(timeout(60)),