Example #1
0
 private void OnStarted()
 {
     executor.Enqueue(() =>
     {
         this.started.OnNext(Unit.Default);
         this.started.OnCompleted();
     });
 }
Example #2
0
        public void Stop()
        {
            server.Stop();
            executor.Enqueue(() =>
            {
                isStopped = true;
                pingTimer.Change(Timeout.Infinite, Timeout.Infinite);

                foreach (var client in clients)
                {
                    client.Close();
                }
            });
        }
Example #3
0
        /// <summary>
        /// Connects to a given remote end point. This method returns before
        /// socket is connected, observe Connected property to discover
        /// if actual connection was successfull or not.
        /// </summary>
        public IObservable <Unit> Connect(IPEndPoint remoteEndPoint)
        {
            if (this.wasConnected)
            {
                throw new InvalidOperationException("Socket was already in connected state");
            }
            this.wasConnected = true;

            executor.Enqueue(() =>
            {
                connectArgs                = new SocketAsyncEventArgs();
                connectArgs.Completed     += ConnectedCapture;
                connectArgs.RemoteEndPoint = remoteEndPoint;

                bool isPending = this.socket.ConnectAsync(connectArgs);

                if (!isPending)
                {
                    ConnectedCapture(this, this.connectArgs);
                }
                else
                {
                    connectionInProgress = true;
                    connectionTimeoutTimer.Change(20000, -1);
                }
            });

            return(Connected);
        }
Example #4
0
        public SocketClient(IExecutor executor, Socket socket)
        {
            this.connectedTcs = new TaskCompletionSource<int>();
            this.executor = executor;
            this.socket = socket;
            this.wasConnected = true;

            EnsureSocketIsConnected();

            InitialiseConnectedSocket();
            executor.Enqueue(StartReceiving);
        }
Example #5
0
        internal static Task <T> PostTask <T>(IExecutor exec, Func <T> func)
        {
            var tcs = new TaskCompletionSource <T>();

            exec.Enqueue(() =>
            {
                try
                {
                    tcs.SetResult(func());
                }
                catch (Exception exc)
                {
                    tcs.SetException(exc);
                }
            });

            return(tcs.Task);
        }
Example #6
0
        internal static Task <System.Reactive.Unit> PostTask(IExecutor exec, Action action)
        {
            //Not reusing <T> implementation, so additional lambda allocation can be ommited
            var tcs = new TaskCompletionSource <System.Reactive.Unit>();

            exec.Enqueue(() =>
            {
                try
                {
                    if (action != null)
                    {
                        action();
                    }
                    tcs.SetResult(System.Reactive.Unit.Default);
                }
                catch (Exception exc)
                {
                    tcs.SetException(exc);
                }
            });

            return(tcs.Task);
        }
Example #7
0
 public void Post(Action action)
 {
     executor.Enqueue(action);
 }