protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation) { var args = new MySocketAsyncEventArgs(); args.SetBuffer(bytes, offset, length); args.UserToken = asyncContinuation; args.Completed += SocketOperationCompleted; lock (this) { if (MaxQueueSize != 0 && _pendingRequests.Count >= MaxQueueSize) { var dequeued = _pendingRequests.Dequeue(); if (dequeued != null) { dequeued.Dispose(); } } _pendingRequests.Enqueue(args); } ProcessNextQueuedItem(); }
protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation) { var args = new MySocketAsyncEventArgs(); args.SetBuffer(bytes, offset, length); args.UserToken = asyncContinuation; args.Completed += SocketOperationCompleted; lock (this) { pendingRequests.Enqueue(args); } ProcessNextQueuedItem(); }
protected override void BeginRequest(NetworkRequestArgs eventArgs) { var args = new MySocketAsyncEventArgs(); args.SetBuffer(eventArgs.RequestBuffer, eventArgs.RequestBufferOffset, eventArgs.RequestBufferLength); args.UserToken = eventArgs.AsyncContinuation; args.Completed += _socketOperationCompleted; bool asyncOperation = false; try { asyncOperation = _socket.SendAsync(args); } catch (SocketException ex) { InternalLogger.Error(ex, "NetworkTarget: Error sending tcp request"); args.SocketError = ex.SocketErrorCode; } catch (Exception ex) { InternalLogger.Error(ex, "NetworkTarget: Error sending tcp request"); if (ex.InnerException is SocketException socketException) { args.SocketError = socketException.SocketErrorCode; } else { args.SocketError = SocketError.OperationAborted; } } if (!asyncOperation) { SocketOperationCompleted(_socket, args); } }
protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation) { var args = new MySocketAsyncEventArgs(); args.SetBuffer(bytes, offset, length); args.UserToken = asyncContinuation; args.Completed += this.SocketOperationCompleted; lock (this) { if (this.MaxQueueSize != 0 && this.pendingRequests.Count >= this.MaxQueueSize) { var dequeued = this.pendingRequests.Dequeue(); if (dequeued != null) { dequeued.Dispose(); } } this.pendingRequests.Enqueue(args); } this.ProcessNextQueuedItem(); }
protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation) { var args = new MySocketAsyncEventArgs(); args.SetBuffer(bytes, offset, length); args.UserToken = asyncContinuation; args.Completed += this.SocketOperationCompleted; lock (this) { this.pendingRequests.Enqueue(args); } this.ProcessNextQueuedItem(); }