Commit 1017eda07313ae84060ee1be6ffe3a59ab3bfa10
1 parent
054b8747
change the return result of read. Now the return type is ReadResult instead of M…
…aybe(ByteArray). ReadResult introduce timeout error handling. Then now the version is 1.8.1
Showing
7 changed files
with
47 additions
and
37 deletions
Show diff stats
anubis_dev/library/network/tools.anubis
| ... | ... | @@ -25,12 +25,13 @@ public define Byte_Net_Result |
| 25 | 25 | )= |
| 26 | 26 | if read(conn, 1, t_out) is |
| 27 | 27 | { |
| 28 | - failure then failure, | |
| 29 | - success(byte) then | |
| 30 | - if nth(0, byte) is | |
| 28 | + error then failure, | |
| 29 | + time_out then time_out, | |
| 30 | + ok(byte) then | |
| 31 | + if nth(0, byte) is | |
| 31 | 32 | { |
| 32 | - failure then time_out, | |
| 33 | - success(c) then success(c) | |
| 33 | + failure then failure, | |
| 34 | + success(byte) then success(byte) | |
| 34 | 35 | } |
| 35 | 36 | }. |
| 36 | 37 | |
| ... | ... | @@ -50,13 +51,11 @@ public define Byte_Net_Result |
| 50 | 51 | )= |
| 51 | 52 | if read(conn, how_many, t_out) is |
| 52 | 53 | { |
| 53 | - failure then failure, | |
| 54 | - success(bytes) then | |
| 54 | + error then failure, | |
| 55 | + time_out then time_out, | |
| 56 | + ok(bytes) then | |
| 55 | 57 | with len = length(bytes), |
| 56 | - //if the returned length size is 0, it means timeout | |
| 57 | - if len = 0 then | |
| 58 | - time_out | |
| 59 | - else if len = how_many then | |
| 58 | + if len = how_many then | |
| 60 | 59 | success(bytes) |
| 61 | 60 | else |
| 62 | 61 | truncated(bytes) | ... | ... |
anubis_dev/library/system/data_io.anubis
| ... | ... | @@ -40,14 +40,12 @@ define Int32 -> Data_IO_Result |
| 40 | 40 | (Int32 how_many) |-> |
| 41 | 41 | if read(file, how_many, 10) is //by default the time_out is 10 seconds |
| 42 | 42 | { |
| 43 | - failure then failure, | |
| 44 | - success(bytes) then | |
| 43 | + error then failure, | |
| 44 | + time_out then time_out, | |
| 45 | + ok(bytes) then | |
| 45 | 46 | with len = length(bytes), |
| 46 | 47 | offset <- *offset + len; //update the offset |
| 47 | - //if the returned length size is 0, it means timeout | |
| 48 | - if len = 0 then | |
| 49 | - time_out | |
| 50 | - else if len = how_many then | |
| 48 | + if len = how_many then | |
| 51 | 49 | success(bytes) |
| 52 | 50 | else |
| 53 | 51 | truncated(bytes) | ... | ... |
anubis_dev/library/system/files.anubis
| ... | ... | @@ -39,8 +39,9 @@ public define ResultCopy |
| 39 | 39 | copy_ok |
| 40 | 40 | else if read(source, read_length, 10) is |
| 41 | 41 | { |
| 42 | - failure then copy_error, | |
| 43 | - success(buffer) then | |
| 42 | + error then copy_error, | |
| 43 | + time_out then copy_error, | |
| 44 | + ok(buffer) then | |
| 44 | 45 | if write( target , buffer) is |
| 45 | 46 | { |
| 46 | 47 | failure then copy_error, |
| ... | ... | @@ -158,8 +159,9 @@ public define Maybe(One) |
| 158 | 159 | success(unique) |
| 159 | 160 | else if read(source_file, read_length, 10) is |
| 160 | 161 | { |
| 161 | - failure then failure, | |
| 162 | - success(buffer) then | |
| 162 | + error then failure, | |
| 163 | + time_out then failure, | |
| 164 | + ok(buffer) then | |
| 163 | 165 | if reliable_write(tcp(socket), buffer) is |
| 164 | 166 | { |
| 165 | 167 | failure then failure, | ... | ... |
anubis_dev/library/system/muscle.anubis
anubis_dev/library/tools/basis.anubis
| ... | ... | @@ -1799,8 +1799,10 @@ define Maybe(ByteArray) |
| 1799 | 1799 | if now > timeout then failure else |
| 1800 | 1800 | if read(conn,n,1) is |
| 1801 | 1801 | { |
| 1802 | - failure then failure, | |
| 1803 | - success(ba) then with l = length(ba), | |
| 1802 | + error then failure, | |
| 1803 | + time_out then failure, | |
| 1804 | + ok(ba) then | |
| 1805 | + with l = length(ba), | |
| 1804 | 1806 | if l = n |
| 1805 | 1807 | then success(so_far+ba) |
| 1806 | 1808 | else reliable_read(conn,n-l,timeout,so_far+ba) | ... | ... |
anubis_dev/library/tools/connections.anubis
| 1 | - | |
| 1 | + | |
| 2 | 2 | *Project* The Anubis Project |
| 3 | 3 | |
| 4 | 4 | *Title* Unifying the handling of connections. |
| ... | ... | @@ -56,7 +56,7 @@ public define Connection file(RWStream a) = file_rw(a). |
| 56 | 56 | Now, here are the unified tools for reading and writing: |
| 57 | 57 | |
| 58 | 58 | |
| 59 | -public define Maybe(ByteArray) // result of reading | |
| 59 | +public define ReadResult // result of reading | |
| 60 | 60 | read |
| 61 | 61 | ( |
| 62 | 62 | Connection c, |
| ... | ... | @@ -77,7 +77,7 @@ public define Maybe(Int32) // number of bytes actually written |
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | |
| 80 | -public define Maybe(ByteArray) // result of reading | |
| 80 | +public define ReadResult // result of reading | |
| 81 | 81 | read |
| 82 | 82 | ( |
| 83 | 83 | Connection c, |
| ... | ... | @@ -91,7 +91,12 @@ public define Maybe(ByteArray) // result of reading |
| 91 | 91 | file_w(wa) then alert, |
| 92 | 92 | file_rw(rwa) then read(weaken(rwa),n,timeout), |
| 93 | 93 | tcp(a) then read(weaken(a),n,timeout), |
| 94 | - ssl(a) then read(a,n,timeout) | |
| 94 | + ssl(a) then | |
| 95 | + if (Maybe(ByteArray))read(a,n,timeout) is | |
| 96 | + { | |
| 97 | + failure then error, | |
| 98 | + success((ByteArray)ba) then ok(ba) | |
| 99 | + } | |
| 95 | 100 | }. |
| 96 | 101 | |
| 97 | 102 | |
| ... | ... | @@ -128,4 +133,4 @@ public define (Int32,Int32) |
| 128 | 133 | |
| 129 | 134 | |
| 130 | 135 | |
| 131 | - | |
| 132 | 136 | \ No newline at end of file |
| 137 | + | ... | ... |
anubis_dev/library/web/multihost_http_server.anubis
| ... | ... | @@ -617,9 +617,9 @@ define String |
| 617 | 617 | colon_expected then |
| 618 | 618 | "':' was expected.\n", |
| 619 | 619 | timeout(n) then |
| 620 | - //"time out: "+n+"\n" | |
| 620 | + "time out: "+n+"\n" | |
| 621 | 621 | //"time out.\n" |
| 622 | - "" | |
| 622 | + //"" | |
| 623 | 623 | }. |
| 624 | 624 | |
| 625 | 625 | |
| ... | ... | @@ -696,9 +696,10 @@ define Result(Error,Word8) |
| 696 | 696 | //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else |
| 697 | 697 | if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity |
| 698 | 698 | { |
| 699 | - failure then error(cannot_read_from_connection), | |
| 700 | - //record_dubious_connection(connection,dead_line,dos), | |
| 701 | - success(ba) then if nth(0,ba) is | |
| 699 | + error then error(cannot_read_from_connection), | |
| 700 | + //record_dubious_connection(connection,dead_line,dos), | |
| 701 | + time_out then error(timeout(600)), | |
| 702 | + ok(ba) then if nth(0,ba) is | |
| 702 | 703 | { |
| 703 | 704 | failure then error(cannot_read_from_connection), |
| 704 | 705 | success(c) then ok(c) |
| ... | ... | @@ -1631,8 +1632,9 @@ define Result(Error,ByteArray) |
| 1631 | 1632 | if retries =< 0 then error(cannot_read_from_connection) else |
| 1632 | 1633 | if read(connection,body_size,60) is |
| 1633 | 1634 | { |
| 1634 | - failure then error(cannot_read_from_connection), | |
| 1635 | - success(new_bytes) then with | |
| 1635 | + error then error(cannot_read_from_connection), | |
| 1636 | + time_out then error(timeout(60)), | |
| 1637 | + ok(new_bytes) then with | |
| 1636 | 1638 | ba = so_far + new_bytes, // contains all the bytes read so far |
| 1637 | 1639 | nr = length(ba), // total read since the beginning |
| 1638 | 1640 | nn = length(new_bytes), // number of bytes just read |
| ... | ... | @@ -1881,8 +1883,9 @@ define One |
| 1881 | 1883 | if sent >= size then unique else |
| 1882 | 1884 | if read(file,min(10000,size-sent),60) is |
| 1883 | 1885 | { |
| 1884 | - failure then log_journal_msg(desc,"Cannot read from file '"+filename+"'.\n"), | |
| 1885 | - success(ba) then | |
| 1886 | + error then log_journal_msg(desc,"Cannot read from file '"+filename+"'.\n"), | |
| 1887 | + time_out then log_journal_msg(desc,"Cannot read from file timeout '"+filename+"'.\n"), | |
| 1888 | + ok(ba) then | |
| 1886 | 1889 | with nr = length(ba), // get the number of bytes read |
| 1887 | 1890 | if reliable_write(connection,ba) is |
| 1888 | 1891 | { | ... | ... |