Fun.FunapiTcpTransport.StartCb C# (CSharp) Method

StartCb() private method

private StartCb ( IAsyncResult ar ) : void
ar IAsyncResult
return void
        private void StartCb(IAsyncResult ar)
        {
            DebugUtils.DebugLog("StartCb called.");

            try
            {
                if (sock_ == null)
                {
                    last_error_code_ = ErrorCode.kConnectFailed;
                    last_error_message_ = "Failed to connect. socket is null.";
                    DebugUtils.Log(last_error_message_);
                    return;
                }

                sock_.EndConnect(ar);
                if (sock_.Connected == false)
                {
                    last_error_code_ = ErrorCode.kConnectFailed;
                    last_error_message_ = "Failed to connect.";
                    DebugUtils.Log(last_error_message_);
                    AddToEventQueue(OnFailure);
                    return;
                }
                DebugUtils.Log("Connected.");

                state_ = State.kEncryptionHandshaking;

                lock (receive_lock_)
                {
                    // Wait for encryption handshaking message.
                    ArraySegment<byte> wrapped = new ArraySegment<byte>(receive_buffer_, 0, receive_buffer_.Length);
                    List<ArraySegment<byte>> buffer = new List<ArraySegment<byte>>();
                    buffer.Add(wrapped);
                    sock_.BeginReceive(buffer, 0, new AsyncCallback(this.ReceiveBytesCb), this);
                }
            }
            catch (ObjectDisposedException e)
            {
                DebugUtils.Log("BeginConnect operation has been Cancelled.");
                DebugUtils.DebugLog(e.ToString());
            }
            catch (Exception e)
            {
                last_error_code_ = ErrorCode.kConnectFailed;
                last_error_message_ = "Failure in StartCb: " + e.ToString();
                DebugUtils.Log(last_error_message_);
                AddToEventQueue(OnFailure);
            }
        }