• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SocketOperation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SocketOperation的典型用法代码示例。如果您正苦于以下问题:C# SocketOperation类的具体用法?C# SocketOperation怎么用?C# SocketOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SocketOperation类属于命名空间,在下文中一共展示了SocketOperation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
		}
开发者ID:nickolyamba,项目名称:mono,代码行数:29,代码来源:SocketAsyncResult.cs


示例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;
        }
开发者ID:JerryXia,项目名称:MyWebDevTools,代码行数:12,代码来源:Program.cs


示例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);
		}
开发者ID:erdincay,项目名称:db4o,代码行数:23,代码来源:ServerNetworkingPerformanceCounterTestCase.cs


示例4: OnError

 HandleResult OnError(TcpClient sender, SocketOperation enOperation, int errorCode)
 {
     // 出错了
     return HandleResult.Ok;
 }
开发者ID:andy521,项目名称:HP-Socket,代码行数:5,代码来源:frmClient.cs


示例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;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:Socket.cs


示例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;
			}
开发者ID:telurmasin,项目名称:mono,代码行数:43,代码来源:Socket_2_1.cs


示例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;
			}
开发者ID:telurmasin,项目名称:mono,代码行数:10,代码来源:Socket_2_1.cs


示例8: SocketAsyncResult

		public SocketAsyncResult (Socket socket, object state, AsyncCallback callback, SocketOperation operation)
		{
			Init (socket, state, callback, operation, new SocketAsyncWorker (this));
		}
开发者ID:quarksbar,项目名称:mono,代码行数:4,代码来源:SocketAsyncResult.cs


示例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;
        }
开发者ID:chengfang0911,项目名称:HP-Socket,代码行数:18,代码来源:frmServer.cs


示例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;
			}
开发者ID:nlhepler,项目名称:mono,代码行数:39,代码来源:Socket_2_1.cs


示例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;
        }
开发者ID:chengfang0911,项目名称:HP-Socket,代码行数:37,代码来源:TcpPortForwarding.cs


示例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;
		}
开发者ID:nickolyamba,项目名称:mono,代码行数:7,代码来源:SocketAsyncResult.cs


示例13: RequestContext

 public RequestContext(SocketOperation operation, ByteBuf data)
 {
     Operation = operation;
     Data = data;
 }
开发者ID:qintao1976,项目名称:Mobius,代码行数:5,代码来源:RioSocketWrapper.cs


示例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;
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:48,代码来源:SocketAsyncWorker.cs


示例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);
        }
开发者ID:andy521,项目名称:HP-Socket,代码行数:15,代码来源:ProxyServer.cs


示例16: 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;
				GC.KeepAlive (this.callback);
				this.operation = operation;
				SockFlags = SocketFlags.None;
				Worker = new Worker (this);
			}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:Socket_2_1.cs


示例17: OnServerClose

        /// <summary>
        /// 出错了
        /// </summary>
        /// <param name="connId"></param>
        /// <param name="enOperation"></param>
        /// <param name="errorCode"></param>
        /// <returns></returns>
        protected virtual HandleResult OnServerClose(IntPtr connId, SocketOperation enOperation, int errorCode)
        {
            if (errorCode == 0)
                AddMsg(string.Format(" > [{0},OnServerClose]", connId));
            else
                AddMsg(string.Format(" > [{0},OnServerError] -> OP:{1},CODE:{2}", connId, enOperation, errorCode));
            // return HPSocketSdk.HandleResult.Ok;

            // 获取附加数据
            IntPtr extraPtr = IntPtr.Zero;
            if (server.GetConnectionExtra(connId, ref extraPtr) == false)
            {
                return HandleResult.Error;
            }

            // extra 就是accept里传入的附加数据了
            ConnExtraData extra = (ConnExtraData)Marshal.PtrToStructure(extraPtr, typeof(ConnExtraData));
            if (extra.FreeType == 0)
            {
                // 由client(N)断开连接,释放agent数据
                agent.Disconnect(extra.ConnIdForClient);
                agent.SetConnectionExtra(extra.ConnIdForClient, null);
            }

            server.SetConnectionExtra(connId, null);

            return HandleResult.Ok;
        }
开发者ID:chengfang0911,项目名称:HP-Socket,代码行数:35,代码来源:TcpPortForwarding.cs


示例18: OnError

        HandleResult OnError(uint dwConnID, SocketOperation enOperation, int iErrorCode)
        {
            // 出错了

            AddMsg(string.Format(" > [{0},OnError] -> OP:{1},CODE:{2}", dwConnID, enOperation, iErrorCode));

            // 通知界面,只处理了连接错误,也没进行是不是连接错误的判断,所以有错误就会设置界面
            // 生产环境请自己控制
            this.Invoke(new SetAppStateDelegate(SetAppState), AppState.Stoped);

            return HandleResult.Ok;
        }
开发者ID:roson9527,项目名称:HP-Socket,代码行数:12,代码来源:frmClient.cs


示例19: OnError

 HandleResult OnError(IntPtr dwConnId, SocketOperation enOperation, int iErrorCode)
 {
     // 出错了
     return HandleResult.Ok;
 }
开发者ID:407390911,项目名称:HP-Socket,代码行数:5,代码来源:frmClient.cs


示例20: Init

		public void Init (Socket socket, object state, AsyncCallback callback, SocketOperation operation, SocketAsyncWorker worker)
		{
			this.socket = socket;
			this.is_blocking = socket != null ? socket.is_blocking : true;
			this.handle = socket != null ? socket.Handle : IntPtr.Zero;
			this.state = state;
			this.callback = callback;
			this.operation = operation;

			if (wait_handle != null)
				((ManualResetEvent) wait_handle).Reset ();

			delayed_exception = null;

			EndPoint = null;
			Buffer = null;
			Offset = 0;
			Size = 0;
			SockFlags = SocketFlags.None;
			AcceptSocket = null;
			Addresses = null;
			Port = 0;
			Buffers = null;
			ReuseSocket = false;
			accept_socket = null;
			total = 0;

			completed_synchronously = false;
			completed = false;
			is_blocking = false;
			error = 0;
			async_result = null;
			EndCalled = 0;
			Worker = worker;
		}
开发者ID:quarksbar,项目名称:mono,代码行数:35,代码来源:SocketAsyncResult.cs



注:本文中的SocketOperation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SocketOptionLevel类代码示例发布时间:2022-05-24
下一篇:
C# SocketImplementationType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap