diff --git a/calexium_lib/net_services/CXM_generic_protocol.anubis b/calexium_lib/net_services/CXM_generic_protocol.anubis index 8a09870..2a64403 100644 --- a/calexium_lib/net_services/CXM_generic_protocol.anubis +++ b/calexium_lib/net_services/CXM_generic_protocol.anubis @@ -9,6 +9,7 @@ read system/muscle.anubis read system/data_io.anubis +read system/string.anubis read tools/basis.anubis read system/message_queue.anubis read calexium_lib/CXM_message_constants.anubis @@ -17,6 +18,14 @@ public define Int32 _CXM_ERROR = 0. public define Int32 _CXM_OK = 1. public define Int32 _CXM_UNKNOW_CMD = 2. +public type ProtocolResult: + failure, + timeout, + unknow_cmd, + error, + ok, + ok_msg(Message). + public define One send_ACK_error ( @@ -68,15 +77,43 @@ public define One } . - public define Maybe(Message) +public define ProtocolResult wait_for_reply ( - RWStream conn + MessageQueue mQ, + Int32 wait_cmd, + Int32 t_out ) = - if unflatten_message(make_data_io(weaken(conn))) is + if mQ.get_next_received_Message(t_out) is { - failure then - sleep(1); - wait_for_reply(conn), - success(msg) then success(msg) - }. + timeout then timeout, + closed then println("wait_for_reply closed");failure, + msg(_msg) then + if *_msg.what = _CXM_ACK then + if find_int32(_msg, "CMD") is + { + failure then println("wait_for_reply CMD");failure, + success(cmd) then + println("wait_for_reply CMD="+to_hexa(cmd)); + if find_int32(_msg, "STATUS") is + { + failure then println("wait_for_reply STATUS");failure, + success(status) then + if cmd = wait_cmd & status = _CXM_OK then + if find_message(_msg, "RESULT") is + { + failure then ok, + success(ok_message) then ok_msg(ok_message) + } + else if cmd = wait_cmd & status = _CXM_ERROR then + error + else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then + unknow_cmd + else + println("wait_for_reply ");failure + } + } + else + println("wait_for_reply not ACK");failure + }. + diff --git a/calexium_lib/net_services/CXM_net_services.anubis b/calexium_lib/net_services/CXM_net_services.anubis index dbf2a04..430b4dd 100644 --- a/calexium_lib/net_services/CXM_net_services.anubis +++ b/calexium_lib/net_services/CXM_net_services.anubis @@ -90,11 +90,13 @@ define One Message msg, List(NetService) net_services )= - print("MESSAGE [" + to_ascii(*msg.what) + "] received\n"); + //TODO add a real management of error + println("Service NEGOCIATION [" + to_hexa(*msg.what) + "] received"); if * msg.what = _CXM_REQUEST_FOR_SERVICE then if has_service(queue, msg, net_services) is { - failure then unique, + failure then + send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE), success(net_service) then send_ACK_ok(queue, _CXM_REQUEST_FOR_SERVICE); net_service.handler(queue) @@ -114,12 +116,12 @@ define One MessageQueue queue, List(NetService) net_services ) = - - if queue.get_next_received_Message(10) is + println("PRE SERVICE message_receiver "+"["+virtual_machine_id + "]"); + if queue.get_next_received_Message(1) is { - timeout then message_receiver(queue, net_services), - closed then unique, - msg(msg) then + timeout then println("PRE timeout");message_receiver(queue, net_services), + closed then println("PRE closed");unique, + msg(msg) then println("PRE negociation"); service_negociation(queue, msg, net_services); message_receiver(queue, net_services) }. @@ -132,8 +134,8 @@ define Server -> (RWStream) -> One (Server server) |-> (RWStream conn) |-> if remote_IP_address_and_port(conn) is (num_peer,_) then //convert IP address of the client to string - // with peer = ip_addr_to_string(num_peer), - // print("NET SERVICES Accepting connection with "+peer+"\n"); + with peer = ip_addr_to_string(num_peer), + println("NET SERVICES Accepting connection with "+peer); //now managing the list of SERVICES with queue = create_MessageQueue, -- libgit2 0.21.4