コード例 #1
0
ファイル: UDTSocket.cs プロジェクト: xingchaoet/ourmsg
        public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state)
        {
            AsyncReceiveRegistration asyncRegistration = new AsyncReceiveRegistration(this, buffer, offset, size, socketFlags, callback, state);

            lock (_receiveRegistrations)
                _receiveRegistrations.Add(asyncRegistration);

            return(null);
        }
コード例 #2
0
ファイル: UDTSocket.cs プロジェクト: xingchaoet/ourmsg
        static private void UDTThreadProcessing()
        {
            try
            {
                while (Thread.CurrentThread.IsAlive)
                {
                    //---- Accept

                    for (int index = _acceptRegistrations.Count - 1; index > -1; index--)
                    {
                        Monitor.Enter(_acceptRegistrations);
                        AsyncAcceptRegistration registration = _acceptRegistrations[index];
                        Monitor.Exit(_acceptRegistrations);

                        if (registration.Socket.IsOnAccept)
                        {
                            // Stop "BeginAccept"
                            lock (_acceptRegistrations)
                                _acceptRegistrations.RemoveAt(index);

                            // Queue it for the call back
                            _processor.AddCommand(registration);
                        }
                    }

                    //---- Receive

                    for (int index = _receiveRegistrations.Count - 1; index > -1; index--)
                    {
                        Monitor.Enter(_receiveRegistrations);
                        AsyncReceiveRegistration registration = _receiveRegistrations[index];
                        Monitor.Exit(_receiveRegistrations);

                        if (!registration.Socket.Connected || registration.Socket.IsOnRead)
                        {
                            // Stop "BeginReceive"
                            lock (_receiveRegistrations)
                                _receiveRegistrations.RemoveAt(index);

                            // Queue it for the call back
                            _processor.AddCommand(registration);
                        }
                    }

                    //---- Like "Select" Wait for an event or 1 millisecond
                    API_WaitForEvent();
                }
            }
            catch (ThreadInterruptedException)
            { }
        }
コード例 #3
0
ファイル: UDTSocket.cs プロジェクト: cheehwasun/ourmsg
		public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state)
		{
			AsyncReceiveRegistration asyncRegistration = new AsyncReceiveRegistration(this, buffer, offset, size, socketFlags, callback, state);
			lock (_receiveRegistrations)
				_receiveRegistrations.Add(asyncRegistration);

			return null;
		}