private void SendTask()
 {
     while (socket != null && socket.Connected)
     {
         BinaryObj binObj = null;
         try
         {
             if (sendQueue.TryDequeue(out binObj))
             {
                 socket.Send(binObj.bytes, 0, binObj.length, SocketFlags.None);
             }
         }
         catch (OperationCanceledException) { }
         catch (Exception e)
         {
             LogError?.Invoke(e.ToString());
         }
         finally
         {
             if (binObj != null)
             {
                 binObj.ResetOjb();
                 BinaryObjPool.Checkin(binObj);
             }
         }
     }
     LogInfo?.Invoke("SimpleTcpClient SendTask shutdown");
 }
Beispiel #2
0
 private void SendTask()
 {
     while (client != null && client.Connected)
     {
         BinaryObj binObj = null;
         try
         {
             if (sendQueue.TryDequeue(out binObj))
             {
                 stream.Write(binObj.bytes, 0, binObj.length);
                 rps++;
                 //stream.Flush();
             }
         }
         catch (OperationCanceledException) { }
         catch (Exception e)
         {
             LogError?.Invoke(e.ToString());
         }
         finally
         {
             if (binObj != null)
             {
                 binObj.ResetOjb();
                 BinaryObjPool.Checkin(binObj);
             }
         }
     }
     LogInfo?.Invoke("SimpleTcpClient SendTask shutdown");
 }
Beispiel #3
0
        public BinaryObj ToBytes()
        {
            BinaryObj buffer = BinaryObjPool.Checkout(BinaryObj.PresetType.RequestToMatching);

            buffer.bw.Write((short)0);
            buffer.bw.Write((byte)this.type);
            buffer.bw.Write(this.dt.ToBinary());
            buffer.bw.Write((byte)this.order.et);
            buffer.bw.Write((byte)this.order.t);
            //if (this.order.s.Length > OrderSymbolMaxSize) throw new Exception(string.Format("Symbol exceed max length:{0}", OrderSymbolMaxSize));
            //buffer.bw.Write(this.order.s);
            string price = this.order.p.ToString();

            //if (price.Length > OrderPriceMaxSize) throw new Exception(string.Format("Price exceed max length:{0}", OrderPriceMaxSize));
            buffer.bw.Write(price);
            buffer.bw.Write(this.order.v);
            if (this.order.u.Length > OrderReqIdMaxSize)
            {
                throw new Exception(string.Format("User ID exceed max length:{0}", OrderReqIdMaxSize));
            }
            buffer.bw.Write(this.order.u);
            if (this.order.id.Length > OrderIdMaxSize)
            {
                throw new Exception(string.Format("Order ID exceed max length:{0}", OrderIdMaxSize));
            }
            buffer.bw.Write(this.order.id);
            buffer.bw.Write(this.order.fv);
            buffer.lenBw.Write((short)buffer.ms.Position);
            buffer.length = (int)buffer.ms.Position;
            Array.Copy(buffer.lenInBytes, 0, buffer.bytes, 0, 2);
            return(buffer);
        }
 public static void Checkin(BinaryObj binObj)
 {
     binObj.ResetOjb();
     if (binObj.type == BinaryObj.PresetType.RequestToMatching)
     {
         PoolForReq.Pool.Checkin(binObj);
     }
     else if (binObj.type == BinaryObj.PresetType.ProcessOrderResult)
     {
         PoolForResp.Pool.Checkin(binObj);
     }
     else if (binObj.type == BinaryObj.PresetType.Transaction)
     {
         PoolForTx.Pool.Checkin(binObj);
     }
 }
        /// <summary>
        /// Thread safe
        /// </summary>
        /// <returns></returns>
        public static BinaryObj ConstructRejectBuffer()
        {
            BinaryObj buffer = BinaryObjPool.Checkout(BinaryObj.PresetType.ProcessOrderResult);

            try
            {
                buffer.bw.Write(false);
                buffer.bw.Write(DateTime.Now.ToBinary());
                buffer.bw.Write((byte)ErrorType.SystemBusy);
                buffer.bw.Write((long)0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(buffer);
        }