diff --git a/src/DataStreamSuite/DataStreamPublisher/Program.cs b/src/DataStreamSuite/DataStreamPublisher/Program.cs index 01ac4ee84..a47d19827 100644 --- a/src/DataStreamSuite/DataStreamPublisher/Program.cs +++ b/src/DataStreamSuite/DataStreamPublisher/Program.cs @@ -11,9 +11,11 @@ using System.Threading; bts.Log.Gen.info($"Starting DSPublisher"); Console.WriteLine("Starting DSPublisher..."); -bool run_echo_tcp_client_only = false; -static void init(string[] args) { - Func login = async (l, p) => { +bool run_echo_tcp_client_only = true; +static void init(string[] args) +{ + Func login = async (l, p) => + { var login = l; var passwd = p; var service_ctx = bts.api.core.ServiceContext.create(); @@ -29,26 +31,32 @@ if (run_echo_tcp_client_only) else _publish_streams(); -static ViewStream build_stream(string stream_expression) { - try { +static ViewStream build_stream(string stream_expression) +{ + try + { var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression); var rv = exp.getView(new Dictionary(0)); return rv; - } catch (Exception ex) { + } + catch (Exception ex) + { bts.Log.assert(false, $"Could not build stream: {stream_expression} ex: {ex}"); return null; } } -async Task start_echo_client() { +async Task start_echo_client() +{ Console.WriteLine("Starting DSPublisher in TCP client echo mode, Hit key to continue"); Console.ReadLine(); await SimpleTCPClientAsync.start("127.0.0.1", 12345); Task.Delay(1000000000).Wait(); } -void _publish_streams() { +void _publish_streams() +{ PubTableBroker pb_broker = new PubTableBroker(); CloudStreamManager csm = new CloudStreamManager(); // get it from config @@ -61,14 +69,16 @@ void _publish_streams() { {"literal_420","literal(\"x\", \"420.0\")"}, // {"bbo_ts","timeSeries(bbo())"} }; - foreach (var kv in streams_to_publish) { + foreach (var kv in streams_to_publish) + { var name = kv.Key; var exp = kv.Value; BCG.ViewStream vs = build_stream(exp); ViewPublisher vpub = new ViewPublisher(name, pb_broker, vs); vs.onChange += on_change; } - while (true) { + while (true) + { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); ViewStreamDatabase.instance.doWork(); csm.doWork(); @@ -77,6 +87,7 @@ void _publish_streams() { -void on_change(object obj) { +void on_change(object obj) +{ bts.Log.Gen.info($"DSPublisher on_change dp: {obj}"); } \ No newline at end of file diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection2.cs b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection2.cs index 524b44f58..48e5d7d96 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection2.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection2.cs @@ -1,248 +1,248 @@ -using BCG; +// using BCG; -using Google.Protobuf; +// using Google.Protobuf; -using System; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using BCG; -using System.Xml.Serialization; -using System.Reflection; -using BCG.Utilities.General; -using System.Net.WebSockets; +// using System; +// using System.IO; +// using System.Linq; +// using System.Net; +// using System.Net.Sockets; +// using System.Runtime.CompilerServices; +// using System.Text; +// using System.Threading.Tasks; +// using BCG; +// using System.Xml.Serialization; +// using System.Reflection; +// using BCG.Utilities.General; +// using System.Net.WebSockets; -namespace BCG { +// namespace BCG { - public class AsyncTCPConnection2 : ITCPConnection, IWorker, IDisposable { - private Socket _socket; - // tied to the socket above - private NetworkStream _nw_stream; - private readonly ConnectionSide _side; - ITCPMessageHandler _message_handler; - private int _msg_id = 0; - RemoteConnectionInfo _peer_address; - RemoteConnectionInfo _self_address; - private TimeSpan _hb_period = TimeSpan.FromSeconds(1); - private DateTime _last_hb_sent = DateTime.MinValue; - private DateTime _last_hb_received = DateTime.MaxValue; - private static byte _msg_type_data = 1; - private static byte _msg_type_hb = 0; - private bool _is_disposed = false; - SyncQueue _data_send_queue = new SyncQueue(); +// public class AsyncTCPConnection2 : ITCPConnection, IWorker, IDisposable { +// private Socket _socket; +// // tied to the socket above +// private NetworkStream _nw_stream; +// private readonly ConnectionSide _side; +// ITCPMessageHandler _message_handler; +// private int _msg_id = 0; +// RemoteConnectionInfo _peer_address; +// RemoteConnectionInfo _self_address; +// private TimeSpan _hb_period = TimeSpan.FromSeconds(1); +// private DateTime _last_hb_sent = DateTime.MinValue; +// private DateTime _last_hb_received = DateTime.MaxValue; +// private static byte _msg_type_data = 1; +// private static byte _msg_type_hb = 0; +// private bool _is_disposed = false; +// SyncQueue _data_send_queue = new SyncQueue(); - public class QueuedMessage { - public string id; - public SendConfirmationDelegate del; - public byte[] data; +// public class QueuedMessage { +// public string id; +// public SendConfirmationDelegate del; +// public byte[] data; - public QueuedMessage(string id, SendConfirmationDelegate del, byte[] data) { - id = id; - del = del; - data = data; - } +// public QueuedMessage(string id, SendConfirmationDelegate del, byte[] data) { +// id = id; +// del = del; +// data = data; +// } - public QueuedMessage(byte[] data) - : this(String.Empty, null, data) { } +// public QueuedMessage(byte[] data) +// : this(String.Empty, null, data) { } - } +// } - public enum ConnectionSide { - Client, - Server - } +// public enum ConnectionSide { +// Client, +// Server +// } - public AsyncTCPConnection2(Socket socket, ConnectionSide side) { - _socket = socket; - _nw_stream = new NetworkStream(socket); - _side = side; - IPEndPoint r_ep = socket.RemoteEndPoint as IPEndPoint; - _peer_address = new RemoteConnectionInfo(r_ep.Address.ToString(), r_ep.Port); +// public AsyncTCPConnection2(Socket socket, ConnectionSide side) { +// _socket = socket; +// _nw_stream = new NetworkStream(socket); +// _side = side; +// IPEndPoint r_ep = socket.RemoteEndPoint as IPEndPoint; +// _peer_address = new RemoteConnectionInfo(r_ep.Address.ToString(), r_ep.Port); - var loc_ep = socket.LocalEndPoint as IPEndPoint; - _self_address = new RemoteConnectionInfo(loc_ep.Address.ToString(), loc_ep.Port); - } +// var loc_ep = socket.LocalEndPoint as IPEndPoint; +// _self_address = new RemoteConnectionInfo(loc_ep.Address.ToString(), loc_ep.Port); +// } - public void register(ITCPMessageHandler message_handler) { - _message_handler = message_handler; - Task.Run(async () => _keep_reading()); - Task.Run(async () => await _keep_sending()); - //_keep_reading(); - // if add a _keep_sending threadis added then we can maek send a non async - // methid making it much easier to integrate with the rest - } +// public void register(ITCPMessageHandler message_handler) { +// _message_handler = message_handler; +// Task.Run(async () => _keep_reading()); +// Task.Run(async () => await _keep_sending()); +// //_keep_reading(); +// // if add a _keep_sending threadis added then we can maek send a non async +// // methid making it much easier to integrate with the rest +// } - // this thread pulls - private async Task _keep_sending() { - bts.Log.Gen.info($"TCPConnection._keep_sending starting"); - while (!_is_disposed) { - try { - QueuedMessage m = _data_send_queue.dequeue(100); - if (m == null) { - continue; - } - await send_async(m.data); - if (String.IsNullOrEmpty(m.id)) { - m.del(m.id, true); - } - } catch (Exception ex) { - bts.Log.Gen.error($"TCPConnection._keep_sending ex: {ex.Message}"); - await Task.Delay(100); - _handle_error(ex); - } - } - } +// // this thread pulls +// private async Task _keep_sending() { +// bts.Log.Gen.info($"TCPConnection._keep_sending starting"); +// while (!_is_disposed) { +// try { +// QueuedMessage m = _data_send_queue.dequeue(100); +// if (m == null) { +// continue; +// } +// await send_async(m.data); +// if (String.IsNullOrEmpty(m.id)) { +// m.del(m.id, true); +// } +// } catch (Exception ex) { +// bts.Log.Gen.error($"TCPConnection._keep_sending ex: {ex.Message}"); +// await Task.Delay(100); +// _handle_error(ex); +// } +// } +// } - private async Task _keep_reading() { - bts.Log.Gen.info($"TCPConnection._keep_reading starting"); - while (!_is_disposed) { - try { - byte[] msg = await TCPSocketUtils.read_bytes_async(_nw_stream); - bts.Log.Gen.info($"AsyncTCPConnection2._keep_reading side: {_side} self: {get_self_address()} peer: {get_peer_address()} msg len: {msg.Length}"); - await _handle_msg(msg); - } catch (Exception ex) { - bts.Log.Gen.error($"TCPConnection._keep_reading ex: {ex.Message}"); - await Task.Delay(100); - _handle_error(ex); - } - } - } +// private async Task _keep_reading() { +// bts.Log.Gen.info($"TCPConnection._keep_reading starting"); +// while (!_is_disposed) { +// try { +// byte[] msg = await TCPSocketUtils.read_bytes_async(_nw_stream); +// bts.Log.Gen.info($"AsyncTCPConnection2._keep_reading side: {_side} self: {get_self_address()} peer: {get_peer_address()} msg len: {msg.Length}"); +// await _handle_msg(msg); +// } catch (Exception ex) { +// bts.Log.Gen.error($"TCPConnection._keep_reading ex: {ex.Message}"); +// await Task.Delay(100); +// _handle_error(ex); +// } +// } +// } - private async Task _handle_msg(byte[] msg) { - // read the first byte to read the msg type and deal with it accordingly - BinaryReader br = new BinaryReader(new MemoryStream(msg)); - byte msg_type = br.ReadByte(); - if (msg_type == _msg_type_data) { - byte[] data = br.ReadBytes(msg.Length - 1); - RemoteMessage m = new RemoteMessage(data, RemoteMessageType.Data, _peer_address); - _message_handler.onData(m); - } else { - RemoteMessage m = new RemoteMessage(null, RemoteMessageType.Heartbeat, _peer_address); - _message_handler.onData(m); - } - } +// private async Task _handle_msg(byte[] msg) { +// // read the first byte to read the msg type and deal with it accordingly +// BinaryReader br = new BinaryReader(new MemoryStream(msg)); +// byte msg_type = br.ReadByte(); +// if (msg_type == _msg_type_data) { +// byte[] data = br.ReadBytes(msg.Length - 1); +// RemoteMessage m = new RemoteMessage(data, RemoteMessageType.Data, _peer_address); +// _message_handler.onData(m); +// } else { +// RemoteMessage m = new RemoteMessage(null, RemoteMessageType.Heartbeat, _peer_address); +// _message_handler.onData(m); +// } +// } - // not very efficient - private static byte[] _prefix_msg_type(byte[] data) { - MemoryStream ms = new MemoryStream(); - BinaryWriter bw = new BinaryWriter(ms); - bw.Write(_msg_type_data); - bw.Write(data); - ms.Position = 0; - return ms.ToArray(); - } +// // not very efficient +// private static byte[] _prefix_msg_type(byte[] data) { +// MemoryStream ms = new MemoryStream(); +// BinaryWriter bw = new BinaryWriter(ms); +// bw.Write(_msg_type_data); +// bw.Write(data); +// ms.Position = 0; +// return ms.ToArray(); +// } - private async void _handle_error(Exception ex) { - bts.Log.Gen.error($"TCPConnection._handle_error ex: {ex}"); - try { - var socket = _nw_stream.Socket; - socket.Close(); - socket.Dispose(); - } catch (Exception ex2) { - bts.Log.Gen.error($"TCPConnection._handle_error got exception when closing Socket ex: {ex}"); - } - _is_disposed = true; - RemoteMessage rm = new RemoteMessage(new byte[] { }, RemoteMessageType.Disconnection, _peer_address); - _message_handler.onData(rm); - } +// private async void _handle_error(Exception ex) { +// bts.Log.Gen.error($"TCPConnection._handle_error ex: {ex}"); +// try { +// var socket = _nw_stream.Socket; +// socket.Close(); +// socket.Dispose(); +// } catch (Exception ex2) { +// bts.Log.Gen.error($"TCPConnection._handle_error got exception when closing Socket ex: {ex}"); +// } +// _is_disposed = true; +// RemoteMessage rm = new RemoteMessage(new byte[] { }, RemoteMessageType.Disconnection, _peer_address); +// _message_handler.onData(rm); +// } - public void send_with_confirmation(byte[] data, string confId, SendConfirmationDelegate del) { } +// public void send_with_confirmation(byte[] data, string confId, SendConfirmationDelegate del) { } - public async Task send_with_confirmation_async(byte[] data, string conf_id, SendConfirmationDelegate del) { - try { - conf_id = (++_msg_id).ToString(); - await TCPSocketUtils.send_bytes_async(_nw_stream, data); - del(conf_id, true); - } catch (Exception ex) { - _handle_error(ex); - } - } +// public async Task send_with_confirmation_async(byte[] data, string conf_id, SendConfirmationDelegate del) { +// try { +// conf_id = (++_msg_id).ToString(); +// await TCPSocketUtils.send_bytes_async(_nw_stream, data); +// del(conf_id, true); +// } catch (Exception ex) { +// _handle_error(ex); +// } +// } - public void sendWithConfirmation(byte[] data, ref string conf_id, SendConfirmationDelegate del) { - conf_id = (++_msg_id).ToString(); - send(data); - del(conf_id, true); - } +// public void sendWithConfirmation(byte[] data, ref string conf_id, SendConfirmationDelegate del) { +// conf_id = (++_msg_id).ToString(); +// send(data); +// del(conf_id, true); +// } - public void send(byte[] data) { - Task.Run(async () => await send_async(data)); - bts.Log.Gen.info($"AsyncTCPConnection2.send self: {get_self_address()} peer: {get_peer_address()} msg len: {data.Length} sent successfully"); - //_data_send_queue.enqueue(new QueuedMessage(data)); - } +// public void send(byte[] data) { +// Task.Run(async () => await send_async(data)); +// bts.Log.Gen.info($"AsyncTCPConnection2.send self: {get_self_address()} peer: {get_peer_address()} msg len: {data.Length} sent successfully"); +// //_data_send_queue.enqueue(new QueuedMessage(data)); +// } - public async Task send_async(byte[] data) { - // prefix 4 bytes for type (data vs hb) - MemoryStream str = new MemoryStream(); - BinaryWriter bw = new BinaryWriter(str); - bw.Write(_msg_type_data); - bw.Write(data); - try { - await TCPSocketUtils.send_bytes_async(_nw_stream, str.ToArray()); - } catch (Exception ex) { - bts.Log.Gen.error($"AsyncTCPConnection2.send_async ex: {ex}"); - _handle_error(ex); - } - } +// public async Task send_async(byte[] data) { +// // prefix 4 bytes for type (data vs hb) +// MemoryStream str = new MemoryStream(); +// BinaryWriter bw = new BinaryWriter(str); +// bw.Write(_msg_type_data); +// bw.Write(data); +// try { +// await TCPSocketUtils.send_bytes_async(_nw_stream, str.ToArray()); +// } catch (Exception ex) { +// bts.Log.Gen.error($"AsyncTCPConnection2.send_async ex: {ex}"); +// _handle_error(ex); +// } +// } - public void getPeerAddress(out string ip, out int port) { - ip = _peer_address.ip; - port = _peer_address.port; - ///.Net has some problems getting the port, so using - ///native code for that - //sockaddr addr = new sockaddr(); - //int namelen = 16; - //getsockname(mySock.Handle, ref addr, ref namelen); - //port = addr.sin_port; - } +// public void getPeerAddress(out string ip, out int port) { +// ip = _peer_address.ip; +// port = _peer_address.port; +// ///.Net has some problems getting the port, so using +// ///native code for that +// //sockaddr addr = new sockaddr(); +// //int namelen = 16; +// //getsockname(mySock.Handle, ref addr, ref namelen); +// //port = addr.sin_port; +// } - public RemoteConnectionInfo get_peer_address() { - string ip; int port; - getPeerAddress(out ip, out port); - return new RemoteConnectionInfo(ip, port); - } +// public RemoteConnectionInfo get_peer_address() { +// string ip; int port; +// getPeerAddress(out ip, out port); +// return new RemoteConnectionInfo(ip, port); +// } - public RemoteConnectionInfo get_self_address() { - string ip; int port; - getSelfAddress(out ip, out port); - return new RemoteConnectionInfo(ip, port); - } +// public RemoteConnectionInfo get_self_address() { +// string ip; int port; +// getSelfAddress(out ip, out port); +// return new RemoteConnectionInfo(ip, port); +// } - public void getSelfAddress(out string ip, out int port) { - ip = _self_address.ip; - port = _self_address.port; - } +// public void getSelfAddress(out string ip, out int port) { +// ip = _self_address.ip; +// port = _self_address.port; +// } - private async void _send_hb() { - if (_last_hb_sent - DateTime.Now > _hb_period) { - MemoryStream ms = new MemoryStream(); - BinaryWriter bw = new BinaryWriter(ms); - bw.Write(_msg_type_hb); - ms.Position = 0; - byte[] hb_msg = ms.ToArray(); - await TCPSocketUtils.send_bytes_async(_nw_stream, hb_msg); - } - } +// private async void _send_hb() { +// if (_last_hb_sent - DateTime.Now > _hb_period) { +// MemoryStream ms = new MemoryStream(); +// BinaryWriter bw = new BinaryWriter(ms); +// bw.Write(_msg_type_hb); +// ms.Position = 0; +// byte[] hb_msg = ms.ToArray(); +// await TCPSocketUtils.send_bytes_async(_nw_stream, hb_msg); +// } +// } - public void doWork() { - _send_hb(); - } +// public void doWork() { +// _send_hb(); +// } - public void Dispose() { - _nw_stream.Close(); - _nw_stream.Dispose(); - _is_disposed = true; - } +// public void Dispose() { +// _nw_stream.Close(); +// _nw_stream.Dispose(); +// _is_disposed = true; +// } - public bool isDisposed { - get { - return _is_disposed; - } - } +// public bool isDisposed { +// get { +// return _is_disposed; +// } +// } - } -} \ No newline at end of file +// } +// } \ No newline at end of file diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_APM.cs b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_APM.cs index 59e8e6a1a..03e04f2eb 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_APM.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_APM.cs @@ -32,6 +32,8 @@ using BCG; using System.Collections.ObjectModel; using System.Numerics; using System.Reflection.Metadata; +using System.Threading.Tasks; +using System.Linq; namespace bts { public class AsyncTCPConnection_APM : ITCPConnection, IWorker, IDisposable { @@ -40,6 +42,9 @@ namespace bts { // since both TCP sends and receives happen in multiple transfers, this // provides a wrapper around copying the partial transfers into the complete buffer public class AsyncMessageBase { + readonly string msg_id = Guid.NewGuid().ToString(); + // every BeginSend or BeginReceive has a unique key associated with it + public int key; // total msg that needs to be transfered public byte[] buffer; // as data is transferred in chunks, transfer_ptr moves ahead by amount of data transferred. @@ -63,16 +68,18 @@ namespace bts { transfer_ptr += advance_by; _n_transfers++; if (transfer_ptr > original_size) { - bts.Log.Gen.error("transfer went beyond initial size {ToString()}"); + bts.Log.Gen.error($"transfer went beyond initial size {ToString()}"); } // TODO: log if it goes past the buffer } - public bool fully_transfered => transfer_ptr >= original_size; + public bool fully_transfered() { + return transfer_ptr >= original_size; + } public override string ToString() { - return $"{GetType().ToString()} original_length: {original_size} transfer_ptr: {transfer_ptr} n_transfers: {_n_transfers}" + - "fully_transfered: {fully_transfered}"; + return $"{GetType().ToString()} msg_id: {msg_id} key: {key} original_length: {original_size} transfer_ptr: {transfer_ptr} n_transfers: {_n_transfers} " + + $"fully_transfered: {fully_transfered()}"; } } public class AsyncSendMessage : AsyncMessageBase { @@ -114,7 +121,7 @@ namespace bts { public byte[] read_bytes(int start_idx) { byte[] rv = new byte[buffer.Length - start_idx]; - buffer.CopyTo(rv, start_idx); + Array.Copy(buffer, start_idx, rv, 0, rv.Length); return rv; } @@ -174,8 +181,12 @@ namespace bts { private const int DATA_MSG_SIGNAL = 0; private const int HB_MSG_SIGNAL = 1; + private int _send_key = 0, _receive_key = 0; + private HashSet _read_key_map = new HashSet(), + _send_key_map = new HashSet(); private readonly int _max_msg_size = PubSub3Config.instance.PS3_MaxPacketSize; private readonly RemoteConnectionInfo _peer_conn_info, _self_conn_info; + private readonly ITCPConnection.ConnectionSide _connection_side; private readonly Socket _sock; private ITCPMessageHandler _message_handler = null; @@ -187,9 +198,10 @@ namespace bts { private bool _hb_received_yet = false, _data_received_yet = false, _hb_sent_once = false; private DateTime _last_hb_received_time = new DateTime(1900, 1, 1); - public AsyncTCPConnection_APM(Socket sock, TimeSpan hb_period) { + public AsyncTCPConnection_APM(Socket sock, TimeSpan hb_period, ITCPConnection.ConnectionSide connection_side) { _sock = sock; _hb_period = hb_period; + _connection_side = connection_side; _sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontRoute, true); string ip; int port; @@ -201,7 +213,7 @@ namespace bts { } public override string ToString() { - return $"AsyncTCPConnection_APM peer: {_peer_conn_info}, self: {_self_conn_info}"; + return $"AsyncTCPConnection_APM side: {_connection_side} peer: {_peer_conn_info}, self: {_self_conn_info}"; } #region ITCPConnection Members @@ -257,6 +269,8 @@ namespace bts { public void doWork() { if (!_is_alive) return; + return; + // disable hbs for now if (!_hb_sent_once) { bts.Log.Gen.info("Sending heartbeat to peer {_peer_conn_info} for the first time"); _hb_sent_once = true; @@ -265,16 +279,26 @@ namespace bts { _begin_or_resume_sending(new AsyncSendMessage(msg, 0)); } + private static int _tid() { + var tid = System.Threading.Thread.CurrentThread.ManagedThreadId; + return tid; + } + + private static string _cb_txt(IAsyncResult res) { + return $"completed?: {res.IsCompleted} sync?: {res.CompletedSynchronously}"; + } + #endregion #region sending data private void _begin_or_resume_sending(AsyncSendMessage message) { - bts.Log.Gen.info($"AsyncTCPConnection_APM._begin_or_resume_sending this: {ToString()} message: {message} _is_alive: {_is_alive}"); + bts.Log.Gen.info($"AsyncTCPConnection_APM._begin_or_resume_sending this: {ToString()} tid: {_tid()} message: {message} _is_alive: {_is_alive}"); if (_is_alive) { try { SocketError begin_send_err; // since we get message on on_send we dont need to keep the state around + message.key = _send_key++; var res = _sock.BeginSend(message.buffer, message.transfer_ptr, message.remaining_size, SocketFlags.None, out begin_send_err, new AsyncCallback(_on_send), message); if (begin_send_err != SocketError.Success) @@ -282,10 +306,12 @@ namespace bts { else { // successfully sent, all we need to do here is make sure if it was sent asynchronously // if not call _on_send explicitely - if (res != null && res.CompletedSynchronously) { - // for small messages on LANs this can happen, we will on_send to deal with it the same way - // TODO - _on_send(res); + if (res != null && res.IsCompleted && res.CompletedSynchronously) { + // for small messages on LANs this can happen, we will on_send to deal with it the same way + Task.Run(() => { + bts.Log.Gen.info($"AsyncTCPConnection_APM._begin_or_resume_sending calling _on_send explicitely"); + _on_send(res); + }); } } } catch (Exception ex) { @@ -295,19 +321,25 @@ namespace bts { } private void _on_send(IAsyncResult res) { - bts.Log.Gen.info($"AsyncTCPConnection_APM._on_send: this: {ToString()} message: {res.AsyncState} _is_alive: {_is_alive}"); + AsyncSendMessage message = res.AsyncState as AsyncSendMessage; + if (_send_key_map.Contains(message.key)) { + bts.Log.Gen.warn($"AsyncTCPConnection_APM._on_send key: {message.key} already handled"); + return; + } + _send_key_map.Add(message.key); + bts.Log.Gen.info($"AsyncTCPConnection_APM._on_send: pre endSend this: {ToString()} tid: {_tid()} res: {_cb_txt(res)} message: {res.AsyncState} _is_alive: {_is_alive}"); if (_is_alive) { try { SocketError send_err; int bytes_sent = _sock.EndSend(res, out send_err); - AsyncSendMessage message = res.AsyncState as AsyncSendMessage; //message.offset += bytesSent; message.advance_transfer_pointer(bytes_sent); - bts.Log.Gen.info($"AsyncTCPConnection_APM._on_send message: {message} completed_sync?: {res.CompletedSynchronously}"); + bts.Log.Gen.info($"AsyncTCPConnection_APM._on_send: post endSend this: {ToString()} tid: {_tid()} res: {_cb_txt(res)} " + + $"message: {res.AsyncState} bytes_sent: {bytes_sent} _is_alive: {_is_alive}"); if (send_err == SocketError.Success) { // successful send of some bytes //if (message.offset == message.buffer.Length) { - if (message.fully_transfered) { + if (message.fully_transfered()) { // fully sent, if confirmation needs to be sent out if (!String.IsNullOrEmpty(message.message_id)) { message.on_send_del(message.message_id, true); @@ -360,6 +392,10 @@ namespace bts { #region receiving data + private void _read_next_msg() { + _read_size(); + } + private void _read_size() { _begin_or_resume_reading(new AsyncReceiveMessage(4, AsyncReceiveMessage.ReadState.reading_size)); } @@ -370,23 +406,29 @@ namespace bts { } private void _begin_or_resume_reading(AsyncReceiveMessage rcv_msg) { + bts.Log.Gen.info($"AsyncTCPConnection_APM._begin_or_resume_reading: this: {ToString()} tid: {_tid()} message: {rcv_msg} _is_alive: {_is_alive}"); if (!_is_alive) return; try { SocketError read_sock_err; + rcv_msg.key = _receive_key++; var res = _sock.BeginReceive(rcv_msg.buffer, rcv_msg.transfer_ptr, rcv_msg.remaining_size, SocketFlags.None, out read_sock_err, new AsyncCallback(_on_read), rcv_msg); if (read_sock_err != SocketError.Success) { - bts.Log.Gen.info($"_begin_or_resume_reading peer: {_peer_conn_info} error: {read_sock_err} rcv_msg: {rcv_msg}"); + bts.Log.Gen.error($"_begin_or_resume_reading this: {this} error: {read_sock_err} rcv_msg: {rcv_msg}"); _handle_error(new ErrorMessage(read_sock_err, "_beging_or_resume_reading")); } else { // successfully started receiving - if (res != null && res.CompletedSynchronously) { + if (res != null && res.IsCompleted && res.CompletedSynchronously) { // make it follow the same code path - _on_read(res); + Task.Run(() => { + bts.Log.Gen.info($"AsyncTCPConnection_APM._begin_or_resume_reading calling _on_send explicitely"); + _on_read(res); + } + ); } } } catch (Exception ex) { @@ -395,30 +437,49 @@ namespace bts { } private void _on_read(IAsyncResult res) { - bts.Log.Gen.info($"AsyncTCPConnection_APM._on_read: this: {ToString()} message: {res.AsyncState} _is_alive: {_is_alive}"); + AsyncReceiveMessage rcv_message = res.AsyncState as AsyncReceiveMessage; + if (_read_key_map.Contains(rcv_message.key)) { + bts.Log.Gen.warn($"AsyncTCPConnection_APM._on_read key: {rcv_message.key} already handled"); + return; + } + _read_key_map.Add(rcv_message.key); if (!_is_alive) return; try { SocketError read_err; - AsyncReceiveMessage rcv_message = res.AsyncState as AsyncReceiveMessage; int bytes_read = _sock.EndReceive(res, out read_err); rcv_message.advance_transfer_pointer(bytes_read); + bts.Log.Gen.info($"AsyncTCPConnection_APM._on_read: this: {ToString()} tid: {_tid()} res: {_cb_txt(res)} bytes_read: {bytes_read} message: {res.AsyncState} _is_alive: {_is_alive} read_err: {read_err}"); + if (bytes_read == 0) { + bts.Log.Gen.error("AsyncTCPConnection_APM._on_read this: {this} read 0 bytes, throwing exception"); + // TODO: call _handle_error + // means other side shutdown the conn, call _handle_error + } + //return; if (read_err == SocketError.Success) { - if (rcv_message.fully_transfered) { + if (rcv_message.fully_transfered()) { if (rcv_message.is_reading_size()) { - _on_read_size_completely(rcv_message); + var msg_size = _on_read_size_completely(rcv_message); + if (msg_size != null && msg_size.HasValue) { + _read_data(msg_size.Value); + } return; } else { // data is read int msg_type = rcv_message.read_int32(); + bts.Log.assert(msg_type == HB_MSG_SIGNAL || msg_type == DATA_MSG_SIGNAL); if (msg_type == DATA_MSG_SIGNAL) { _on_read_data_completely(rcv_message); + _read_next_msg(); + return; return; } else if (msg_type == HB_MSG_SIGNAL) { _on_read_hb_completely(rcv_message); + _read_next_msg(); + return; } // go back to reading size for a new message - _read_size(); + //_read_size(); } } else { // msg has not been fully rd, we have already advanced the transfer ptr @@ -434,22 +495,26 @@ namespace bts { #endregion - private void _on_read_size_completely(AsyncReceiveMessage msg) { + private int? _on_read_size_completely(AsyncReceiveMessage msg) { bts.Log.assert(msg.is_reading_size()); - bts.Log.assert(msg.fully_transfered); + bts.Log.assert(msg.fully_transfered()); bts.Log.assert(msg.original_size == 4); var msg_sz = msg.read_int32(); + bts.Log.Gen.info($"AsyncTCPConnection_APM._on_read_size_completely this: {this} msg: {msg} msg_sz: {msg_sz}"); if (msg_sz > _max_msg_size) { string err_msg = $"Encountered malformed message, prefixed_size: {msg_sz}"; _handle_error(new ErrorMessage(new ApplicationException(err_msg), "_on_read")); - } else + return null; + } else { // sz is determined, now we read that many bytes - _read_data(msg_sz); + //_read_data(msg_sz); + return msg_sz; + } } private void _on_read_hb_completely(AsyncReceiveMessage msg) { bts.Log.assert(!msg.is_reading_size()); - bts.Log.assert(msg.fully_transfered); + bts.Log.assert(msg.fully_transfered()); bts.Log.assert(msg.original_size == 4); bts.Log.assert(msg.read_int32(0) == HB_MSG_SIGNAL); if (!_hb_received_yet) { @@ -461,8 +526,10 @@ namespace bts { } private void _on_read_data_completely(AsyncReceiveMessage msg) { bts.Log.assert(!msg.is_reading_size()); - bts.Log.assert(msg.fully_transfered); - bts.Log.assert(msg.read_int32(0) == DATA_MSG_SIGNAL); + bts.Log.assert(msg.fully_transfered()); + var type = msg.read_int32(0); + bts.Log.assert(type == DATA_MSG_SIGNAL); + bts.Log.Gen.info($"AsyncTCPConnection_APM._on_read_data_completely this: {this} msg: {msg} type: {type}"); byte[] data = msg.read_bytes(4); ///callbacks can be made through thread pool to avoid this ///thread from being blocked, by this callback @@ -482,9 +549,9 @@ namespace bts { if (_is_alive) { _master_worker.removeWorker(this); _is_alive = false; - bts.Log.Gen.info($"AsycnTCPConnection with peer: {_peer_conn_info} being disposed, last HB was received at {_last_hb_received_time}"); + bts.Log.Gen.info($"AsycnTCPConnection.Dispose this: {this} being disposed, last HB was received at {_last_hb_received_time}"); try { - _sock.Close(); + _sock.Shutdown(SocketShutdown.Both); } catch (Exception ex) { String.Format("AsyncTCPConnection_APM.Dispose exception: {ex} thrown when closing socket"); if (ex is OutOfMemoryException) @@ -498,7 +565,7 @@ namespace bts { private void _handle_error(ErrorMessage err_msg) { lock (this) { - Log.Gen.info("AsyncTCPConnection_APM._handle_error peer_conn_info: {_peer_conn_info} error_msg: {err_msg}"); + Log.Gen.info($"AsyncTCPConnection_APM._handle_error this: {this} error_msg: {err_msg}"); if (err_msg.oom) throw err_msg.exception; Dispose(); diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs b/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs index a5f1d5635..2b61b354d 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs @@ -9,6 +9,10 @@ namespace BCG { /// on top of the sockets (used on both server and client) /// public interface ITCPConnection : IDisposable { + public enum ConnectionSide { + Client, + Server + } /// /// The delegate is fired signalling if the data send was /// successful or not diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/ServerToClientManagedTCPConnectionAcceptor.cs b/src/DataStreamSuite/PubSub/ManagedTCP/ServerToClientManagedTCPConnectionAcceptor.cs index 155637930..7d01bf2c4 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/ServerToClientManagedTCPConnectionAcceptor.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/ServerToClientManagedTCPConnectionAcceptor.cs @@ -22,20 +22,20 @@ namespace BCG { return portNo; } - public static int activate(ITCPConnectionHandler handler, int port, TimeSpan clientHBTimeSpan) { - lock (mySyncObject) { - if (myPortToSingleServerAcceptorMap.ContainsKey(port)) { - string msg = string.Format("Error: Application is already accepting clients on port {0}", port); - // BlueEventLog.logEvent(msg, BlueEventLog2Level.Error); - return port; - } else { - SingleServerToClientManagedTCPConnectionAcceptor theAcceptor = new SingleServerToClientManagedTCPConnectionAcceptor(); - int assignedport = theAcceptor.activate(handler, port, clientHBTimeSpan); - myPortToSingleServerAcceptorMap[assignedport] = theAcceptor; - return assignedport; - } - } //end lock - } //end activate code + // public static int activate(ITCPConnectionHandler handler, int port, TimeSpan clientHBTimeSpan) { + // lock (mySyncObject) { + // if (myPortToSingleServerAcceptorMap.ContainsKey(port)) { + // string msg = string.Format("Error: Application is already accepting clients on port {0}", port); + // // BlueEventLog.logEvent(msg, BlueEventLog2Level.Error); + // return port; + // } else { + // SingleServerToClientManagedTCPConnectionAcceptor theAcceptor = new SingleServerToClientManagedTCPConnectionAcceptor(); + // int assignedport = theAcceptor.activate(handler, port, clientHBTimeSpan); + // myPortToSingleServerAcceptorMap[assignedport] = theAcceptor; + // return assignedport; + // } + // } //end lock + // } //end activate code public static int accept_connections(ITCPConnectionHandler handler, int port, TimeSpan clientHBTimeSpan) { lock (mySyncObject) { diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/TCPSocketUtils.cs b/src/DataStreamSuite/PubSub/ManagedTCP/TCPSocketUtils.cs index a60d9fd15..ab1673b59 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/TCPSocketUtils.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/TCPSocketUtils.cs @@ -13,6 +13,7 @@ using BCG.Utilities.General; using System.Net.WebSockets; using bts; using System.Threading; +using Google.Protobuf.WellKnownTypes; namespace BCG { // utility functions for TCP socket async communications. Does the following @@ -35,7 +36,7 @@ namespace BCG { try { // keeps on accepting connections client_socket = await listener.AcceptAsync(); - AsyncTCPConnection2 new_conn = new(client_socket, AsyncTCPConnection2.ConnectionSide.Server); + ITCPConnection new_conn = new bts.AsyncTCPConnection_APM(client_socket, TimeSpan.FromSeconds(1), ITCPConnection.ConnectionSide.Server); handler.onConnection(new_conn); } catch (Exception ex) { bts.Log.Gen.error($"TCPConnection.accept ex: {ex} trying again"); @@ -57,7 +58,7 @@ namespace BCG { client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); await client_socket.ConnectAsync(server_ip_address, server_port); bts.Log.Gen.info($"AsyncTCPConnection2.connect_to_server conn: {log_conn} successfully connected after {i} attempts"); - ITCPConnection new_conn = new AsyncTCPConnection2(client_socket, AsyncTCPConnection2.ConnectionSide.Client); + ITCPConnection new_conn = new bts.AsyncTCPConnection_APM(client_socket, TimeSpan.FromSeconds(1), ITCPConnection.ConnectionSide.Client); conn_handler.onConnection(new_conn); break; } catch (Exception ex) { diff --git a/src/DataStreamSuite/PubSub/Testing/SimpleTCPClient.cs b/src/DataStreamSuite/PubSub/Testing/SimpleTCPClient.cs index 775a40b70..a466dd13f 100644 --- a/src/DataStreamSuite/PubSub/Testing/SimpleTCPClient.cs +++ b/src/DataStreamSuite/PubSub/Testing/SimpleTCPClient.cs @@ -12,12 +12,14 @@ using BCG; namespace BCG { - // This uses AsyncTCPConnection2's stateful async functions public class SimpleTCPClientAsync : ITCPConnectionHandler, ITCPMessageHandler { - AsyncTCPConnection2 _conn = null; + //AsyncTCPConnection2 _conn = null; int _m_msgs_received = 0; - UInt32 msg_sz = 1024 * 1024 * 1024; - int wait_time_ms = 10000; + UInt32 msg_sz = 1024 * 1024;// * 1024 * 1024; + readonly int max_n_msgs = Int32.MaxValue; + int n_msgs_sent = 0; + + int wait_time_ms = 1000; public static async Task start(string ip, int port) { SimpleTCPClientAsync c = new SimpleTCPClientAsync(ip, port); c.connect(); @@ -38,11 +40,15 @@ namespace BCG { for (int i = 0; i < buff.Length; i++) { buff[i] = (byte)i; } - _conn = connection as AsyncTCPConnection2; - while (!_conn.isDisposed) { - Console.WriteLine($"SimpleTCPClientAsync sending data len: {buff.Length}"); - await _conn.send_async(buff); + //_conn = connection as AsyncTCPConnection2; + while (!connection.isDisposed) { await Task.Delay(wait_time_ms); + if (n_msgs_sent < max_n_msgs) { + Console.WriteLine($"Sending msg_no: {n_msgs_sent}"); + // Console.ReadLine(); + connection.send(buff); + n_msgs_sent++; + } } }); } diff --git a/src/DataStreamSuite/PubSub/Testing/SimpleTCPServer.cs b/src/DataStreamSuite/PubSub/Testing/SimpleTCPServer.cs index e806364cc..c5add2c20 100644 --- a/src/DataStreamSuite/PubSub/Testing/SimpleTCPServer.cs +++ b/src/DataStreamSuite/PubSub/Testing/SimpleTCPServer.cs @@ -53,7 +53,7 @@ namespace BCG { return; } _n_msgs_received++; - Console.WriteLine($"SimpleTCPServerAsync.onData msgs_received: {_n_msgs_received} msg: {msg} ci: {rci} echoing it back"); + Console.WriteLine($"\n\nSimpleTCPServerAsync.onData msgs_received: {_n_msgs_received} msg: {msg} ci: {rci} NOW echoing it back\n\n"); if (msg.messageType == RemoteMessageType.Data) { this_conn.send(msg.message); } diff --git a/src/DataStreamSuite/PubSub/Testing/SocketEventArgExample.cs b/src/DataStreamSuite/PubSub/Testing/SocketEventArgExample.cs index e69de29bb..fa836a987 100644 --- a/src/DataStreamSuite/PubSub/Testing/SocketEventArgExample.cs +++ b/src/DataStreamSuite/PubSub/Testing/SocketEventArgExample.cs @@ -0,0 +1,235 @@ +// // Implements the connection logic for the socket server. +// // After accepting a connection, all data read from the client +// // is sent back to the client. The read and echo back to the client pattern +// // is continued until the client disconnects. +// class Server +// { +// private int m_numConnections; // the maximum number of connections the sample is designed to handle simultaneously +// private int m_receiveBufferSize;// buffer size to use for each socket I/O operation +// BufferManager m_bufferManager; // represents a large reusable set of buffers for all socket operations +// const int opsToPreAlloc = 2; // read, write (don't alloc buffer space for accepts) +// Socket listenSocket; // the socket used to listen for incoming connection requests +// // pool of reusable SocketAsyncEventArgs objects for write, read and accept socket operations +// SocketAsyncEventArgsPool m_readWritePool; +// int m_totalBytesRead; // counter of the total # bytes received by the server +// int m_numConnectedSockets; // the total number of clients connected to the server +// Semaphore m_maxNumberAcceptedClients; + +// // Create an uninitialized server instance. +// // To start the server listening for connection requests +// // call the Init method followed by Start method +// // +// // the maximum number of connections the sample is designed to handle simultaneously +// // buffer size to use for each socket I/O operation +// public Server(int numConnections, int receiveBufferSize) +// { +// m_totalBytesRead = 0; +// m_numConnectedSockets = 0; +// m_numConnections = numConnections; +// m_receiveBufferSize = receiveBufferSize; +// // allocate buffers such that the maximum number of sockets can have one outstanding read and +// //write posted to the socket simultaneously +// m_bufferManager = new BufferManager(receiveBufferSize * numConnections * opsToPreAlloc, +// receiveBufferSize); + +// m_readWritePool = new SocketAsyncEventArgsPool(numConnections); +// m_maxNumberAcceptedClients = new Semaphore(numConnections, numConnections); +// } + +// // Initializes the server by preallocating reusable buffers and +// // context objects. These objects do not need to be preallocated +// // or reused, but it is done this way to illustrate how the API can +// // easily be used to create reusable objects to increase server performance. +// // +// public void Init() +// { +// // Allocates one large byte buffer which all I/O operations use a piece of. This gaurds +// // against memory fragmentation +// m_bufferManager.InitBuffer(); + +// // preallocate pool of SocketAsyncEventArgs objects +// SocketAsyncEventArgs readWriteEventArg; + +// for (int i = 0; i < m_numConnections; i++) +// { +// //Pre-allocate a set of reusable SocketAsyncEventArgs +// readWriteEventArg = new SocketAsyncEventArgs(); +// readWriteEventArg.Completed += new EventHandler(IO_Completed); + +// // assign a byte buffer from the buffer pool to the SocketAsyncEventArg object +// m_bufferManager.SetBuffer(readWriteEventArg); + +// // add SocketAsyncEventArg to the pool +// m_readWritePool.Push(readWriteEventArg); +// } +// } + +// // Starts the server such that it is listening for +// // incoming connection requests. +// // +// // The endpoint which the server will listening +// // for connection requests on +// public void Start(IPEndPoint localEndPoint) +// { +// // create the socket which listens for incoming connections +// listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); +// listenSocket.Bind(localEndPoint); +// // start the server with a listen backlog of 100 connections +// listenSocket.Listen(100); + +// // post accepts on the listening socket +// SocketAsyncEventArgs acceptEventArg = new SocketAsyncEventArgs(); +// acceptEventArg.Completed += new EventHandler(AcceptEventArg_Completed); +// StartAccept(acceptEventArg); + +// //Console.WriteLine("{0} connected sockets with one outstanding receive posted to each....press any key", m_outstandingReadCount); +// Console.WriteLine("Press any key to terminate the server process...."); +// Console.ReadKey(); +// } + +// // Begins an operation to accept a connection request from the client +// // +// // The context object to use when issuing +// // the accept operation on the server's listening socket +// public void StartAccept(SocketAsyncEventArgs acceptEventArg) +// { +// // loop while the method completes synchronously +// bool willRaiseEvent = false; +// while (!willRaiseEvent) +// { +// m_maxNumberAcceptedClients.WaitOne(); + +// // socket must be cleared since the context object is being reused +// acceptEventArg.AcceptSocket = null; +// willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg); +// if (!willRaiseEvent) +// { +// ProcessAccept(acceptEventArg); +// } +// } +// } + +// // This method is the callback method associated with Socket.AcceptAsync +// // operations and is invoked when an accept operation is complete +// // +// void AcceptEventArg_Completed(object sender, SocketAsyncEventArgs e) +// { +// ProcessAccept(e); + +// // Accept the next connection request +// StartAccept(e); +// } + +// private void ProcessAccept(SocketAsyncEventArgs e) +// { +// Interlocked.Increment(ref m_numConnectedSockets); +// Console.WriteLine("Client connection accepted. There are {0} clients connected to the server", +// m_numConnectedSockets); + +// // Get the socket for the accepted client connection and put it into the +// //ReadEventArg object user token +// SocketAsyncEventArgs readEventArgs = m_readWritePool.Pop(); +// readEventArgs.UserToken = e.AcceptSocket; + +// // As soon as the client is connected, post a receive to the connection +// bool willRaiseEvent = e.AcceptSocket.ReceiveAsync(readEventArgs); +// if (!willRaiseEvent) +// { +// ProcessReceive(readEventArgs); +// } +// } + +// // This method is called whenever a receive or send operation is completed on a socket +// // +// // SocketAsyncEventArg associated with the completed receive operation +// void IO_Completed(object sender, SocketAsyncEventArgs e) +// { +// // determine which type of operation just completed and call the associated handler +// switch (e.LastOperation) +// { +// case SocketAsyncOperation.Receive: +// ProcessReceive(e); +// break; +// case SocketAsyncOperation.Send: +// ProcessSend(e); +// break; +// default: +// throw new ArgumentException("The last operation completed on the socket was not a receive or send"); +// } +// } + +// // This method is invoked when an asynchronous receive operation completes. +// // If the remote host closed the connection, then the socket is closed. +// // If data was received then the data is echoed back to the client. +// // +// private void ProcessReceive(SocketAsyncEventArgs e) +// { +// // check if the remote host closed the connection +// if (e.BytesTransferred > 0 && e.SocketError == SocketError.Success) +// { +// //increment the count of the total bytes receive by the server +// Interlocked.Add(ref m_totalBytesRead, e.BytesTransferred); +// Console.WriteLine("The server has read a total of {0} bytes", m_totalBytesRead); + +// //echo the data received back to the client +// e.SetBuffer(e.Offset, e.BytesTransferred); +// Socket socket = (Socket)e.UserToken; +// bool willRaiseEvent = socket.SendAsync(e); +// if (!willRaiseEvent) +// { +// ProcessSend(e); +// } +// } +// else +// { +// CloseClientSocket(e); +// } +// } + +// // This method is invoked when an asynchronous send operation completes. +// // The method issues another receive on the socket to read any additional +// // data sent from the client +// // +// // +// private void ProcessSend(SocketAsyncEventArgs e) +// { +// if (e.SocketError == SocketError.Success) +// { +// // done echoing data back to the client +// Socket socket = (Socket)e.UserToken; +// // read the next block of data send from the client +// bool willRaiseEvent = socket.ReceiveAsync(e); +// if (!willRaiseEvent) +// { +// ProcessReceive(e); +// } +// } +// else +// { +// CloseClientSocket(e); +// } +// } + +// private void CloseClientSocket(SocketAsyncEventArgs e) +// { +// Socket socket = (Socket)e.UserToken; + +// // close the socket associated with the client +// try +// { +// socket.Shutdown(SocketShutdown.Send); +// } +// // throws if client process has already closed +// catch (Exception) { } +// socket.Close(); + +// // decrement the counter keeping track of the total number of clients connected to the server +// Interlocked.Decrement(ref m_numConnectedSockets); + +// // Free the SocketAsyncEventArg so they can be reused by another client +// m_readWritePool.Push(e); + +// m_maxNumberAcceptedClients.Release(); +// Console.WriteLine("A client has been disconnected from the server. There are {0} clients connected to the server", m_numConnectedSockets); +// } +// } \ No newline at end of file diff --git a/src/DataStreamSuite/PubSubServer/Program.cs b/src/DataStreamSuite/PubSubServer/Program.cs index 4aace9314..9d6f7e413 100644 --- a/src/DataStreamSuite/PubSubServer/Program.cs +++ b/src/DataStreamSuite/PubSubServer/Program.cs @@ -15,7 +15,7 @@ namespace BCG { /// [STAThread] public static async Task Main(string[] args) { - bool run_echo_tcp_server_only = false; + bool run_echo_tcp_server_only = true; bts.utils.BTSNativeMethods.provide_command_line(new string[] { }, 0); mbts.config.Configuration.initialize(); if (run_echo_tcp_server_only) {