public override void GetResponseObject() { if (responseObject == null) { this.responseObject = reusableSeaaBuffer.Checkout(); } }
/// <summary> /// /// </summary> /// <param name="socket"></param> /// <param name="serverBufferSize"></param> public TcpNetworkSender( Socket socket, int serverBufferSize) : base(serverBufferSize) { this.socket = socket; this.reusableSeaaBuffer = new SimpleObjectPool <SeaaBuffer>(() => new SeaaBuffer(SeaaBuffer_Completed, this.serverBufferSize)); this.responseObject = null; }
private unsafe void Send(Socket socket, SeaaBuffer sendObject, int offset, int size) { // Reset send buffer sendObject.socketEventAsyncArgs.SetBuffer(offset, size); // Set user context to reusable object handle for disposal when send is done sendObject.socketEventAsyncArgs.UserToken = sendObject; if (!socket.SendAsync(sendObject.socketEventAsyncArgs)) { SeaaBuffer_Completed(null, sendObject.socketEventAsyncArgs); } }
public override bool SendResponse(int offset, int size) { var _r = responseObject; if (_r == null) { return(false); } responseObject = null; try { Send(socket, _r, offset, size); } catch { reusableSeaaBuffer.Return(_r); return(false); } return(true); }
public override void ReturnResponseObject() { reusableSeaaBuffer.Return(responseObject); responseObject = null; }
/// <summary> /// Return to pool /// </summary> /// <param name="obj"></param> public void Return(SeaaBuffer obj) => reusableSeaaBuffer.Return(obj);