Commit 3d8d124de4c16235151c32e645e09f42f8ff679e
1 parent
81b57275
adding function receive_message_from_io() into muscle
correction on send_message_to_udp()
Showing
1 changed file
with
24 additions
and
9 deletions
Show diff stats
anubis_dev/library/system/muscle.anubis
| ... | ... | @@ -1564,21 +1564,36 @@ public define Message_Send_Result |
| 1564 | 1564 | ok(socket) then |
| 1565 | 1565 | //the necessary UDP socket was created, hence we send the Message packet |
| 1566 | 1566 | with header = host_to_lendian_Int32_ByteArray(length(buffer)) + |
| 1567 | - host_to_lendian_Int32_ByteArray(_MUSCLE_MESSAGE_ENCODING_DEFAULT), | |
| 1568 | - //send the header. that header is construct as follow (size of the following message + header mark) | |
| 1567 | + host_to_lendian_Int32_ByteArray(_MUSCLE_MESSAGE_ENCODING_DEFAULT) + | |
| 1568 | + buffer, | |
| 1569 | + //send the header + buffer. that header is construct as follow (size of the following message + header mark) | |
| 1569 | 1570 | if udp_send(socket, ip_address, ip_port, header) is |
| 1570 | 1571 | { |
| 1571 | 1572 | network_unreachable then network_error, |
| 1572 | - packet_sent then | |
| 1573 | - //now we send the real message | |
| 1574 | - if udp_send(socket, ip_address, ip_port, buffer) is | |
| 1575 | - { | |
| 1576 | - network_unreachable then network_error, | |
| 1577 | - packet_sent then ok | |
| 1578 | - } | |
| 1573 | + packet_sent then ok | |
| 1579 | 1574 | } |
| 1580 | 1575 | } |
| 1581 | 1576 | }. |
| 1577 | + | |
| 1578 | +public define Maybe(Message) | |
| 1579 | + receive_message_from_io | |
| 1580 | + ( | |
| 1581 | + Data_IO io | |
| 1582 | + ) = | |
| 1583 | + if read_Int32(io) is | |
| 1584 | + { | |
| 1585 | + failure then print("Can't read data \n"); failure, | |
| 1586 | + success(data_len) then | |
| 1587 | + if read_Int32(io) is | |
| 1588 | + { | |
| 1589 | + failure then print("Can't read data \n"); failure, | |
| 1590 | + success(encoding) then | |
| 1591 | + if encoding = _MUSCLE_MESSAGE_ENCODING_DEFAULT then | |
| 1592 | + unflatten_message(io) | |
| 1593 | + else print("Bad header or unknown encoding:" + encoding); failure | |
| 1594 | + } | |
| 1595 | + }. | |
| 1596 | + | |
| 1582 | 1597 | |
| 1583 | 1598 | public define Maybe(Int32) |
| 1584 | 1599 | send_buffer | ... | ... |