本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.DoOperation方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.DoOperation方法的具体用法?C# SocketAsyncEventArgs.DoOperation怎么用?C# SocketAsyncEventArgs.DoOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.DoOperation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectAsync
public bool ConnectAsync (SocketAsyncEventArgs e)
{
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
CheckConnect (e);
// if an address family is specified then they must match
AddressFamily raf = e.RemoteEndPoint.AddressFamily;
if ((raf != AddressFamily.Unspecified) && (raf != AddressFamily))
throw new NotSupportedException ("AddressFamily mismatch between socket and endpoint");
e.DoOperation (SocketAsyncOperation.Connect, this);
// We always return true for now
return true;
}
示例2: ReceiveFromAsync
public bool ReceiveFromAsync (SocketAsyncEventArgs e)
{
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
// We do not support recv into multiple buffers yet
if (e.BufferList != null)
throw new NotSupportedException ("Mono doesn't support using BufferList at this point.");
if (e.RemoteEndPoint == null)
throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
e.DoOperation (SocketAsyncOperation.ReceiveFrom, this);
// We always return true for now
return true;
}
示例3: SendToAsync
public bool SendToAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (e.RemoteEndPoint == null)
throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
e.DoOperation (SocketAsyncOperation.SendTo, this);
// We always return true for now
return true;
}
示例4: ConnectAsync
public bool ConnectAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (islistening)
throw new InvalidOperationException ("You may not perform this operation after calling the Listen method.");
if (e.RemoteEndPoint == null)
throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
if (e.BufferList != null)
throw new ArgumentException ("Multiple buffers cannot be used with this method.");
e.DoOperation (SocketAsyncOperation.Connect, this);
// We always return true for now
return true;
}
示例5: DisconnectAsync
public bool DisconnectAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
e.DoOperation (SocketAsyncOperation.Disconnect, this);
return true;
}
示例6: AcceptAsync
public bool AcceptAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (!IsBound)
throw new InvalidOperationException ("You must call the Bind method before performing this operation.");
if (!islistening)
throw new InvalidOperationException ("You must call the Listen method before performing this operation.");
if (e.BufferList != null)
throw new ArgumentException ("Multiple buffers cannot be used with this method.");
if (e.Count < 0)
throw new ArgumentOutOfRangeException ("e.Count");
Socket acceptSocket = e.AcceptSocket;
if (acceptSocket != null) {
if (acceptSocket.IsBound || acceptSocket.Connected)
throw new InvalidOperationException ("AcceptSocket: The socket must not be bound or connected.");
} else
e.AcceptSocket = new Socket (AddressFamily, SocketType, ProtocolType);
try {
e.DoOperation (SocketAsyncOperation.Accept, this);
} catch {
((IDisposable)e).Dispose ();
throw;
}
// We always return true for now
return true;
}
示例7: SendAsync
public bool SendAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (e.Buffer == null && e.BufferList == null)
throw new ArgumentException ("Either e.Buffer or e.BufferList must be valid buffers.");
e.DoOperation (SocketAsyncOperation.Send, this);
// We always return true for now
return true;
}
示例8: ReceiveAsync
public bool ReceiveAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
//
// LAME SPEC: the ArgumentException is never thrown, instead an NRE is
// thrown when e.Buffer and e.BufferList are null (works fine when one is
// set to a valid object)
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
// We do not support recv into multiple buffers yet
if (e.BufferList != null)
throw new NotSupportedException ("Mono doesn't support using BufferList at this point.");
e.DoOperation (SocketAsyncOperation.Receive, this);
// We always return true for now
return true;
}
示例9: ConnectAsync
public static bool ConnectAsync (SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
{
// exception ordering requires to check before creating the socket (good thing resource wise too)
CheckConnect (e);
Socket s = new Socket (AddressFamily.InterNetwork, socketType, protocolType);
e.DoOperation (SocketAsyncOperation.Connect, s);
// We always return true for now
return true;
}