示例#1
0
        private void ReceiveAsync(SocketTcpAsync.ReceiveContext context = null)
        {
            bool flag = context == null;

            if (flag)
            {
                context = new SocketTcpAsync.ReceiveContext(this.sock, new byte[9], new byte[base.MTU]);
            }
            try
            {
                this.sock.BeginReceive(context.CurrentBuffer, context.CurrentOffset, context.CurrentExpected - context.CurrentOffset, SocketFlags.None, new AsyncCallback(this.ReceiveAsync), context);
            }
            catch (Exception ex)
            {
                bool flag2 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
                if (flag2)
                {
                    bool flag3 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                    if (flag3)
                    {
                        base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[]
                        {
                            "SocketTcpAsync.ReceiveAsync Exception. State: ",
                            base.State,
                            ". Server: '",
                            base.ServerAddress,
                            "' Exception: ",
                            ex
                        }));
                    }
                    base.HandleException(StatusCode.ExceptionOnReceive);
                }
            }
        }
示例#2
0
        private void ReceiveAsync(IAsyncResult ar)
        {
            bool flag = base.State == PhotonSocketState.Disconnecting || base.State == PhotonSocketState.Disconnected;

            if (!flag)
            {
                int num = 0;
                try
                {
                    num = this.sock.EndReceive(ar);
                    bool flag2 = num == 0;
                    if (flag2)
                    {
                        throw new SocketException(10054);
                    }
                }
                catch (SocketException ex)
                {
                    bool flag3 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
                    if (flag3)
                    {
                        bool flag4 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                        if (flag4)
                        {
                            base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[]
                            {
                                "SocketTcpAsync.EndReceive SocketException. State: ",
                                base.State,
                                ". Server: '",
                                base.ServerAddress,
                                "' ErrorCode: ",
                                ex.ErrorCode,
                                " SocketErrorCode: ",
                                ex.SocketErrorCode,
                                " Message: ",
                                ex.Message,
                                " ",
                                ex
                            }));
                        }
                        base.HandleException(StatusCode.ExceptionOnReceive);
                        return;
                    }
                }
                catch (Exception ex2)
                {
                    bool flag5 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
                    if (flag5)
                    {
                        bool flag6 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                        if (flag6)
                        {
                            base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[]
                            {
                                "SocketTcpAsync.EndReceive Exception. State: ",
                                base.State,
                                ". Server: '",
                                base.ServerAddress,
                                "' Exception: ",
                                ex2
                            }));
                        }
                        base.HandleException(StatusCode.ExceptionOnReceive);
                        return;
                    }
                }
                SocketTcpAsync.ReceiveContext receiveContext = (SocketTcpAsync.ReceiveContext)ar.AsyncState;
                bool flag7 = num + receiveContext.CurrentOffset != receiveContext.CurrentExpected;
                if (flag7)
                {
                    bool readingHeader = receiveContext.ReadingHeader;
                    if (readingHeader)
                    {
                        receiveContext.ReceivedHeaderBytes += num;
                    }
                    else
                    {
                        receiveContext.ReceivedMessageBytes += num;
                    }
                    this.ReceiveAsync(receiveContext);
                }
                else
                {
                    bool readingHeader2 = receiveContext.ReadingHeader;
                    if (readingHeader2)
                    {
                        byte[] headerBuffer = receiveContext.HeaderBuffer;
                        bool   flag8        = headerBuffer[0] == 240;
                        if (flag8)
                        {
                            base.HandleReceivedDatagram(headerBuffer, headerBuffer.Length, true);
                            receiveContext.Reset();
                            this.ReceiveAsync(receiveContext);
                        }
                        else
                        {
                            int num2 = (int)headerBuffer[1] << 24 | (int)headerBuffer[2] << 16 | (int)headerBuffer[3] << 8 | (int)headerBuffer[4];
                            receiveContext.ExpectedMessageBytes = num2 - 7;
                            bool flag9 = receiveContext.ExpectedMessageBytes > receiveContext.MessageBuffer.Length;
                            if (flag9)
                            {
                                receiveContext.MessageBuffer = new byte[receiveContext.ExpectedMessageBytes];
                            }
                            receiveContext.MessageBuffer[0]     = headerBuffer[7];
                            receiveContext.MessageBuffer[1]     = headerBuffer[8];
                            receiveContext.ReceivedMessageBytes = 2;
                            this.ReceiveAsync(receiveContext);
                        }
                    }
                    else
                    {
                        base.HandleReceivedDatagram(receiveContext.MessageBuffer, receiveContext.ExpectedMessageBytes, true);
                        receiveContext.Reset();
                        this.ReceiveAsync(receiveContext);
                    }
                }
            }
        }