Exemplo n.º 1
0
        private void OnStateWaitResponse()
        {
            Status = SourceStreamStatus.Connecting;
            HTTPResponse response = null;

            if (Recv(stream => { response = HTTPResponseReader.Read(stream); }))
            {
                if (response.Status == 200)
                {
                    lastReceived = Environment.TickCount;
                    state        = State.Receiving;
                }
                else
                {
                    Logger.Error("Server responses {0} to GET {1}", response.Status, SourceUri.PathAndQuery);
                    EndConnection();
                    state = State.Retrying;
                }
            }
            else if (Environment.TickCount - waitResponseStart > 10000)
            {
                Logger.Error("Recv response timed out");
                EndConnection();
                state = State.Retrying;
            }
        }
Exemplo n.º 2
0
        private State WaitResponse()
        {
            response = null;
            bool longresponse = false;

            try {
                connection.Recv(stream => {
                    longresponse = stream.Length >= 2048;
                    response     = HTTPResponseReader.Read(stream);
                });
            }
            catch (IOException) {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            if (response != null)
            {
                if (response.Status == 200)
                {
                    return(State.Receiving);
                }
                else
                {
                    Logger.Error("Server responses {0} to GET {1}", response.Status, SourceUri.PathAndQuery);
                    Stop(response.Status == 404 ? StopReason.OffAir : StopReason.UnavailableError);
                    return(State.Disconnected);
                }
            }
            else if (longresponse)
            {
                Stop(StopReason.ConnectionError);
                return(State.Disconnected);
            }
            else
            {
                return(State.WaitingResponse);
            }
        }