/// <summary> /// Posts a send operation with a SockDataToken which contains the data to be sent. /// </summary> private void DoSend(SockDataToken dataToken) { // Prepare the SocketAsyncEventArgs for send operation SocketAsyncEventArgs sendEventArg; if (!poolOfRecvSendEvents.TryDequeue(out sendEventArg)) { sendEventArg = new SocketAsyncEventArgs(); sendEventArg.Completed += IoCompleted; } sendEventArg.UserToken = dataToken; sendEventArg.AcceptSocket = dataToken.ClientSocket.innerSocket; DoSend(sendEventArg); }
/// <summary> /// Sends data to this socket with a ByteBuf object that contains data to be sent. /// </summary> /// <param name="data">A ByteBuf object that contains data to be sent</param> public void Send(ByteBuf data) { EnsureAccessible(); if (!isConnected) { throw new InvalidOperationException("The operation is not allowed on non-connected sockets."); } if (!data.IsReadable()) { throw new ArgumentException("The parameter {0} must contain one or more elements.", "data"); } var dataToken = new SockDataToken(this, data); if (parent != null) { parent.DoSend(dataToken); } else { DoSend(dataToken); } var status = sendStatusQueue.Take(); if (status == (int)SocketError.Success) { return; } // throw a SocketException if theres is an error. dataToken.Reset(); Dispose(true); var socketException = new SocketException(status); throw socketException; }
/// <summary> /// Posts a send operation with a SockDataToken which contains the data to be sent. /// </summary> private void DoSend(SockDataToken dataToken) { // Prepare the SocketAsyncEventArgs for send operation SocketAsyncEventArgs sendEventArg; if (!poolOfRecvSendEvents.TryDequeue(out sendEventArg)) { sendEventArg = new SocketAsyncEventArgs(); sendEventArg.Completed += IoCompleted; } sendEventArg.UserToken = dataToken; sendEventArg.AcceptSocket = dataToken.ClientSocket.innerSocket; DoSend(sendEventArg); }
/// <summary> /// Sends data to this socket with a ByteBuf object that contains data to be sent. /// </summary> /// <param name="data">A ByteBuf object that contains data to be sent</param> public void Send(ByteBuf data) { EnsureAccessible(); if (!isConnected) { throw new InvalidOperationException("The operation is not allowed on non-connected sockets."); } if (!data.IsReadable()) { throw new ArgumentException("The parameter {0} must contain one or more elements.", "data"); } var dataToken = new SockDataToken(this, data); if (parent != null) { parent.DoSend(dataToken); } else { DoSend(dataToken); } var status = sendStatusQueue.Take(); if (status == (int) SocketError.Success) return; // throw a SocketException if theres is an error. dataToken.Reset(); Dispose(true); var socketException = new SocketException(status); throw socketException; }