Пример #1
0
 /// <summary>
 /// Answer the <code>Configuration</code> with defaults.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <returns></returns>
 public static Configuration DefaultedFor(
     Stage stage,
     IResponseConsumer consumerOfUnknownResponses)
 => DefaultedExceptFor(
     stage,
     Address.From(Host.Of("localhost"), 8080, AddressType.None),
     consumerOfUnknownResponses);
Пример #2
0
        public HyperPipe(int poolSize,
                         IRequestProvider <T> requestProvider,
                         IResponseConsumer <T> responseConsumer)
        {
            _requestProvider  = requestProvider;
            _responseConsumer = responseConsumer;

            _easyPool    = new EasyPool <T>(poolSize);
            _multiHandle = CurlNative.Multi.Init();
            if (_multiHandle.IsInvalid)
            {
                throw new Exception("Could not init curl_multi handle.");
            }

            _socketMap = new SocketPollMap();
            _loop      = new Loop();
            _timeout   = _loop.CreateTimer();

            // Explicitly define callback functions to keep them from being GCed.
            _socketCallback = HandleSocket;
            _timerCallback  = StartTimeout;

            Logger.LogDebug($"Set {CURLMoption.SOCKETFUNCTION}.");
            CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.SOCKETFUNCTION, _socketCallback);
            Logger.LogDebug($"Set {CURLMoption.TIMERFUNCTION}.");
            CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.TIMERFUNCTION, _timerCallback);
        }
Пример #3
0
 /// <summary>
 /// Answer the <code>Configuration</code> with for keep-alive mode with defaults
 /// except for the <paramref name="addressOfHost"/> and <paramref name="consumerOfUnknownResponses"/>.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <returns></returns>
 public static Configuration DefaultedKeepAliveExceptFor(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses)
 => Has(
     stage,
     addressOfHost,
     consumerOfUnknownResponses,
     true,
     10,
     10240,
     10,
     10240);
Пример #4
0
 /// <summary>
 /// Answer the <code>Configuration</code> with for keep-alive mode with defaults
 /// except for the <paramref name="addressOfHost"/> and <paramref name="consumerOfUnknownResponses"/>.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <returns></returns>
 public static Configuration DefaultedKeepAliveExceptFor(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses)
 => Has(
     stage,
     addressOfHost,
     consumerOfUnknownResponses,
     true,
     10,
     10240,
     10,
     10240,
     TimeSpan.FromMilliseconds(1000));
Пример #5
0
 /// <summary>
 /// Answer the <code>Configuration</code> with defaults except for the
 /// <paramref name="addressOfHost"/>, <paramref name="consumerOfUnknownResponses"/>,
 /// <paramref name="writeBufferSize"/>,
 /// and <paramref name="readBufferSize"/>.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <param name="writeBufferSize">The int size of the write buffer.</param>
 /// <param name="readBufferSize">The int size of the read buffer.</param>
 /// <returns></returns>
 public static Configuration DefaultedExceptFor(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses,
     int writeBufferSize,
     int readBufferSize)
 => Has(
     stage,
     addressOfHost,
     consumerOfUnknownResponses,
     false,
     10,
     writeBufferSize,
     10,
     readBufferSize);
Пример #6
0
 /// <summary>
 /// Answer the <code>Configuration</code> with the given options and that requires a secure channel.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <param name="keepAlive">The boolean indicating whether or not the connection is kept alive over multiple requests-responses.</param>
 /// <param name="probeInterval">The long number of milliseconds between each consumer channel probe.</param>
 /// <param name="writeBufferSize">The int size of the buffer used for writes/sends.</param>
 /// <param name="readBufferPoolSize">The int number of read buffers in the pool.</param>
 /// <param name="readBufferSize">The int size of the buffer used for reads/receives.</param>
 /// <returns></returns>
 public static Configuration Secure(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses,
     bool keepAlive,
     long probeInterval,
     int writeBufferSize,
     int readBufferPoolSize,
     int readBufferSize)
 => new Configuration(
     stage,
     addressOfHost,
     consumerOfUnknownResponses,
     keepAlive,
     probeInterval,
     writeBufferSize,
     readBufferPoolSize,
     readBufferSize,
     true);
Пример #7
0
 /// <summary>
 /// Answer the <code>Configuration</code> with the given options.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <param name="keepAlive">The boolean indicating whether or not the connection is kept alive over multiple requests-responses.</param>
 /// <param name="probeInterval">The long number of milliseconds between each consumer channel probe.</param>
 /// <param name="writeBufferSize">The int size of the buffer used for writes/sends.</param>
 /// <param name="readBufferPoolSize">The int number of read buffers in the pool.</param>
 /// <param name="readBufferSize">The int size of the buffer used for reads/receives.</param>
 /// <param name="clientConnectionTimeout">The timeout for a client to establish connection.</param>
 /// <returns></returns>
 public static Configuration Has(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses,
     bool keepAlive,
     long probeInterval,
     int writeBufferSize,
     int readBufferPoolSize,
     int readBufferSize,
     TimeSpan clientConnectionTimeout)
 => new Configuration(
     stage,
     addressOfHost,
     consumerOfUnknownResponses,
     keepAlive,
     probeInterval,
     writeBufferSize,
     readBufferPoolSize,
     readBufferSize,
     false);
Пример #8
0
 /// <summary>
 /// Constructs my default state with the given options.
 /// </summary>
 /// <param name="stage">The Stage to host the Client.</param>
 /// <param name="addressOfHost">The Address of the host server.</param>
 /// <param name="consumerOfUnknownResponses">The ResponseConsumer of responses that cannot be associated with a given consumer.</param>
 /// <param name="keepAlive">The boolean indicating whether or not the connection is kept alive over multiple requests-responses.</param>
 /// <param name="probeInterval">The long number of milliseconds between each consumer channel probe.</param>
 /// <param name="writeBufferSize">The int size of the buffer used for writes/sends.</param>
 /// <param name="readBufferPoolSize">The int number of read buffers in the pool.</param>
 /// <param name="readBufferSize">The int size of the buffer used for reads/receives.</param>
 /// <param name="secure">The boolean indicating whether the connection should be secure.</param>
 public Configuration(
     Stage stage,
     Address addressOfHost,
     IResponseConsumer consumerOfUnknownResponses,
     bool keepAlive,
     long probeInterval,
     int writeBufferSize,
     int readBufferPoolSize,
     int readBufferSize,
     bool secure)
 {
     Stage         = stage;
     AddressOfHost = addressOfHost;
     ConsumerOfUnknownResponses = consumerOfUnknownResponses;
     KeepAlive          = keepAlive;
     ProbeInterval      = probeInterval;
     WriteBufferSize    = writeBufferSize;
     ReadBufferPoolSize = readBufferPoolSize;
     ReadBufferSize     = readBufferSize;
     IsSecure           = secure;
 }
Пример #9
0
 public void RemoveSource(IResponseConsumer source)
 {
     this.RaiseResponseEvent -= source.HandleResponseEvent;
     source.RaiseUserEvent -= this.HandleUserEvent;
 }
Пример #10
0
 public void AddSource(IResponseConsumer source)
 {
     this.RaiseResponseEvent += source.HandleResponseEvent;
     source.RaiseUserEvent += this.HandleUserEvent;
 }