internal void Enqueue(StreamHandle handle, byte[] array, int offset, int count, Action <Exception> completion)
        {
            Contract.Requires(handle != null);
            Contract.Requires(array != null && array.Length > 0);
            Contract.Requires(offset >= 0 && count > 0);
            Contract.Requires((offset + count) <= array.Length);

            WriteTask request;

            if (!this.requestPool.TryDequeue(out request))
            {
                request = new WriteTask(this.OnCompleted);
            }

            request.CompletionAction = completion;

            try
            {
                request.Prepare(array, offset, count);
                handle.WriteStream(request);
            }
            catch (Exception exception)
            {
                Log.Error($"{nameof(WriteTaskQueue)} {request} write error.", exception);
                request.Release();
                request.CompletionAction = null;
                throw;
            }
        }
Exemple #2
0
        static void OnConnectionCallback(IntPtr handle, int status)
        {
            var server = RequestContext.GetTarget <StreamHandle>(handle);

            if (server == null)
            {
                return;
            }

            StreamHandle client = null;
            Exception    error  = null;

            try
            {
                if (status < 0)
                {
                    error = NativeMethods.CreateError((uv_err_code)status);
                }
                else
                {
                    client = server.NewStream();
                    NativeMethods.StreamAccept(server.InternalHandle, client.InternalHandle);
                }

                server.Accept(client, error);

                Log.Debug($"{server.GetType().Name} Connection accepted.");
            }
            catch (Exception exception)
            {
                Log.Error($"{nameof(StreamHandle)} Failed to accept client connection.", exception);
                client?.Dispose();
            }
        }
Exemple #3
0
        internal Pipeline(StreamHandle streamHandle)
        {
            Contract.Requires(streamHandle != null);

            this.streamHandle   = streamHandle;
            this.readBuffer     = new BufferBlock();
            this.writeTaskQueue = new WriteTaskQueue();
        }
Exemple #4
0
 void Accept(StreamHandle client, Exception error)
 {
     Contract.Requires(client != null);
     try
     {
         client.Pipeline.ReadAction = this.Pipeline.ReadAction;
         client.ReadStart();
         this.connectionHandler?.Invoke(client, error);
     }
     catch (Exception exception)
     {
         Log.Error($"{this.GetType().Name} connection handler invocation failed.", exception);
     }
 }