Commit c62e00f37e959a4880875c3c273adc85dd0df4fb

Authored by David René
1 parent c11bb75d

change the return result of read. Now the return type is ReadResult instead of M…

…aybe(ByteArray). ReadResult introduce timeout error handling.
anubis_dev/library/doc_tools/latex.anubis
... ... @@ -340,14 +340,16 @@ define Bool
340 340 wait for true
341 341 then if read(process_stdout(ec),1000,120) is
342 342 {
343   - failure then print("SO=failure \n"),
344   - success(s) then print("SO=["+to_string(s)+"]\n")
  343 + error then print("SO=failure \n"),
  344 + timeout then print("SO=timeout \n"),
  345 + ok(s) then print("SO=["+to_string(s)+"]\n")
345 346 };
346 347  
347 348 if read(process_stderr(ec),1000,120) is
348 349 {
349   - failure then print("SE=failure \n"),
350   - success(s) then print("SE=["+to_string(s)+"]\n")
  350 + error then print("SE=failure \n"),
  351 + timeout then print("SE=timeout \n"),
  352 + ok(s) then print("SE=["+to_string(s)+"]\n")
351 353 };
352 354  
353 355 if check_execute_status(ec) is
... ...
anubis_dev/library/mail/smtp_server.anubis
... ... @@ -770,8 +770,9 @@ define Maybe(ByteArray)
770 770 ) =
771 771 if read(weaken(conn),1000,480) is
772 772 {
773   - failure then failure,
774   - success(bytes) then
  773 + error then failure,
  774 + timeout then failure,
  775 + ok(bytes)then
775 776 with new = so_far+bytes,
776 777 l = length(new),
777 778 if extract(new,l-5,l) = crlf_dot_crlf
... ... @@ -975,4 +976,4 @@ public define One
975 976  
976 977  
977 978  
978   -
979 979 \ No newline at end of file
  980 +
... ...
anubis_dev/library/network/tools.anubis
... ... @@ -13,7 +13,7 @@ read system/string.anubis
13 13  
14 14 public type Byte_Net_Result:
15 15 failure,
16   - time_out,
  16 + timeout,
17 17 success(Word8).
18 18  
19 19  
... ... @@ -25,9 +25,9 @@ public define Byte_Net_Result
25 25 )=
26 26 if read(conn, 1, t_out) is
27 27 {
28   - error then failure,
29   - time_out then time_out,
30   - ok(byte) then
  28 + error then failure,
  29 + timeout then timeout,
  30 + ok(byte) then
31 31 if nth(0, byte) is
32 32 {
33 33 failure then failure,
... ... @@ -38,7 +38,7 @@ public define Byte_Net_Result
38 38  
39 39 public type Bytes_Net_Result:
40 40 failure,
41   - time_out,
  41 + timeout,
42 42 success(ByteArray),
43 43 truncated(ByteArray).
44 44  
... ... @@ -51,8 +51,8 @@ public define Byte_Net_Result
51 51 )=
52 52 if read(conn, how_many, t_out) is
53 53 {
54   - error then failure,
55   - time_out then time_out,
  54 + error then failure,
  55 + timeout then timeout,
56 56 ok(bytes) then
57 57 with len = length(bytes),
58 58 if len = how_many then
... ...
anubis_dev/library/predefined.anubis
... ... @@ -1322,7 +1322,7 @@ public define Bool
1322 1322  
1323 1323 public type ReadResult:
1324 1324 error,
1325   - time_out,
  1325 + timeout,
1326 1326 ok(ByteArray).
1327 1327  
1328 1328 // public define Maybe(ByteArray)
... ...
anubis_dev/library/system/data_io.anubis
... ... @@ -31,7 +31,7 @@ public type Data_IO:
31 31  
32 32 /* File interface */
33 33  
34   -define Int32 -> Data_IO_Result
  34 + define Int32 -> Data_IO_Result
35 35 make_read_bytes // making the 'rb' function
36 36 (
37 37 RStream file,
... ... @@ -51,7 +51,7 @@ define Int32 -> Data_IO_Result
51 51 truncated(bytes)
52 52 }.
53 53  
54   -public define Data_IO
  54 + public define Data_IO
55 55 make_data_io
56 56 (
57 57 RStream file
... ...
anubis_dev/library/system/files.anubis
... ... @@ -39,9 +39,9 @@ public define ResultCopy
39 39 copy_ok
40 40 else if read(source, read_length, 10) is
41 41 {
42   - error then copy_error,
43   - time_out then copy_error,
44   - ok(buffer) then
  42 + error then copy_error,
  43 + timeout then copy_error,
  44 + ok(buffer)then
45 45 if write( target , buffer) is
46 46 {
47 47 failure then copy_error,
... ... @@ -159,9 +159,9 @@ public define Maybe(One)
159 159 success(unique)
160 160 else if read(source_file, read_length, 10) is
161 161 {
162   - error then failure,
163   - time_out then failure,
164   - ok(buffer) then
  162 + error then failure,
  163 + timeout then failure,
  164 + ok(buffer)then
165 165 if reliable_write(tcp(socket), buffer) is
166 166 {
167 167 failure then failure,
... ...
anubis_dev/library/system/muscle.anubis
... ... @@ -1608,76 +1608,8 @@ public define Message_Send_Result
1608 1608  
1609 1609  
1610 1610  
1611   -/********************** TESTING SERVER *************************/
1612 1611  
1613   -define One
1614   - message_received
1615   - (
1616   - Message msg
1617   - )=
1618   - print("MESSAGE [" + to_ascii(*msg.what) + "] received\n");
1619   - if * msg.what = 323232 then
1620   - unique
1621   - else
1622   - unique
1623   - .
1624   -
1625   -define One
1626   - message_receiver
1627   - (
1628   - RWStream conn
1629   - ) =
1630   -
1631   - if unflatten_message(make_data_io(weaken(conn))) is
1632   - {
1633   - failure then
1634   - print("can't unflatten any message\n");
1635   - message_receiver(conn),
1636   - success(msg) then
1637   - message_received(msg);
1638   - message_receiver(conn)
1639   - }.
1640   -
1641   -define Server -> (RWStream) -> One
1642   - muscle_handler
1643   - (
1644   - One dummy
1645   - ) =
1646   - (Server server) |-> (RWStream conn) |->
1647   - if remote_IP_address_and_port(conn) is (num_peer,_) then
1648   - //convert IP address of the client to string
1649   - with peer = ip_addr_to_string(num_peer),
1650   - print("Accepting connection with "+peer+"\n");
1651   -
1652   - //now managing the AUTHORIZATION state
1653   - message_receiver(conn).
1654   -
1655   -public define One
1656   - start_muscle_server
1657   - (
1658   - One dummy
1659   - ) =
1660   - if start_server(0,
1661   - 44701,
1662   - muscle_handler(unique),
1663   - (One u) |-> unique) is
1664   - {
1665   - cannot_create_the_socket then print("Cannot create the listening socket.\n"),
1666   - cannot_bind_to_port then print("Cannot bind to port 44701\n"),
1667   - cannot_listen_on_port then print("Cannot listen on port 44701\n"),
1668   - ok(server) then print("Muscle Server started on port 44701 \n")
1669   - }.
1670   -
1671   -global define One
1672   - muscle
1673   - (
1674   - List(String) args
1675   - ) =
1676   - start_muscle_server(unique);
1677   - print("Muscle Message Test\n")
1678   - .
1679   -
1680   -global define One
  1612 + global define One
1681 1613 muscle_file
1682 1614 (
1683 1615 List(String) args
... ...
anubis_dev/library/test/all_unit_test.anubis
1 1  
  2 +read tools/basis.anubis
2 3 read tools/unit_test.anubis
3 4 read test/system/convert.unit_test.anubis
  5 +read test/system/message_queue.unit_test.anubis
4 6  
5 7  
6 8 define List(TestAction)
... ... @@ -8,7 +10,8 @@ define List(TestAction)
8 10 (
9 11 One dummy
10 12 )=
11   - make_convert_test_actions
  13 + make_convert_test_actions +
  14 + make_message_queue_test_actions
12 15 .
13 16  
14 17 global define One
... ...
anubis_dev/library/tools/basis.anubis
... ... @@ -1800,7 +1800,7 @@ define Maybe(ByteArray)
1800 1800 if read(conn,n,1) is
1801 1801 {
1802 1802 error then failure,
1803   - time_out then failure,
  1803 + timeout then failure,
1804 1804 ok(ba) then
1805 1805 with l = length(ba),
1806 1806 if l = n
... ...
anubis_dev/library/web/http_server.anubis
... ... @@ -487,8 +487,9 @@ define Maybe(Word8)
487 487 ) =
488 488 if read(connection,1,60) is
489 489 {
490   - failure then failure,
491   - success(ba) then nth(0,ba)
  490 + error then failure,
  491 + timeout then failure,
  492 + ok(ba) then nth(0,ba)
492 493 }.
493 494  
494 495  
... ... @@ -1445,8 +1446,9 @@ define Result(Error,ByteArray)
1445 1446 if retries =< 0 then error(cannot_read_from_connection) else
1446 1447 if read(connection,body_size,60) is
1447 1448 {
1448   - failure then error(cannot_read_from_connection),
1449   - success(new_bytes) then with
  1449 + error then error(cannot_read_from_connection),
  1450 + timeout then error(cannot_read_from_connection),
  1451 + ok(new_bytes) then with
1450 1452 ba = so_far + new_bytes, // contains all the bytes read so far
1451 1453 nr = length(ba), // total read since the beginning
1452 1454 nn = length(new_bytes), // number of bytes just read
... ... @@ -1695,8 +1697,9 @@ define One
1695 1697 if sent >= size then unique else
1696 1698 if read(file,min(10000,size-sent),60) is
1697 1699 {
1698   - failure then log_journal_msg(desc,"Cannot read from file '"+filename+"'.\n"),
1699   - success(ba) then
  1700 + error then log_journal_msg(desc,"Cannot read from file '"+filename+"'.\n"),
  1701 + timeout then log_journal_msg(desc,"Cannot read from file timeout'"+filename+"'.\n"),
  1702 + ok(ba) then
1700 1703 with nr = length(ba), // get the number of bytes read
1701 1704 if reliable_write(connection,ba) is
1702 1705 {
... ... @@ -2582,4 +2585,4 @@ public define One
2582 2585  
2583 2586  
2584 2587  
2585   -
2586 2588 \ No newline at end of file
  2589 +
... ...
anubis_dev/library/web/multihost_http_server.anubis
... ... @@ -698,7 +698,7 @@ define Result(Error,Word8)
698 698 {
699 699 error then error(cannot_read_from_connection),
700 700 //record_dubious_connection(connection,dead_line,dos),
701   - time_out then error(timeout(600)),
  701 + timeout then error(timeout(600)),
702 702 ok(ba) then if nth(0,ba) is
703 703 {
704 704 failure then error(cannot_read_from_connection),
... ... @@ -1633,7 +1633,7 @@ define Result(Error,ByteArray)
1633 1633 if read(connection,body_size,60) is
1634 1634 {
1635 1635 error then error(cannot_read_from_connection),
1636   - time_out then error(timeout(60)),
  1636 + timeout then error(timeout(60)),
1637 1637 ok(new_bytes) then with
1638 1638 ba = so_far + new_bytes, // contains all the bytes read so far
1639 1639 nr = length(ba), // total read since the beginning
... ... @@ -1884,7 +1884,7 @@ define One
1884 1884 if read(file,min(10000,size-sent),60) is
1885 1885 {
1886 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"),
  1887 + timeout then log_journal_msg(desc,"Cannot read from file timeout '"+filename+"'.\n"),
1888 1888 ok(ba) then
1889 1889 with nr = length(ba), // get the number of bytes read
1890 1890 if reliable_write(connection,ba) is
... ...