/// <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); }
/// <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); }
/// <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); }
/// <summary> /// 开始发送数据包方法 /// </summary> /// <param name="connection"></param> /// <param name="packet"></param> public void OnStartSending(SocketBase.IConnection connection, SocketBase.Packet packet) { }
/// <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 { } }
/// <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); } }
/// <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) { }