Commit 0071bc67de282fc624a8d0a70654eb27433991de

Authored by David RENE
1 parent 75c12334

update web/CXM_multihost_http_server to manage timeout in read function

add FTP constant definition
change net_services functions that now use MessageQueue instead of RWStream socket
calexium_lib/CXM_message_constants.anubis
@@ -39,3 +39,7 @@ public define Int32 _CXM_ACK_RESULT_MSG = 0x33771002. // @@ -39,3 +39,7 @@ public define Int32 _CXM_ACK_RESULT_MSG = 0x33771002. //
39 39
40 public define Int32 _CXM_FTP_SERVICE_MSG_BASIS = 0x33771400. // 40 public define Int32 _CXM_FTP_SERVICE_MSG_BASIS = 0x33771400. //
41 public define Int32 _CXM_FTP_SERVICE_ID = 0x33771401. 41 public define Int32 _CXM_FTP_SERVICE_ID = 0x33771401.
  42 +public define Int32 _CXM_FTP_GET_FILE = 0x33771402.
  43 +public define Int32 _CXM_FTP_START_TRANSFERT = 0x33771403.
  44 +public define Int32 _CXM_FTP_DATA = 0x33771404.
  45 +
calexium_lib/net_services/CXM_generic_protocol.anubis
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 read system/muscle.anubis 10 read system/muscle.anubis
11 read system/data_io.anubis 11 read system/data_io.anubis
12 read tools/basis.anubis 12 read tools/basis.anubis
13 - 13 +read system/message_queue.anubis
14 read calexium_lib/CXM_message_constants.anubis 14 read calexium_lib/CXM_message_constants.anubis
15 15
16 public define Int32 _CXM_ERROR = 0. 16 public define Int32 _CXM_ERROR = 0.
@@ -20,31 +20,30 @@ public define Int32 _CXM_UNKNOW_CMD = 2. @@ -20,31 +20,30 @@ public define Int32 _CXM_UNKNOW_CMD = 2.
20 public define One 20 public define One
21 send_ACK_error 21 send_ACK_error
22 ( 22 (
23 - RWStream conn, 23 + MessageQueue queue,
24 Int32 cmd_id 24 Int32 cmd_id
25 )= 25 )=
26 with err_msg = message(_CXM_ACK), 26 with err_msg = message(_CXM_ACK),
27 forget(add_int32(err_msg, "CMD", cmd_id)); 27 forget(add_int32(err_msg, "CMD", cmd_id));
28 forget(add_int32(err_msg, "STATUS", _CXM_ERROR)); 28 forget(add_int32(err_msg, "STATUS", _CXM_ERROR));
29 - forget(send_message_by_Stream(conn, err_msg))  
30 - . 29 + forget(queue.add_Message_to_send(err_msg)).
31 30
32 public define One 31 public define One
33 send_ACK_ok 32 send_ACK_ok
34 ( 33 (
35 - RWStream conn,  
36 - Int32 cmd_id 34 + MessageQueue queue,
  35 + Int32 cmd_id
37 )= 36 )=
38 with ok_msg = message(_CXM_ACK), 37 with ok_msg = message(_CXM_ACK),
39 forget(add_int32(ok_msg, "CMD", cmd_id)); 38 forget(add_int32(ok_msg, "CMD", cmd_id));
40 forget(add_int32(ok_msg, "STATUS", _CXM_OK)); 39 forget(add_int32(ok_msg, "STATUS", _CXM_OK));
41 - forget(send_message_by_Stream(conn, ok_msg)) 40 + forget(queue.add_Message_to_send(ok_msg))
42 . 41 .
43 42
44 public define One 43 public define One
45 send_ACK_ok 44 send_ACK_ok
46 ( 45 (
47 - RWStream conn, 46 + MessageQueue queue,
48 Int32 cmd_id, 47 Int32 cmd_id,
49 Message result 48 Message result
50 )= 49 )=
@@ -52,24 +51,24 @@ public define One @@ -52,24 +51,24 @@ public define One
52 forget(add_int32(ok_msg, "CMD", cmd_id)); 51 forget(add_int32(ok_msg, "CMD", cmd_id));
53 forget(add_int32(ok_msg, "STATUS", _CXM_OK)); 52 forget(add_int32(ok_msg, "STATUS", _CXM_OK));
54 forget(add_message(ok_msg, "RESULT", result)); 53 forget(add_message(ok_msg, "RESULT", result));
55 - forget(send_message_by_Stream(conn, ok_msg)) 54 + forget(queue.add_Message_to_send(ok_msg))
56 . 55 .
57 56
58 public define One 57 public define One
59 send_result 58 send_result
60 ( 59 (
61 - RWStream conn, 60 + MessageQueue queue,
62 Int32 cmd_id, 61 Int32 cmd_id,
63 Maybe(Message) mb_msg 62 Maybe(Message) mb_msg
64 )= 63 )=
65 if mb_msg is 64 if mb_msg is
66 { 65 {
67 - failure then send_ACK_error(conn, cmd_id),  
68 - success(msg) then send_ACK_ok(conn, cmd_id, msg) 66 + failure then send_ACK_error(queue, cmd_id),
  67 + success(msg) then send_ACK_ok(queue, cmd_id, msg)
69 } 68 }
70 . 69 .
71 70
72 -public define Maybe(Message) 71 + public define Maybe(Message)
73 wait_for_reply 72 wait_for_reply
74 ( 73 (
75 RWStream conn 74 RWStream conn
calexium_lib/net_services/CXM_net_services.anubis
@@ -11,7 +11,8 @@ read system/convert.anubis @@ -11,7 +11,8 @@ read system/convert.anubis
11 read system/string.anubis 11 read system/string.anubis
12 read system/muscle.anubis 12 read system/muscle.anubis
13 read system/data_io.anubis 13 read system/data_io.anubis
14 - 14 +read system/message_queue.anubis
  15 +read system/message_transceiver.anubis
15 read CXM_generic_protocol.anubis 16 read CXM_generic_protocol.anubis
16 read calexium_lib/CXM_message_constants.anubis 17 read calexium_lib/CXM_message_constants.anubis
17 18
@@ -20,7 +21,7 @@ public type NetService: @@ -20,7 +21,7 @@ public type NetService:
20 Int32 version, 21 Int32 version,
21 Int32 id, 22 Int32 id,
22 String name, 23 String name,
23 - (RWStream) -> One handler 24 + (MessageQueue) -> One handler
24 ). 25 ).
25 26
26 define One 27 define One
@@ -62,17 +63,17 @@ define Maybe(NetService) @@ -62,17 +63,17 @@ define Maybe(NetService)
62 define Maybe(NetService) 63 define Maybe(NetService)
63 has_service 64 has_service
64 ( 65 (
65 - RWStream conn,  
66 - Message msg, 66 + MessageQueue queue,
  67 + Message msg,
67 List(NetService) net_services 68 List(NetService) net_services
68 )= 69 )=
69 if find_int32(msg, "service") is 70 if find_int32(msg, "service") is
70 { 71 {
71 - failure then send_ACK_error(conn, _CXM_REQUEST_FOR_SERVICE); failure, 72 + failure then send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE); failure,
72 success(service_id) then 73 success(service_id) then
73 if find_int32(msg, "version") is 74 if find_int32(msg, "version") is
74 { 75 {
75 - failure then send_ACK_error(conn, _CXM_REQUEST_FOR_SERVICE);failure, 76 + failure then send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE);failure,
76 success(service_version) then find_service(net_services, service_id, service_version) 77 success(service_version) then find_service(net_services, service_id, service_version)
77 } 78 }
78 }. 79 }.
@@ -85,18 +86,18 @@ define Maybe(NetService) @@ -85,18 +86,18 @@ define Maybe(NetService)
85 define One 86 define One
86 service_negociation 87 service_negociation
87 ( 88 (
88 - RWStream conn,  
89 - Message msg, 89 + MessageQueue queue,
  90 + Message msg,
90 List(NetService) net_services 91 List(NetService) net_services
91 )= 92 )=
92 print("MESSAGE [" + to_ascii(*msg.what) + "] received\n"); 93 print("MESSAGE [" + to_ascii(*msg.what) + "] received\n");
93 if * msg.what = _CXM_REQUEST_FOR_SERVICE then 94 if * msg.what = _CXM_REQUEST_FOR_SERVICE then
94 - if has_service(conn, msg, net_services) is 95 + if has_service(queue, msg, net_services) is
95 { 96 {
96 failure then unique, 97 failure then unique,
97 success(net_service) then 98 success(net_service) then
98 - send_ACK_ok(conn, _CXM_REQUEST_FOR_SERVICE);  
99 - net_service.handler(conn) 99 + send_ACK_ok(queue, _CXM_REQUEST_FOR_SERVICE);
  100 + net_service.handler(queue)
100 } 101 }
101 else 102 else
102 unique 103 unique
@@ -110,19 +111,17 @@ define One @@ -110,19 +111,17 @@ define One
110 define One 111 define One
111 message_receiver 112 message_receiver
112 ( 113 (
113 - RWStream conn, 114 + MessageQueue queue,
114 List(NetService) net_services 115 List(NetService) net_services
115 ) = 116 ) =
116 117
117 - if unflatten_message(make_data_io(weaken(conn))) is 118 + if queue.get_next_received_Message(10) is
118 { 119 {
119 - failure then  
120 - //print("can't unflatten any message\n");  
121 - sleep(1);  
122 - message_receiver(conn, net_services),  
123 - success(msg) then  
124 - service_negociation(conn, msg, net_services);  
125 - message_receiver(conn, net_services) 120 + timeout then message_receiver(queue, net_services),
  121 + closed then unique,
  122 + msg(msg) then
  123 + service_negociation(queue, msg, net_services);
  124 + message_receiver(queue, net_services)
126 }. 125 }.
127 126
128 define Server -> (RWStream) -> One 127 define Server -> (RWStream) -> One
@@ -137,7 +136,9 @@ define Server -> (RWStream) -> One @@ -137,7 +136,9 @@ define Server -> (RWStream) -> One
137 // print("NET SERVICES Accepting connection with "+peer+"\n"); 136 // print("NET SERVICES Accepting connection with "+peer+"\n");
138 137
139 //now managing the list of SERVICES 138 //now managing the list of SERVICES
140 - message_receiver(conn, net_services). 139 + with queue = create_MessageQueue,
  140 + message_transceiver(conn, queue);
  141 + message_receiver(queue, net_services).
141 142
142 143
143 public define Maybe(Server) 144 public define Maybe(Server)
calexium_lib/net_services_protocols/pkg_updater_protocol.anubis
@@ -7,5 +7,6 @@ @@ -7,5 +7,6 @@
7 * 7 *
8 */ 8 */
9 9
  10 +
10 public define Int32 no_update = 0. 11 public define Int32 no_update = 0.
11 public define Int32 update_available = 1. 12 public define Int32 update_available = 1.
calexium_lib/web/CXM_multihost_http_server.anubis
@@ -696,9 +696,10 @@ define Result(Error,Word8) @@ -696,9 +696,10 @@ define Result(Error,Word8)
696 //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else 696 //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else
697 if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity 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), 699 + error then error(cannot_read_from_connection),
  700 + timeout then error(timeout(600)),
700 //record_dubious_connection(connection,dead_line,dos), 701 //record_dubious_connection(connection,dead_line,dos),
701 - success(ba) then if nth(0,ba) is 702 + ok(ba) then if nth(0,ba) is
702 { 703 {
703 failure then error(cannot_read_from_connection), 704 failure then error(cannot_read_from_connection),
704 success(c) then ok(c) 705 success(c) then ok(c)
@@ -1631,8 +1632,9 @@ define Result(Error,ByteArray) @@ -1631,8 +1632,9 @@ define Result(Error,ByteArray)
1631 if retries =< 0 then error(cannot_read_from_connection) else 1632 if retries =< 0 then error(cannot_read_from_connection) else
1632 if read(connection,body_size,60) is 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 + timeout then error(timeout(60)),
  1637 + ok(new_bytes) then with
1636 ba = so_far + new_bytes, // contains all the bytes read so far 1638 ba = so_far + new_bytes, // contains all the bytes read so far
1637 nr = length(ba), // total read since the beginning 1639 nr = length(ba), // total read since the beginning
1638 nn = length(new_bytes), // number of bytes just read 1640 nn = length(new_bytes), // number of bytes just read
@@ -1881,8 +1883,9 @@ define One @@ -1881,8 +1883,9 @@ define One
1881 if sent >= size then unique else 1883 if sent >= size then unique else
1882 if read(file,min(10000,size-sent),60) is 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 + timeout then log_journal_msg(desc,"Cannot read from file timeoput'"+filename+"'.\n"),
  1888 + ok(ba) then
1886 with nr = length(ba), // get the number of bytes read 1889 with nr = length(ba), // get the number of bytes read
1887 if reliable_write(connection,ba) is 1890 if reliable_write(connection,ba) is
1888 { 1891 {