Commit 5da3baefc1bd2246c8994f12e3e0ff883053ef76

Authored by David RENE
1 parent 0071bc67

add ftp service

improve wait_for_reply
calexium_lib/net_services/CXM_generic_protocol.anubis
... ... @@ -9,6 +9,7 @@
9 9  
10 10 read system/muscle.anubis
11 11 read system/data_io.anubis
  12 +read system/string.anubis
12 13 read tools/basis.anubis
13 14 read system/message_queue.anubis
14 15 read calexium_lib/CXM_message_constants.anubis
... ... @@ -17,6 +18,14 @@ public define Int32 _CXM_ERROR = 0.
17 18 public define Int32 _CXM_OK = 1.
18 19 public define Int32 _CXM_UNKNOW_CMD = 2.
19 20  
  21 +public type ProtocolResult:
  22 + failure,
  23 + timeout,
  24 + unknow_cmd,
  25 + error,
  26 + ok,
  27 + ok_msg(Message).
  28 +
20 29 public define One
21 30 send_ACK_error
22 31 (
... ... @@ -68,15 +77,43 @@ public define One
68 77 }
69 78 .
70 79  
71   - public define Maybe(Message)
  80 +public define ProtocolResult
72 81 wait_for_reply
73 82 (
74   - RWStream conn
  83 + MessageQueue mQ,
  84 + Int32 wait_cmd,
  85 + Int32 t_out
75 86 ) =
76   - if unflatten_message(make_data_io(weaken(conn))) is
  87 + if mQ.get_next_received_Message(t_out) is
77 88 {
78   - failure then
79   - sleep(1);
80   - wait_for_reply(conn),
81   - success(msg) then success(msg)
82   - }.
  89 + timeout then timeout,
  90 + closed then println("wait_for_reply closed");failure,
  91 + msg(_msg) then
  92 + if *_msg.what = _CXM_ACK then
  93 + if find_int32(_msg, "CMD") is
  94 + {
  95 + failure then println("wait_for_reply CMD");failure,
  96 + success(cmd) then
  97 + println("wait_for_reply CMD="+to_hexa(cmd));
  98 + if find_int32(_msg, "STATUS") is
  99 + {
  100 + failure then println("wait_for_reply STATUS");failure,
  101 + success(status) then
  102 + if cmd = wait_cmd & status = _CXM_OK then
  103 + if find_message(_msg, "RESULT") is
  104 + {
  105 + failure then ok,
  106 + success(ok_message) then ok_msg(ok_message)
  107 + }
  108 + else if cmd = wait_cmd & status = _CXM_ERROR then
  109 + error
  110 + else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then
  111 + unknow_cmd
  112 + else
  113 + println("wait_for_reply ");failure
  114 + }
  115 + }
  116 + else
  117 + println("wait_for_reply not ACK");failure
  118 + }.
  119 +
... ...
calexium_lib/net_services/CXM_net_services.anubis
... ... @@ -90,11 +90,13 @@ define One
90 90 Message msg,
91 91 List(NetService) net_services
92 92 )=
93   - print("MESSAGE [" + to_ascii(*msg.what) + "] received\n");
  93 + //TODO add a real management of error
  94 + println("Service NEGOCIATION [" + to_hexa(*msg.what) + "] received");
94 95 if * msg.what = _CXM_REQUEST_FOR_SERVICE then
95 96 if has_service(queue, msg, net_services) is
96 97 {
97   - failure then unique,
  98 + failure then
  99 + send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE),
98 100 success(net_service) then
99 101 send_ACK_ok(queue, _CXM_REQUEST_FOR_SERVICE);
100 102 net_service.handler(queue)
... ... @@ -114,12 +116,12 @@ define One
114 116 MessageQueue queue,
115 117 List(NetService) net_services
116 118 ) =
117   -
118   - if queue.get_next_received_Message(10) is
  119 + println("PRE SERVICE message_receiver "+"["+virtual_machine_id + "]");
  120 + if queue.get_next_received_Message(1) is
119 121 {
120   - timeout then message_receiver(queue, net_services),
121   - closed then unique,
122   - msg(msg) then
  122 + timeout then println("PRE timeout");message_receiver(queue, net_services),
  123 + closed then println("PRE closed");unique,
  124 + msg(msg) then println("PRE negociation");
123 125 service_negociation(queue, msg, net_services);
124 126 message_receiver(queue, net_services)
125 127 }.
... ... @@ -132,8 +134,8 @@ define Server -> (RWStream) -> One
132 134 (Server server) |-> (RWStream conn) |->
133 135 if remote_IP_address_and_port(conn) is (num_peer,_) then
134 136 //convert IP address of the client to string
135   - // with peer = ip_addr_to_string(num_peer),
136   - // print("NET SERVICES Accepting connection with "+peer+"\n");
  137 + with peer = ip_addr_to_string(num_peer),
  138 + println("NET SERVICES Accepting connection with "+peer);
137 139  
138 140 //now managing the list of SERVICES
139 141 with queue = create_MessageQueue,
... ...