some buf gixes + cleanup

This commit is contained in:
Taha authored and Adeel Khan committed 2024-10-03 17:54:28 +05:00
1 parent cc43e9d3a4
commit 5ef862b026
14 files changed
+121 -94

No files matched your search

@@ -45,7 +45,7 @@ namespace bts {
_peer_conn_info = get_peer_address();
_self_conn_info = get_self_address();
Log.Gen.info("AsyncTCPConnection_AsyncWrapper.cons _peer_conn_info: {_peer_conn_info} _self_conn_info: {_self_conn_info}");
_detect_connection_status_change();
//_detect_connection_status_change();
}
private void _detect_connection_status_change() {
@@ -75,7 +75,7 @@ namespace bts {
int n_bytes = buffer.Length;
int n_transfers = 0;
while (total_bytes_sent < n_bytes) {
while (_is_alive && total_bytes_sent < n_bytes) {
int remaining_bytes = n_bytes - total_bytes_sent;
_nw_stream.Write(buffer, total_bytes_sent, remaining_bytes);
total_bytes_sent += remaining_bytes;
@@ -141,7 +141,7 @@ namespace bts {
byte[] buffer = new byte[n_bytes];
int total_bytes_read = 0;
int n_transfers = 0;
while (total_bytes_read < n_bytes) {
while (_is_alive && total_bytes_read < n_bytes) {
int bytes_read = _nw_stream.Read(buffer, total_bytes_read, n_bytes - total_bytes_read);
if (bytes_read <= 0) {
throw new IOException("Read 0 bytes, the connection was closed before all data could be read.");
@@ -201,6 +201,7 @@ namespace bts {
if (one_msg.msg_type == DATA_MSG_SIGNAL) {
_msg_handler.onData(new RemoteMessage(one_msg.data, RemoteMessageType.Data, _peer_conn_info));
} else if (one_msg.msg_type == HB_MSG_SIGNAL) {
// keep a last hb time an dudpate it here atomically
_msg_handler.onData(new RemoteMessage(null, RemoteMessageType.Heartbeat, _peer_conn_info));
} else {
throw new ApplicationException($"Unknown message type: {one_msg.msg_type}");
@@ -265,5 +266,11 @@ namespace bts {
Dispose();
}
}
public override string ToString() {
RemoteConnectionInfo self = get_self_address(),
peer = get_peer_address();
return $"type: {GetType().ToString()} self: {self} peer: {peer} is_disposed: {isDisposed}";
}
}
}