Exemple #1
0
        static void DispatcherCB(IAsyncResult ares)
        {
            SocketAsyncEventArgs args = (SocketAsyncEventArgs)ares.AsyncState;

            if (Interlocked.Exchange(ref args.in_progress, 0) != 1)
            {
                throw new InvalidOperationException("No operation in progress");
            }
            SocketAsyncOperation op = args.LastOperation;

            // Notes;
            //  -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
            //	-SendPackets and ReceiveMessageFrom are not implemented yet
            if (op == SocketAsyncOperation.Receive)
            {
                args.ReceiveCallback(ares);
            }
            else if (op == SocketAsyncOperation.Send)
            {
                args.SendCallback(ares);
            }
#if !MOONLIGHT
            else if (op == SocketAsyncOperation.ReceiveFrom)
            {
                args.ReceiveFromCallback(ares);
            }
            else if (op == SocketAsyncOperation.SendTo)
            {
                args.SendToCallback(ares);
            }
            else if (op == SocketAsyncOperation.Accept)
            {
                args.AcceptCallback(ares);
            }
            else if (op == SocketAsyncOperation.Disconnect)
            {
                args.DisconnectCallback(ares);
            }
#endif
            else if (op == SocketAsyncOperation.Connect)
            {
                args.ConnectCallback();
            }

            /*
             * else if (op == Socket.SocketOperation.ReceiveMessageFrom)
             * else if (op == Socket.SocketOperation.SendPackets)
             */
            else
            {
                throw new NotImplementedException(String.Format("Operation {0} is not implemented", op));
            }
        }
        static void DispatcherCB(IAsyncResult ares)
        {
            SocketAsyncEventArgs args = (SocketAsyncEventArgs)ares.AsyncState;

            if (Interlocked.Exchange(ref args.in_progress, 0) != 1)
            {
                throw new InvalidOperationException("No operation in progress");
            }

            /* Notes;
             *  -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
             *  -SendPackets and ReceiveMessageFrom are not implemented yet */
            switch (args.LastOperation)
            {
            case SocketAsyncOperation.Receive:
                args.ReceiveCallback(ares);
                break;

            case SocketAsyncOperation.Send:
                args.SendCallback(ares);
                break;

            case SocketAsyncOperation.ReceiveFrom:
                args.ReceiveFromCallback(ares);
                break;

            case SocketAsyncOperation.SendTo:
                args.SendToCallback(ares);
                break;

            case SocketAsyncOperation.Accept:
                args.AcceptCallback(ares);
                break;

            case SocketAsyncOperation.Disconnect:
                args.DisconnectCallback(ares);
                break;

            case SocketAsyncOperation.Connect:
                args.ConnectCallback(ares);
                break;

            /*
             * case SocketOperation.ReceiveMessageFrom:
             * case SocketOperation.SendPackets:
             */
            default:
                throw new NotImplementedException(String.Format("Operation {0} is not implemented", args.LastOperation));
            }
        }
Exemple #3
0
        static void DispatcherCB(IAsyncResult ares)
        {
            SocketAsyncEventArgs args = (SocketAsyncEventArgs)ares.AsyncState;
            SocketAsyncOperation op   = args.LastOperation;

            // Notes;
            //  -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
            //	-SendPackets and ReceiveMessageFrom are not implemented yet
            if (op == SocketAsyncOperation.Receive)
            {
                args.ReceiveCallback(ares);
            }
            else if (op == SocketAsyncOperation.Send)
            {
                args.SendCallback(ares);
            }
#if !MOONLIGHT
            else if (op == SocketAsyncOperation.ReceiveFrom)
            {
                args.ReceiveFromCallback(ares);
            }
            else if (op == SocketAsyncOperation.SendTo)
            {
                args.SendToCallback(ares);
            }
            else if (op == SocketAsyncOperation.Accept)
            {
                args.AcceptCallback(ares);
            }
            else if (op == SocketAsyncOperation.Disconnect)
            {
                args.DisconnectCallback(ares);
            }
#endif
            else if (op == SocketAsyncOperation.Connect)
            {
                args.ConnectCallback();                  /* This should not be hit yet. See DoOperation() */
            }

            /*
             * else if (op == Socket.SocketOperation.ReceiveMessageFrom)
             * else if (op == Socket.SocketOperation.SendPackets)
             */
            else
            {
                throw new NotImplementedException(String.Format("Operation {0} is not implemented", op));
            }
        }