Esempio n. 1
0
        TcpStreamGenerator.CallbackReturnValue HandleStreamGeneratorOnCallback(TcpStreamGenerator tcpStreamGenerator,
                                                                               TcpStreamGenerator.CallbackCondition condition)
        {
            switch (condition)
            {
            // stop monitoring if we have an error condition
            case TcpStreamGenerator.CallbackCondition.SizeLimitReached:
            case TcpStreamGenerator.CallbackCondition.OutOfRange:
            case TcpStreamGenerator.CallbackCondition.ConnectionTimeout:
            case TcpStreamGenerator.CallbackCondition.StreamError:
                string errorString = string.Format("condition == {0}, shutting down monitors",
                                                   condition);
                log.Warn(errorString);
                ShutDownMonitor(errorString);
                return(TcpStreamGenerator.CallbackReturnValue.StopMonitoring);

            // early out if we don't have the next packet in sequence
            case TcpStreamGenerator.CallbackCondition.OutOfSequence:
                if (IsDebugEnabled)
                {
                    log.DebugFormat("condition {0} != TcpStreamMonitor.CallbackCondition.NextInSequence, returning ContinueMonitoring",
                                    condition);
                }
                return(TcpStreamGenerator.CallbackReturnValue.ContinueMonitoring);

            case TcpStreamGenerator.CallbackCondition.DuplicateDropped:
                // nothing to do here, we dropped a duplicate entry
                return(TcpStreamGenerator.CallbackReturnValue.ContinueMonitoring);

            // normal case, nothing to do here but fall through
            case TcpStreamGenerator.CallbackCondition.NextInSequence:
                break;

            default:
                string error = "Unknown condition of '" + condition + "'";
                throw new System.InvalidOperationException(error);
            }

            // process the data in the TcpStream until we encounter
            // an error/exception case
            HttpMessage.ProcessStatus processStatus;
            while (true)
            {
                processStatus = HandleTcpStreamGenerator(tcpStreamGenerator);

                if (IsDebugEnabled)
                {
                    log.DebugFormat("processStatus is {0}", processStatus);
                }

                // if an error was detected we should stop monitoring the monitor
                // with the error and delete the other monitor
                if (processStatus == HttpMessage.ProcessStatus.Error)
                {
                    var    monitorType = tcpStreamGeneratorToMonitorType[tcpStreamGenerator];
                    string errorString = string.Format("Processing monitorType {0} got {1}, stopping monitor and deleting other monitor",
                                                       monitorType, processStatus);
                    ShutDownMonitor(errorString);
                    return(TcpStreamGenerator.CallbackReturnValue.StopMonitoring);
                }
                else if (processStatus == HttpMessage.ProcessStatus.NeedMoreData)
                {
                    // not enough data remaining in the TcpStream so stop looping
                    // and ask the TcpStreamMonitor to continue monitoring
                    return(TcpStreamGenerator.CallbackReturnValue.ContinueMonitoring);
                }
                else if (processStatus == HttpMessage.ProcessStatus.Continue)
                {
                    // just continue looping
                }
                else if (processStatus == HttpMessage.ProcessStatus.Continue)
                {
                    // just continue looping
                }
            }
        }
Esempio n. 2
0
        TcpStreamGenerator.CallbackReturnValue HandleTcpStreamGeneratorOnCallback(TcpStreamGenerator tcpStreamGenerator, TcpStreamGenerator.CallbackCondition condition)
        {
            Console.WriteLine("{0} bytes in stream",
                              tcpStreamGenerator.tcpStream.Length);

            int expectedSize = 0;

            for (int i = 0; i < callbackCount; i++)
            {
                expectedSize += payloadSizes[i];
            }

            Assert.Equal(expectedSize, tcpStreamGenerator.tcpStream.Length);

            callbackCount++;
            return(TcpStreamGenerator.CallbackReturnValue.ContinueMonitoring);
        }