示例#1
0
        public virtual RelayRequestResponse RecvRelayRequestResponse()
        {
            RelayRequestResponse response = null;

            if (Recv(s => { response = RelayRequestResponseReader.Read(s); }))
            {
                Logger.Debug("Relay response: {0}", response.StatusCode);
                return(response);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        private State WaitRelayResponse()
        {
            relayResponse = null;
            bool longresponse = false;

            try {
                connection.Recv(stream => {
                    longresponse  = stream.Length >= 2048;
                    relayResponse = RelayRequestResponseReader.Read(stream);
                });
            }
            catch (IOException) {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            if (relayResponse != null)
            {
                Logger.Debug("Relay response: {0}", relayResponse.StatusCode);
                if (relayResponse.StatusCode == 200 || relayResponse.StatusCode == 503)
                {
                    return(State.SendingHandshakeRequest);
                }
                else
                {
                    Logger.Error("Server responses {0} to GET {1}", relayResponse.StatusCode, SourceUri.PathAndQuery);
                    Stop(relayResponse.StatusCode == 404 ? StopReason.OffAir : StopReason.UnavailableError);
                    return(State.Disconnected);
                }
            }
            else if (longresponse)
            {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            else
            {
                return(State.WaitingRelayResponse);
            }
        }