public bool SendPacketsAsync(SocketAsyncEventArgs e) { bool retval; if (s_loggingEnabled) { Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", ""); } // Throw if socket disposed if (CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } if (e == null) { throw new ArgumentNullException("e"); } if (e.SendPacketsElements == null) { throw new ArgumentNullException("e.SendPacketsElements"); } if (!Connected) { throw new NotSupportedException(SR.net_notconnected); } // Prepare for the native call. e.StartOperationCommon(this); e.StartOperationSendPackets(); // Make the native call. SocketError socketError; Debug.Assert(e.SendPacketsDescriptorCount != null); if (e.SendPacketsDescriptorCount > 0) { try { socketError = e.DoOperationSendPackets(this, _handle); } catch (Exception) { // Clear in-use flag on event args object. e.Complete(); throw; } // Handle completion when completion port is not posted. if (socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); retval = false; } else { retval = true; } } else { // No buffers or files to send. e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None); retval = false; } if (s_loggingEnabled) { Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", retval); } return retval; }
/// <summary> /// Sends a collection of files or in memory data buffers asynchronously to a connected <see cref="T:System.Net.Sockets.Socket"/> object. /// </summary> /// /// <returns> /// Returns true if the I/O operation is pending. The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will be raised upon completion of the operation. Returns false if the I/O operation completed synchronously. In this case, The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will not be raised and the <paramref name="e"/> object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation. /// </returns> /// <param name="e">The <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param><exception cref="T:System.IO.FileNotFoundException">The file specified in the <see cref="P:System.Net.Sockets.SendPacketsElement.FilePath"/> property was not found. </exception><exception cref="T:System.InvalidOperationException">A socket operation was already in progress using the <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object specified in the <paramref name="e"/> parameter.</exception><exception cref="T:System.NotSupportedException">Windows XP or later is required for this method. This exception also occurs if the <see cref="T:System.Net.Sockets.Socket"/> is not connected to a remote host. </exception><exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.Socket"/> has been closed. </exception><exception cref="T:System.Net.Sockets.SocketException">A connectionless <see cref="T:System.Net.Sockets.Socket"/> is being used and the file being sent exceeds the maximum packet size of the underlying transport.</exception> public bool SendPacketsAsync(SocketAsyncEventArgs e) { if (Socket.s_LoggingEnabled) Logging.Enter(Logging.Sockets, (object) this, "SendPacketsAsync", ""); if (this.CleanedUp) throw new ObjectDisposedException(this.GetType().FullName); if (!this.Connected) throw new NotSupportedException(SR.GetString("net_notconnected")); e.StartOperationCommon(this); e.StartOperationSendPackets(); this.BindToCompletionPort(); bool flag1; if (e.m_SendPacketsDescriptor.Length > 0) { bool flag2; try { flag2 = this.TransmitPackets(this.m_Handle, e.m_PtrSendPacketsDescriptor, e.m_SendPacketsDescriptor.Length, e.m_SendPacketsSendSize, e.m_PtrNativeOverlapped, e.m_SendPacketsFlags); } catch (Exception ex) { e.Complete(); throw; } SocketError socketError = flag2 ? SocketError.Success : (SocketError) Marshal.GetLastWin32Error(); if (socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); flag1 = false; } else flag1 = true; } else { e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None); flag1 = false; } if (Socket.s_LoggingEnabled) Logging.Exit(Logging.Sockets, (object) this, "SendPacketsAsync", (object) (bool) (flag1 ? 1 : 0)); return flag1; }
// // SendPacketsAsync // public bool SendPacketsAsync(SocketAsyncEventArgs e) { bool retval; if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", ""); // Throw if socket disposed if(CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } // Throw if not connected. if(!Connected) { throw new NotSupportedException(SR.GetString(SR.net_notconnected)); } // Prepare for the native call. e.StartOperationCommon(this); e.StartOperationSendPackets(); BindToCompletionPort(); // Make the native call. SocketError socketError; bool result; if (e.m_SendPacketsDescriptor.Length > 0) { try { result = TransmitPackets( m_Handle, e.m_PtrSendPacketsDescriptor, e.m_SendPacketsDescriptor.Length, e.m_SendPacketsSendSize, e.m_PtrNativeOverlapped, e.m_SendPacketsFlags); } catch(Exception) { // clear in-use on event arg object e.Complete(); throw; } if(!result) { socketError = (SocketError)Marshal.GetLastWin32Error(); } else { socketError = SocketError.Success; } // Handle completion when completion port is not posted. if(socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); retval = false; } else { retval = true; } } else { // No buffers or files to send. e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None); retval = false; } if(s_LoggingEnabled) Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", retval); return retval; }
public bool SendPacketsAsync(SocketAsyncEventArgs e) { bool flag; SocketError success; bool flag2; if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", ""); } if (this.CleanedUp) { throw new ObjectDisposedException(base.GetType().FullName); } if (!this.Connected) { throw new NotSupportedException(SR.GetString("net_notconnected")); } e.StartOperationCommon(this); e.StartOperationSendPackets(); this.BindToCompletionPort(); try { flag2 = this.TransmitPackets(this.m_Handle, e.m_PtrSendPacketsDescriptor, e.m_SendPacketsElements.Length, e.m_SendPacketsSendSize, e.m_PtrNativeOverlapped, e.m_SendPacketsFlags); } catch (Exception exception) { e.Complete(); throw exception; } if (!flag2) { success = (SocketError) Marshal.GetLastWin32Error(); } else { success = SocketError.Success; } if ((success != SocketError.Success) && (success != SocketError.IOPending)) { e.FinishOperationSyncFailure(success, 0, SocketFlags.None); flag = false; } else { flag = true; } if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", flag); } return flag; }