private IBoltProtocol SelectBoltProtocol(BoltProtocolVersion version, IDictionary <string, string> routingContext) { var boltProtocol = BoltProtocolFactory.ForVersion(version, routingContext); Reader = boltProtocol.NewReader(_tcpSocketClient.ReadStream, _bufferSettings, _logger); Writer = boltProtocol.NewWriter(_tcpSocketClient.WriteStream, _bufferSettings, _logger); return(boltProtocol); }
private IBoltProtocol SelectBoltProtocol(int version) { var boltProtocol = BoltProtocolFactory.ForVersion(version); Reader = boltProtocol.NewReader(_tcpSocketClient.ReadStream, _bufferSettings, _logger); Writer = boltProtocol.NewWriter(_tcpSocketClient.WriteStream, _bufferSettings, _logger); return(boltProtocol); }
public void Start() { _connMetricsListener?.ConnectionConnecting(_connEvent); _tcpSocketClient.Connect(_uri); SetOpened(); _logger?.Debug($"~~ [CONNECT] {_uri}"); _connMetricsListener?.ConnectionConnected(_connEvent); var version = DoHandshake(); _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger); }
public Task StartAsync() { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); _connMetricsListener?.ConnectionConnecting(_connEvent); _tcpSocketClient.ConnectAsync(_uri) .ContinueWith(t => { if (t.IsFaulted) { tcs.SetException(t.Exception.GetBaseException()); } else if (t.IsCanceled) { tcs.SetCanceled(); } else { SetOpened(); _logger?.Debug($"~~ [CONNECT] {_uri}"); _connMetricsListener?.ConnectionConnected(_connEvent); return(DoHandshakeAsync()); } return(Task.FromResult(-1)); }, TaskContinuationOptions.ExecuteSynchronously).Unwrap() .ContinueWith(t => { int version = t.Result; if (version != -1) { try { _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger); tcs.SetResult(null); } catch (AggregateException exc) { tcs.SetException(exc.GetBaseException()); } catch (Exception exc) { tcs.SetException(exc); } } }, TaskContinuationOptions.ExecuteSynchronously); return(tcs.Task); }
private int DoHandshake() { var data = BoltProtocolFactory.PackSupportedVersions(); _tcpSocketClient.WriteStream.Write(data, 0, data.Length); _tcpSocketClient.WriteStream.Flush(); _logger?.Debug("C: [HANDSHAKE] ", data); data = new byte[4]; _tcpSocketClient.ReadStream.Read(data, 0, data.Length); var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data); _logger?.Debug($"S: [HANDSHAKE] {agreedVersion}"); return(agreedVersion); }
private async Task <int> DoHandshakeAsync() { var data = BoltProtocolFactory.PackSupportedVersions(); await _tcpSocketClient.WriteStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); await _tcpSocketClient.WriteStream.FlushAsync().ConfigureAwait(false); _logger?.Debug("C: [HANDSHAKE] ", data); data = new byte[4]; await _tcpSocketClient.ReadStream.ReadAsync(data, 0, data.Length).ConfigureAwait(false); var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data); _logger?.Debug($"S: [HANDSHAKE] {agreedVersion}"); return(agreedVersion); }
private async Task <BoltProtocolVersion> DoHandshakeAsync() { var data = BoltProtocolFactory.PackSupportedVersions(NumSupportedVersions); await _tcpSocketClient.WriteStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); await _tcpSocketClient.WriteStream.FlushAsync().ConfigureAwait(false); _logger?.Debug("C: [HANDSHAKE] {0}", data.ToHexString()); data = new byte[4]; var read = await _tcpSocketClient.ReadStream.ReadAsync(data, 0, data.Length).ConfigureAwait(false); if (read < data.Length) { throw new IOException($"Unexpected end of stream when performing handshake, read returned {read}"); } var agreedVersion = BoltProtocolFactory.UnpackAgreedVersion(data); _logger?.Debug("S: [HANDSHAKE] {0}.{1}", agreedVersion.MajorVersion, agreedVersion.MinorVersion); return(agreedVersion); }