예제 #1
0
        /// <summary>
        /// OnStartSending
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="packet"></param>
        protected override void OnStartSending(SocketBase.IConnection connection, SocketBase.Packet packet)
        {
            base.OnStartSending(connection, packet);

            var request = packet as Request <TMessage>;

            if (request == null)
            {
                return;
            }

            request.SendConnection = connection;
            this._receivingQueue.TryAdd(request);
        }
예제 #2
0
        /// <summary>
        /// send packet
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">packet is null.</exception>
        public bool Send(SocketBase.Packet packet)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            SocketBase.IConnection connection = null;
            if (!this._connectionPool.TryAcquire(out connection))
            {
                return(false);
            }

            connection.BeginSend(packet);
            return(true);
        }
예제 #3
0
        /// <summary>
        /// OnSendCallback
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="packet"></param>
        /// <param name="isSuccess"></param>
        protected override void OnSendCallback(SocketBase.IConnection connection, SocketBase.Packet packet, bool isSuccess)
        {
            base.OnSendCallback(connection, packet, isSuccess);

            var request = packet as Request <TMessage>;

            if (request == null)
            {
                return;
            }

            if (isSuccess)
            {
                request.SentTime = SocketBase.Utils.Date.UtcNow;
                this.OnSent(connection, request);
                return;
            }

            Request <TMessage> removed;

            if (this._receivingQueue.TryRemove(connection.ConnectionID, request.SeqID, out removed))
            {
                removed.SendConnection = null;
            }

            if (!request.AllowRetry)
            {
                this.OnSendFailed(request);
                return;
            }

            if (SocketBase.Utils.Date.UtcNow.Subtract(request.CreatedTime).TotalMilliseconds > this._millisecondsSendTimeout)
            {
                //send time out
                this.OnPendingSendTimeout(request);
                return;
            }

            //retry send
            this.Send(request);
        }
 /// <summary>
 /// send callback
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="packet"></param>
 /// <param name="isSuccess"></param>
 protected override void OnSendCallback(SocketBase.IConnection connection, SocketBase.Packet packet, bool isSuccess)
 {
     base.OnSendCallback(connection, packet, isSuccess);
     this._socketService.OnSendCallback(connection, packet, isSuccess);
 }
예제 #5
0
 /// <summary>
 /// 开始发送数据包方法
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="packet"></param>
 public void OnStartSending(SocketBase.IConnection connection, SocketBase.Packet packet)
 {
 }
예제 #6
0
 /// <summary>
 /// start sending
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="packet"></param>
 protected override void OnStartSending(SocketBase.IConnection connection, SocketBase.Packet packet)
 {
     base.OnStartSending(connection, packet);
     try { this._socketService.OnStartSending(connection, packet); }
     catch { }
 }
예제 #7
0
 /// <summary>
 /// start sending
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="packet"></param>
 protected override void OnStartSending(SocketBase.IConnection connection, SocketBase.Packet packet)
 {
     base.OnStartSending(connection, packet);
     try { this._socketService.OnStartSending(connection, packet); }
     catch (Exception ex) { SocketBase.Log.Trace.Error(ex.Message, ex); }
 }
예제 #8
0
 /// <summary>
 /// 发送回调
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="packet"></param>
 /// <param name="isSuccess"></param>
 public virtual void OnSendCallback(SocketBase.IConnection connection, SocketBase.Packet packet, bool isSuccess)
 {
 }