diff --git a/web/multihost_http_server.anubis b/web/multihost_http_server.anubis index a2dfea0..27dfb14 100644 --- a/web/multihost_http_server.anubis +++ b/web/multihost_http_server.anubis @@ -873,52 +873,75 @@ define One define Maybe(ByteArray) read_from_connexion ( - HTTP_Buffered_Connection connection, - Int size, - Int time_out, - ByteArray result_buffer, - Int position + HTTP_Buffered_Connection connection, //connection to read + Int size_to_read, //size to read + Int time_out, //time out + ByteArray result_buffer //the current read bytes ) = - //println(pid + "read_from_connexion(" + size + ")"); + //println(pid + "read_from_connexion(" + size_to_read + ", "+time_out+")"); + //println(pid + "connection buffer ["+length(*connection.buffer)+"]["+*connection.read_pos+"]["+to_string(*connection.buffer)+"]"); if *connection.read_pos < length(*connection.buffer) then - //println(pid + " reading from buffer (size = " + length(*connection.buffer) + ", pos = " + *connection.read_pos); - //with t1_tmp = (UTime) unow, - with result = extract(*connection.buffer, *connection.read_pos, *connection.read_pos + size), + //println(pid + " reading from buffer (size = " + length(*connection.buffer) + ", pos = " + *connection.read_pos+ ")"); + with result = extract(*connection.buffer, *connection.read_pos, *connection.read_pos + size_to_read), size_read = length(result), - put(result,result_buffer,position,0); + //put(result, result_buffer, position, 0); + //println(pid + "read size ["+size_read+"]["+to_string(result)+"]"); + //println(pid + "result_buffer size ["+length(result_buffer)+"]["+to_string(result_buffer)+"]"); + with current_result_buffer = result_buffer + result, + //println(pid + "current_result_buffer size ["+length(current_result_buffer)+"]["+to_string(current_result_buffer)+"]"); + //println(pid + "connection.read_pos "+*connection.read_pos+" + read_size ["+size_read+"]"); connection.read_pos <- *connection.read_pos + size_read; + //println(pid + "new connection.read_pos["+*connection.read_pos+"]"); //accumulate_t1(t1_tmp); - if size > size_read then + if size_to_read > size_read then - terminal read_from_connexion(connection, size - size_read, time_out, result_buffer, position+size_read) + terminal read_from_connexion(connection, size_to_read - size_read, time_out, current_result_buffer) // { // error then error, // timeout then ok(result), // ok(ba) then ok(result + ba) // } else - success(result_buffer) + // println(pid + "success: ["+length(current_result_buffer)+"]"); + // println(pid + "content: ["+to_string(current_result_buffer)+"]"); + success(current_result_buffer) else - with t0 = (UTime) unow, + //with t0 = (UTime) unow, //if unow > dead_line then record_dubious_connection(connection,dead_line,dos) else + println(pid +"try to read fill buffer with 32768 bytes time out ["+time_out+"]"); if read(connection.conn, 32768, time_out) is // read with timeout { - failure then println(pid + "read failed ["+to_string(result_buffer)+"]"); failure, + failure then println(pid + "read failed ["+to_string(result_buffer)+"] connection maybe lost"); failure, success(ba) then with size_read = length(ba), + println( pid + "read ["+size_read+"] bytes"); //the needed read is higher than the - if size > size_read then - put(ba, result_buffer, position, 0); - read_from_connexion(connection, size - size_read, time_out, result_buffer, position+size_read) + if size_read = 0 then + read_from_connexion(connection, size_to_read, time_out, result_buffer) + else if size_to_read > size_read then + //put(ba, result_buffer, position, 0); + with current_result_buffer = result_buffer + ba, + read_from_connexion(connection, size_to_read - size_read, time_out, current_result_buffer) else //println(pid + "ba = " + length(ba) + " duration: " + __utime_to_string((UTime) unow - t0)); connection.buffer <- ba; connection.read_pos <- 0; //println(pid + "rb = " + length(*read_buffer)); - terminal read_from_connexion(connection, size, time_out, result_buffer, position) - }. + terminal read_from_connexion(connection, size_to_read, time_out, result_buffer) + } +. + +define Maybe(ByteArray) + read_from_connexion + ( + HTTP_Buffered_Connection connection, //connection to read + Int size_to_read, //size to read + Int time_out //time out + )= + read_from_connexion(connection, size_to_read, time_out, constant_byte_array(0,0)) +. define Result(Error,Word8) next_char // reading a character (check the list first, and read on the connection @@ -938,7 +961,7 @@ define Result(Error,Word8) if nth(*connection.read_pos, *connection.buffer) is { failure then - if read_from_connexion(connection,1,0, constant_byte_array(1,0),0) is + if read_from_connexion(connection, 1, 600 /*, constant_byte_array(1,0),0*/) is { failure then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), //record_dubious_connection(connection,dead_line,dos), @@ -953,6 +976,7 @@ define Result(Error,Word8) }, success(c) then connection.read_pos <- *connection.read_pos + 1; + //println(pid + "read [" + implode([c]) + "] \t new pos ["+*connection.read_pos+"]"); //accumulate_t2(t2_tmp); ok(c) }, @@ -1898,7 +1922,7 @@ public define Result(Error, ByteArray) if body_size = 0 then ok(constant_byte_array(0,0)) else if retries =< 0 then error(cannot_read_from_connection) else - if read_from_connexion(connection,body_size,0,constant_byte_array(body_size,0),0) is + if read_from_connexion(connection, body_size, 600 /*,constant_byte_array(body_size,0),0*/) is { failure then error(cannot_read_from_connection), success(new_bytes) then @@ -3100,18 +3124,18 @@ define String define String strip_port - ( - String name, - Int i - ) = - if nth(i,name) is - { - failure then name, - success(c) then - if c = ':' - then substr(name,0,i) - else strip_port(name,i+1) - }. + ( + String name, + Int i + ) = + if nth(i,name) is + { + failure then name, + success(c) then + if c = ':' + then substr(name, 0, i) + else strip_port(name, i+1) + }. -- libgit2 0.21.4