public ResponsePacketHandler(ConnectionsController connection, int waitForResponseSleepTime)
 {
     if (null == connection)
     {
         throw new ArgumentNullException(nameof(connection));
     }
     _connection = connection;
     _waitForResponseSleepTime = waitForResponseSleepTime;
 }
Exemple #2
0
        /// <inheritdoc />
        public void Disconnect()
        {
            // sanity check
            ThrowIfDisposed();

            if (_connectionController != null && _connectionController.Client)
            {
                _connectionController.OnServerDisconnect -= OnServerDisconnect;
            }

            _connectionController?.DisConnect();
            _connectionController = null;
        }
Exemple #3
0
        /// <inheritdoc />
        public async Task <bool> ConnectAsync(SQLiteServerConnection connection)
        {
            // sanity check
            ThrowIfDisposed();

            // save the connection
            _connection = connection;

            // sanity check
            if (_connectionController?.Connected ?? false)
            {
                throw new SQLiteServerException("Already connected!");
            }

            _connectionController = new ConnectionsController(_address, _port, _backlog, _heartBeatTimeOutInMs);
            if (!_connectionController.Connect())
            {
                throw new SQLiteServerException("Unable to connected.");
            }

            // wait untl we are connected
            await Task.Run(async() =>
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                while (!_connectionController.Connected)
                {
                    // yield all the work.
                    await Task.Yield();

                    // check for delay
                    if (_heartBeatTimeOutInMs > 0 && watch.ElapsedMilliseconds >= _heartBeatTimeOutInMs)
                    {
                        // we timed out.
                        break;
                    }
                }
                watch.Stop();
            }).ConfigureAwait(false);

            if (!_connectionController.Connected)
            {
                throw new SQLiteServerException("Timmed out waiting for update.");
            }
            return(true);
        }