本文整理汇总了C#中SocketOperation类的典型用法代码示例。如果您正苦于以下问题:C# SocketOperation类的具体用法?C# SocketOperation怎么用?C# SocketOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketOperation类属于命名空间,在下文中一共展示了SocketOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
{
base.Init (callback, state);
this.socket = socket;
this.handle = socket != null ? socket.Handle : IntPtr.Zero;
this.operation = operation;
DelayedException = null;
EndPoint = null;
Buffer = null;
Offset = 0;
Size = 0;
SockFlags = SocketFlags.None;
AcceptSocket = null;
Addresses = null;
Port = 0;
Buffers = null;
ReuseSocket = false;
CurrentAddress = 0;
AcceptedSocket = null;
Total = 0;
error = 0;
EndCalled = 0;
}
示例2: OnError
static HandleResult OnError(TcpClient sender, SocketOperation enOperation, int errorCode)
{
// 出错了
AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", sender.ConnectionId, enOperation, errorCode));
// 通知界面,只处理了连接错误,也没进行是不是连接错误的判断,所以有错误就会设置界面
// 生产环境请自己控制
//this.Invoke(new SetAppStateDelegate(SetAppState), AppState.Stoped);
return HandleResult.Ok;
}
示例3: AssertCounter
private void AssertCounter(SocketOperation operation, Func<MockServerSocket4, long> delegatingRetriever, Func<PerformanceCounter> counterRetriever, int expectedCount)
{
MockServerSocket4 mockServerSocket = new MockServerSocket4();
IServerSocket4 serverSocket = new MonitoredServerSocket4(mockServerSocket);
FileSession().WithEnvironment(
delegate
{
IList<ISocket4> clients = new List<ISocket4>();
for (int i = 0; i < ClientCount; i++)
{
clients.Add(serverSocket.Accept());
}
for (int i = 0; i < clients.Count; i++)
{
operation(clients[i], i);
}
});
Assert.AreEqual(expectedCount, delegatingRetriever(mockServerSocket));
Assert.AreEqual(expectedCount, counterRetriever().RawValue);
}
示例4: OnError
HandleResult OnError(TcpClient sender, SocketOperation enOperation, int errorCode)
{
// 出错了
return HandleResult.Ok;
}
示例5: InitSocketAsyncEventArgs
void InitSocketAsyncEventArgs (SocketAsyncEventArgs e, AsyncCallback callback, object state, SocketOperation operation)
{
e.socket_async_result.Init (this, callback, state, operation);
e.current_socket = this;
e.SetLastOperation (SocketOperationToSocketAsyncOperation (operation));
e.SocketError = SocketError.Success;
e.BytesTransferred = 0;
}
示例6: Init
/* This is called when reusing a SocketAsyncEventArgs */
public void Init (Socket sock, object state, AsyncCallback callback, SocketOperation op)
{
result.Init (sock, state, callback, op);
SocketAsyncOperation async_op;
// Notes;
// -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
// -SendPackets and ReceiveMessageFrom are not implemented yet
if (op == Socket.SocketOperation.Connect)
async_op = SocketAsyncOperation.Connect;
#if !MOONLIGHT
else if (op == Socket.SocketOperation.Accept)
async_op = SocketAsyncOperation.Accept;
else if (op == Socket.SocketOperation.Disconnect)
async_op = SocketAsyncOperation.Disconnect;
#endif
else if (op == Socket.SocketOperation.Receive || op == Socket.SocketOperation.ReceiveGeneric)
async_op = SocketAsyncOperation.Receive;
#if !MOONLIGHT
else if (op == Socket.SocketOperation.ReceiveFrom)
async_op = SocketAsyncOperation.ReceiveFrom;
#endif
/*
else if (op == Socket.SocketOperation.ReceiveMessageFrom)
async_op = SocketAsyncOperation.ReceiveMessageFrom;
*/
else if (op == Socket.SocketOperation.Send || op == Socket.SocketOperation.SendGeneric)
async_op = SocketAsyncOperation.Send;
#if !MOONLIGHT
/*
else if (op == Socket.SocketOperation.SendPackets)
async_op = SocketAsyncOperation.SendPackets;
*/
else if (op == Socket.SocketOperation.SendTo)
async_op = SocketAsyncOperation.SendTo;
#endif
else
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", op));
args.SetLastOperation (async_op);
args.SocketError = SocketError.Success;
}
示例7: SocketAsyncResult
public SocketAsyncResult (Socket sock, object state, AsyncCallback callback, SocketOperation operation)
{
this.Sock = sock;
this.blocking = sock.blocking;
this.handle = sock.socket;
this.state = state;
this.callback = callback;
this.operation = operation;
SockFlags = SocketFlags.None;
}
示例8: SocketAsyncResult
public SocketAsyncResult (Socket socket, object state, AsyncCallback callback, SocketOperation operation)
{
Init (socket, state, callback, operation, new SocketAsyncWorker (this));
}
示例9: OnClose
HandleResult OnClose(IntPtr connId, SocketOperation enOperation, int errorCode)
{
if(errorCode == 0)
// 客户离开了
AddMsg(string.Format(" > [{0},OnClose]", connId));
else
// 客户出错了
AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode));
// return HPSocketSdk.HandleResult.Ok;
// 释放附加数据
if (server.SetConnectionExtra(connId, null) == false)
{
AddMsg(string.Format(" > [{0},OnClose] -> SetConnectionExtra({0}, null) fail", connId));
}
return HandleResult.Ok;
}
示例10: Init
/* This is called when reusing a SocketAsyncEventArgs */
public void Init (Socket sock, SocketAsyncEventArgs args, SocketOperation op)
{
result.Init (sock, args, SocketAsyncEventArgs.Dispatcher, op);
result.Worker = this;
SocketAsyncOperation async_op;
// Notes;
// -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
// -SendPackets and ReceiveMessageFrom are not implemented yet
if (op == Socket.SocketOperation.Connect)
async_op = SocketAsyncOperation.Connect;
else if (op == Socket.SocketOperation.Accept)
async_op = SocketAsyncOperation.Accept;
else if (op == Socket.SocketOperation.Disconnect)
async_op = SocketAsyncOperation.Disconnect;
else if (op == Socket.SocketOperation.Receive || op == Socket.SocketOperation.ReceiveGeneric)
async_op = SocketAsyncOperation.Receive;
else if (op == Socket.SocketOperation.ReceiveFrom)
async_op = SocketAsyncOperation.ReceiveFrom;
/*
else if (op == Socket.SocketOperation.ReceiveMessageFrom)
async_op = SocketAsyncOperation.ReceiveMessageFrom;
*/
else if (op == Socket.SocketOperation.Send || op == Socket.SocketOperation.SendGeneric)
async_op = SocketAsyncOperation.Send;
/*
else if (op == Socket.SocketOperation.SendPackets)
async_op = SocketAsyncOperation.SendPackets;
*/
else if (op == Socket.SocketOperation.SendTo)
async_op = SocketAsyncOperation.SendTo;
else
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", op));
args.SetLastOperation (async_op);
args.SocketError = SocketError.Success;
args.BytesTransferred = 0;
}
示例11: OnAgentClose
/// <summary>
/// 出错了
/// </summary>
/// <param name="connId"></param>
/// <param name="enOperation"></param>
/// <param name="errorCode"></param>
/// <returns></returns>
protected virtual HandleResult OnAgentClose(IntPtr connId, SocketOperation enOperation, int errorCode)
{
if(errorCode == 0)
AddMsg(string.Format(" > [{0},OnAgentClose]", connId));
else
AddMsg(string.Format(" > [{0},OnAgentError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode));
// return HPSocketSdk.HandleResult.Ok;
// 获取附加数据
IntPtr extraPtr = IntPtr.Zero;
if (agent.GetConnectionExtra(connId, ref extraPtr) == false)
{
return HandleResult.Error;
}
ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData));
agent.SetConnectionExtra(connId, null);
if (extra.FreeType == 0)
{
// 由Target断开连接,释放server连接
extra.FreeType = 1;
server.SetConnectionExtra(extra.ConnIdForServer, extra);
extra.Server.Disconnect(extra.ConnIdForServer);
}
return HandleResult.Ok;
}
示例12: SocketAsyncResult
public SocketAsyncResult (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
: base (callback, state)
{
this.socket = socket;
this.handle = socket != null ? socket.Handle : IntPtr.Zero;
this.operation = operation;
}
示例13: RequestContext
public RequestContext(SocketOperation operation, ByteBuf data)
{
Operation = operation;
Data = data;
}
示例14: Init
/* This is called when reusing a SocketAsyncEventArgs */
public void Init (Socket sock, SocketAsyncEventArgs args, SocketOperation op)
{
result.Init (sock, args, SocketAsyncEventArgs.Dispatcher, op, this);
SocketAsyncOperation async_op;
// Notes;
// -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
// -SendPackets and ReceiveMessageFrom are not implemented yet
switch (op) {
case SocketOperation.Connect:
async_op = SocketAsyncOperation.Connect;
break;
case SocketOperation.Accept:
async_op = SocketAsyncOperation.Accept;
break;
case SocketOperation.Disconnect:
async_op = SocketAsyncOperation.Disconnect;
break;
case SocketOperation.Receive:
case SocketOperation.ReceiveGeneric:
async_op = SocketAsyncOperation.Receive;
break;
case SocketOperation.ReceiveFrom:
async_op = SocketAsyncOperation.ReceiveFrom;
break;
// case SocketOperation.ReceiveMessageFrom:
// async_op = SocketAsyncOperation.ReceiveMessageFrom;
// break;
case SocketOperation.Send:
case SocketOperation.SendGeneric:
async_op = SocketAsyncOperation.Send;
break;
// case SocketOperation.SendPackets:
// async_op = SocketAsyncOperation.SendPackets;
// break;
case SocketOperation.SendTo:
async_op = SocketAsyncOperation.SendTo;
break;
default:
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", op));
}
args.SetLastOperation (async_op);
args.SocketError = SocketError.Success;
args.BytesTransferred = 0;
}
示例15: OnServerError
/// <summary>
/// 出错了
/// </summary>
/// <param name="connId"></param>
/// <param name="enOperation"></param>
/// <param name="errorCode"></param>
/// <returns></returns>
protected virtual HandleResult OnServerError(IntPtr connId, SocketOperation enOperation, int errorCode)
{
AddMsg(string.Format(" > [{0},OnServerError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode));
// return HPSocketSdk.HandleResult.Ok;
// 因为要释放附加数据,所以直接返回OnServerClose()了
return OnServerClose(connId);
}