|
@@ -122,6 +122,18 @@ namespace Communication
|
|
|
/// nanomsg 通信句柄
|
|
|
/// </summary>
|
|
|
protected BusSocket m_socket;
|
|
|
+ protected object m_sock_lock = new object();
|
|
|
+ BusSocket Net
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ lock(m_sock_lock)
|
|
|
+ {
|
|
|
+ return m_socket;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// nnxx生成id队列
|
|
|
/// </summary>
|
|
@@ -331,9 +343,9 @@ namespace Communication
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (!comm.mb_initialized || comm.m_socket == null)
|
|
|
+ if (!comm.mb_initialized || comm.Net == null)
|
|
|
continue;
|
|
|
- byte[] data = comm.m_socket.ReceiveImmediate();
|
|
|
+ byte[] data = comm.Net.ReceiveImmediate();
|
|
|
if (data != null && data.Length > 0 && comm.m_receive_queue != null)
|
|
|
{
|
|
|
// 解析头
|
|
@@ -366,16 +378,15 @@ namespace Communication
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (!comm.mb_initialized || comm.m_socket == null)
|
|
|
+ if (!comm.mb_initialized || comm.Net == null)
|
|
|
continue;
|
|
|
- lock (comm.m_send_lock)
|
|
|
+
|
|
|
+ if (comm.m_send_queue.Count > 0)
|
|
|
{
|
|
|
- if(comm.m_send_queue.Count > 0)
|
|
|
- {
|
|
|
- MsgStamped msg_stamped = comm.m_send_queue.Dequeue();
|
|
|
- comm.m_socket.Send(msg_stamped.msg.ToByteArray());
|
|
|
- }
|
|
|
+ MsgStamped msg_stamped = comm.m_send_queue.Dequeue();
|
|
|
+ comm.Net.Send(msg_stamped.msg.ToByteArray());
|
|
|
}
|
|
|
+
|
|
|
//Console.WriteLine("msg sent");
|
|
|
}
|
|
|
catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
|