本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.StartOperationSendPackets方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.StartOperationSendPackets方法的具体用法?C# SocketAsyncEventArgs.StartOperationSendPackets怎么用?C# SocketAsyncEventArgs.StartOperationSendPackets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.StartOperationSendPackets方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
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;
}
示例2: SendPacketsAsync
/// <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;
}
示例3: SendPacketsAsync
//
// 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;
}
示例4: SendPacketsAsync
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;
}