Commit aafb9501a8ab51f562b574158289ee850f6e7222

Authored by David René
1 parent 8a8a9890

ensure the send of the entire message throught the network

anubis_dev/library/system/message_transceiver.anubis
... ... @@ -44,6 +44,7 @@ define DataResult
44 44 ok(bytes) then
45 45 with len_fragment = length(bytes),
46 46 new_buffer = current + bytes,
  47 +// println("fragment "+len_fragment + " total : "+length(new_buffer));
47 48 receive_data(conn, len_left - len_fragment, new_buffer)
48 49 }
49 50 .
... ... @@ -71,10 +72,10 @@ define One
71 72 else
72 73 with buffer_len = length(current_buffer),
73 74 if buffer_len = 8 then
74   - //println("buffer len 8 bytes [" + to_hexa(current_buffer));
  75 +// println("buffer len 8 bytes [" + to_hexa(current_buffer));
75 76 if is_header(current_buffer) then
76 77 with message_len = lendian_to_host_Int32(extract(current_buffer, 0, 4)),
77   - // println("Message length "+message_len);
  78 +// println("Message length "+message_len);
78 79 if receive_data(conn, message_len, constant_byte_array(0,0)) is
79 80 {
80 81 failure then
... ... @@ -97,7 +98,7 @@ define One
97 98 //TODO manage the timeout
98 99 message_receiver(conn, queue, current_buffer),
99 100 ok(bytes) then
100   - //println("receiver bytes " + to_hexa(bytes));
  101 +// println("receiver bytes " + to_hexa(bytes));
101 102 with new_buffer = current_buffer + bytes,
102 103 message_receiver(conn, queue, new_buffer)
103 104 }
... ...
anubis_dev/library/system/muscle.anubis
... ... @@ -1580,6 +1580,28 @@ public define Message_Send_Result
1580 1580 }
1581 1581 }.
1582 1582  
  1583 +public define Maybe(Int32)
  1584 + send_buffer
  1585 + (
  1586 + RWStream conn,
  1587 + ByteArray buffer,
  1588 + Int32 left_to_send,
  1589 + Int32 so_far
  1590 + )=
  1591 + if left_to_send = 0 then
  1592 + success(so_far)
  1593 + else
  1594 + if write(weaken(conn), buffer) is
  1595 + {
  1596 + failure then failure,
  1597 + success(len)then
  1598 + if left_to_send = len then
  1599 + success(so_far+len)
  1600 + else
  1601 + send_buffer(conn, extract(buffer, len, length(buffer)), left_to_send - len, so_far+len)
  1602 + }
  1603 + .
  1604 +
1583 1605 public define Message_Send_Result
1584 1606 send_message_by_Stream
1585 1607 (
... ... @@ -1593,15 +1615,15 @@ public define Message_Send_Result
1593 1615 with header = host_to_lendian_Int32_ByteArray(length(buffer)) +
1594 1616 host_to_lendian_Int32_ByteArray(_MUSCLE_MESSAGE_ENCODING_DEFAULT),
1595 1617 //send the header. that header is construct as follow (size of the following message + header mark)
1596   - if write(weaken(conn),header) is
  1618 + if send_buffer(conn,header, length(header), 0) is
1597 1619 {
1598 1620 failure then network_error,
1599 1621 success(_) then
1600 1622 //now we send the real message
1601   - if write(weaken(conn), buffer) is
  1623 + if send_buffer(conn, buffer, length(buffer), 0) is
1602 1624 {
1603 1625 failure then network_error,
1604   - success(_) then ok
  1626 + success(len)then ok
1605 1627 }
1606 1628 }
1607 1629 }.
... ...