diff --git a/calexium_lib/web/CXM_multihost_http_server.anubis b/calexium_lib/web/CXM_multihost_http_server.anubis index c5fc13f..aeed0d6 100644 --- a/calexium_lib/web/CXM_multihost_http_server.anubis +++ b/calexium_lib/web/CXM_multihost_http_server.anubis @@ -499,6 +499,28 @@ define String variable UTime t0 = utime(0,0). +variable UTime t1 = utime(0,0). + +define One + accumulate_t1 + ( + UTime start + ) = + with delta = (UTime)now - start, + t1 <- delta + *t1; + unique. + +variable UTime t2 = utime(0,0). + +define One + accumulate_t2 + ( + UTime start + ) = + with delta = (UTime)now - start, + t2 <- delta + *t2; + unique. + define One print_delta @@ -508,7 +530,6 @@ define One println(utime_to_string((UTime)now - *t0) + " : " + txt). - ----------------------------------- Table of Contents --------------------------------- *** [1] Types which are private to this file. @@ -721,9 +742,11 @@ define ReadResult 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) now, with result = extract(*connection.buffer, *connection.read_pos, *connection.read_pos + size), size_read = length(result), connection.read_pos <- *connection.read_pos + size_read; + //accumulate_t1(t1_tmp); if size > size_read then //println("Wanted " + size + ", read only " + size_read); @@ -757,56 +780,28 @@ define Result(Error,Word8) DenialOfService dos ) = //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else - if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity - { - error then error(cannot_read_from_connection), - timeout then error(timeout(600)), - //record_dubious_connection(connection,dead_line,dos), - ok(ba) then if nth(0,ba) is + if nth(*connection.read_pos, *connection.buffer) is + { + failure then + if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity { - failure then error(cannot_read_from_connection), - success(c) then -// println("-" + pid + "read [" + implode([c]) + "]\t"); - ok(c) - } - }. - - -variable ByteArray read_buffer = constant_byte_array(0, 0). -variable Int32 read_offset = 0. - - define Result(Error,Word8) - read_one_byte - ( - BufferedConnection connection, - Int32 dead_line, - DenialOfService dos - ) = - if *read_offset < length(*read_buffer) then - if nth(*read_offset, *read_buffer) is - { - failure then println(pid + "nth failed)"); error(cannot_read_from_connection), + error then error(cannot_read_from_connection), + timeout then error(timeout(600)), + //record_dubious_connection(connection,dead_line,dos), + ok(ba) then if nth(0,ba) is + { + failure then error(cannot_read_from_connection), + success(c) then + // println("-" + pid + "read [" + implode([c]) + "]\t"); + ok(c) + } + }, success(c) then - println("-" + pid + "read [" + implode([c]) + "]\tat " + *read_offset); - read_offset <- *read_offset + 1; + connection.read_pos <- *connection.read_pos + 1; ok(c) - } - else - //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else - println(pid + "len = " + length(*read_buffer)); - if read(connection, 16384, 600) is // the connection is closed after 10 minutes of inactivity - { - error then println(pid + "read failed)"); error(cannot_read_from_connection), - timeout then error(timeout(600)), - //record_dubious_connection(connection,dead_line,dos), - ok(ba) then - println(pid + "ba = " + length(ba)); - read_buffer <- ba; - read_offset <- 0; - println(pid + "rb = " + length(*read_buffer)); - read_one_byte(connection, dead_line, dos) - }. - + }. + + define Result(Error,Word8) next_char // reading a character (check the list first, and read on the connection @@ -816,16 +811,27 @@ define Result(Error,Word8) Int32 dead_line, DenialOfService dos ) = + with t2_tmp = (UTime) now, if *unput_chars is { - [ ] then read_one_byte(connection,dead_line,dos), + [ ] then with ret = read_one_byte(connection,dead_line,dos), accumulate_t2(t2_tmp); ret, +// if read(connection.conn, 1, 600) is // the connection is closed after 10 minutes of inactivity +// { +// error then accumulate_t2(t2_tmp); println(pid + "read failed)"); error(cannot_read_from_connection), +// timeout then accumulate_t2(t2_tmp); error(timeout(600)), +// ok(ba) then if nth(0,ba) is +// { +// failure then accumulate_t2(t2_tmp); error(cannot_read_from_connection), +// success(c) then accumulate_t2(t2_tmp); +// ok(c) +// } +// }, [h . t] then - unput_chars <- t; + unput_chars <- t; accumulate_t2(t2_tmp); ok(h) }. - @@ -2990,7 +2996,9 @@ define One send_answer(host_name, desc,connection.conn, request_line, headers, body, make_generate_trust_ticket(dos)); with duration = (UTime) now - *t0, - println("Request duration: " + utime_to_string(duration)) + println("Request duration: " + utime_to_string(duration)); + //println("BufferRead duration: " + utime_to_string(*t1)); + println("next_char duration: " + utime_to_string(*t2)) } } } -- libgit2 0.21.4