Skip to content

Commit 6e40a4d

Browse files
minor fixes
1 parent 81d7857 commit 6e40a4d

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

src/tarantool.client/LogicalConnection.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,25 @@ private async Task<TResponse> SendRequestImpl<TRequest, TResponse>(TRequest requ
154154

155155
try
156156
{
157-
try
158-
{
159-
_physicalConnectionLock.EnterWriteLock();
157+
_physicalConnectionLock.EnterWriteLock();
160158

161-
_logWriter?.WriteLine($"Begin sending request header buffer, requestId: {requestId}, code: {request.Code}, length: {headerBuffer.Length}");
162-
_physicalConnection.Write(headerBuffer, 0, Constants.PacketSizeBufferSize + (int)headerLength);
159+
_logWriter?.WriteLine($"Begin sending request header buffer, requestId: {requestId}, code: {request.Code}, length: {headerBuffer.Length}");
160+
_physicalConnection.Write(headerBuffer, 0, Constants.PacketSizeBufferSize + (int)headerLength);
163161

164-
_logWriter?.WriteLine($"Begin sending request body buffer, length: {bodyBuffer.Length}");
165-
_physicalConnection.Write(bodyBuffer, 0, bodyBuffer.Length);
166-
}
167-
finally
168-
{
169-
_physicalConnectionLock.ExitWriteLock();
170-
}
162+
_logWriter?.WriteLine($"Begin sending request body buffer, length: {bodyBuffer.Length}");
163+
_physicalConnection.Write(bodyBuffer, 0, bodyBuffer.Length);
171164
}
172165
catch (Exception ex)
173166
{
174-
_logWriter?.WriteLine($"Request with requestId {requestId} failed, header:\n{ToReadableString(headerBuffer)} \n body: \n{ToReadableString(bodyBuffer)}");
167+
_logWriter?.WriteLine(
168+
$"Request with requestId {requestId} failed, header:\n{ToReadableString(headerBuffer)} \n body: \n{ToReadableString(bodyBuffer)}");
175169
Dispose();
176170
throw;
177171
}
172+
finally
173+
{
174+
_physicalConnectionLock.ExitWriteLock();
175+
}
178176

179177
try
180178
{

src/tarantool.client/LogicalConnectionManager.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ public async Task Connect()
6363

6464
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Connected...");
6565

66-
if (_clientOptions.ConnectionOptions.PingCheckInterval > 0)
66+
if (_clientOptions.ConnectionOptions.PingCheckInterval >= 0)
6767
{
6868
_pingCheckInterval = _clientOptions.ConnectionOptions.PingCheckInterval;
6969
}
7070

71-
_timer = new Timer(x => CheckPing(), null, _pingTimerInterval, Timeout.Infinite);
71+
if (_pingCheckInterval > 0)
72+
{
73+
_timer = new Timer(x => CheckPing(), null, _pingTimerInterval, Timeout.Infinite);
74+
}
7275
}
7376

7477
private static readonly PingRequest _pingRequest = new PingRequest();
@@ -135,19 +138,32 @@ private async Task EnsureConnection()
135138
}
136139
}
137140

141+
private void ScheduleNextPing()
142+
{
143+
if (_pingCheckInterval > 0)
144+
{
145+
_nextPingTime = DateTimeOffset.UtcNow.AddMilliseconds(_pingCheckInterval);
146+
}
147+
}
148+
138149
public async Task<DataResponse<TResponse[]>> SendRequest<TRequest, TResponse>(TRequest request) where TRequest : IRequest
139150
{
140151
await EnsureConnection();
152+
141153
var result = await _droppableLogicalConnection.SendRequest<TRequest, TResponse>(request);
142-
_nextPingTime = DateTimeOffset.UtcNow.AddMilliseconds(_pingCheckInterval);
154+
155+
ScheduleNextPing();
156+
143157
return result;
144158
}
145159

146160
public async Task SendRequestWithEmptyResponse<TRequest>(TRequest request) where TRequest : IRequest
147161
{
148162
await EnsureConnection();
163+
149164
await _droppableLogicalConnection.SendRequestWithEmptyResponse(request);
150-
_nextPingTime = DateTimeOffset.UtcNow.AddMilliseconds(_pingCheckInterval);
165+
166+
ScheduleNextPing();
151167
}
152168
}
153169
}

src/tarantool.client/ResponseReader.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,26 @@ public void BeginReading()
106106

107107
private void EndReading(Task<int> readWork)
108108
{
109-
if (!_disposed)
109+
if (_disposed)
110110
{
111-
if (readWork.Status == TaskStatus.RanToCompletion)
112-
{
113-
var readBytesCount = readWork.Result;
114-
_clientOptions.LogWriter?.WriteLine($"End reading from connection, read bytes count: {readBytesCount}");
115-
116-
if (ProcessReadBytes(readBytesCount))
117-
{
118-
BeginReading();
119-
return;
120-
}
121-
}
122-
123-
_clientOptions.LogWriter?.WriteLine($"Connection read failed: {readWork.Exception}");
124-
Dispose();
111+
_clientOptions.LogWriter?.WriteLine("Attempt to end reading in disposed state... Exiting.");
112+
return;
125113
}
126-
else
114+
115+
if (readWork.Status == TaskStatus.RanToCompletion)
127116
{
128-
_clientOptions.LogWriter?.WriteLine("Attempt to end reading in disposed state... Exiting.");
117+
var readBytesCount = readWork.Result;
118+
_clientOptions.LogWriter?.WriteLine($"End reading from connection, read bytes count: {readBytesCount}");
119+
120+
if (ProcessReadBytes(readBytesCount))
121+
{
122+
BeginReading();
123+
return;
124+
}
129125
}
126+
127+
_clientOptions.LogWriter?.WriteLine($"Connection read failed: {readWork.Exception}");
128+
Dispose();
130129
}
131130

132131
private bool ProcessReadBytes(int readBytesCount)

0 commit comments

Comments
 (0)