Esempio n. 1
0
        void begin_receive(Socket socket, SocketAsyncEventArgs receive_args, SocketAsyncEventArgs send_args)
        {
            // receive_args, send_args 아무곳에서나 꺼내와도 된다. 둘다 동일한 CUserToken을 물고 있다.
            CUserToken token = receive_args.UserToken as CUserToken;

            token.set_event_args(receive_args, send_args);
            // 생성된 클라이언트 소켓을 보관해 놓고 통신할 때 사용한다.
            token.socket = socket;

            bool pending = socket.ReceiveAsync(receive_args);

            if (!pending)
            {
                process_receive(receive_args);
            }
        }
Esempio n. 2
0
        void on_session_closed(CUserToken token)
        {
            this.usermanager.remove(token);

            // Free the SocketAsyncEventArg so they can be reused by another client
            // 버퍼는 반환할 필요가 없다. SocketAsyncEventArg가 버퍼를 물고 있기 때문에
            // 이것을 재사용 할 때 물고 있는 버퍼를 그대로 사용하면 되기 때문이다.
            if (this.receive_event_args_pool != null)
            {
                this.receive_event_args_pool.Push(token.receive_event_args);
            }

            if (this.send_event_args_pool != null)
            {
                this.send_event_args_pool.Push(token.send_event_args);
            }

            token.set_event_args(null, null);
        }
Esempio n. 3
0
        void begin_receive(Socket client_socket, SocketAsyncEventArgs recv_args, SocketAsyncEventArgs send_args)
        {
            // receve_args, send_args 아무곳에서나 꺼내와도 된다. 둘다 동일한 CUserToken을 물고 있다.
            CUserToken token = recv_args.UserToken as CUserToken;

            token.set_event_args(recv_args, send_args);

            // 생성된 클라이언트 소켓을 보관해 놓고 통신할 떄 사용한다.
            token.socket = client_socket;

            // 데이터를 받을 수 있도록 소켓 매소드를 호출해줍니다.
            // 비동기로 수신할 경우 워커 스레드에서 대기중으로 있다가 Completed 에 설정해 놓은 매소드가 호출됩니다.
            // 동기로 완료될 경우에는 직접 완료 매소드 호출해줘야 한다.
            bool pending = client_socket.ReceiveAsync(recv_args);

            if (!pending)
            {
                process_receive(recv_args);
            }
        }