Skip to content

Commit 84f7060

Browse files
committed
Null checks
1 parent 7e66bb6 commit 84f7060

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Parse/Infrastructure/Execution/TextWebSocketClient.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public async Task OpenAsync(string serverUri, CancellationToken cancellationToke
7575
/// A task representing the asynchronous operation of closing the WebSocket connection.
7676
/// </returns>
7777
public async Task CloseAsync(CancellationToken cancellationToken = default) =>
78-
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, String.Empty, cancellationToken);
78+
await webSocket?.CloseAsync(WebSocketCloseStatus.NormalClosure, String.Empty, cancellationToken)!;
7979

8080
private async Task ListenForMessages(CancellationToken cancellationToken)
8181
{
@@ -96,9 +96,26 @@ private async Task ListenForMessages(CancellationToken cancellationToken)
9696
break;
9797
}
9898

99-
string message = Encoding.UTF8.GetString(buffer, 0, result.Count);
100-
Debug.WriteLine($"Received message: {message}");
101-
MessageReceived?.Invoke(this, message);
99+
if (result.EndOfMessage)
100+
{
101+
string message = Encoding.UTF8.GetString(buffer, 0, result.Count);
102+
MessageReceived?.Invoke(this, message);
103+
}
104+
else
105+
{
106+
// Handle partial messages by accumulating data until EndOfMessage is true
107+
StringBuilder messageBuilder = new StringBuilder();
108+
messageBuilder.Append(Encoding.UTF8.GetString(buffer, 0, result.Count));
109+
while (!result.EndOfMessage)
110+
{
111+
result = await webSocket.ReceiveAsync(
112+
new ArraySegment<byte>(buffer),
113+
cancellationToken);
114+
messageBuilder.Append(Encoding.UTF8.GetString(buffer, 0, result.Count));
115+
}
116+
string fullMessage = messageBuilder.ToString();
117+
MessageReceived?.Invoke(this, fullMessage);
118+
}
102119
}
103120
}
104121
catch (OperationCanceledException ex)
@@ -148,7 +165,6 @@ private void StartListening(CancellationToken cancellationToken)
148165
if (!task.IsFaulted)
149166
return;
150167
Debug.WriteLine($"Websocket listener task faulted: {task.Exception}");
151-
throw task.Exception;
152168
}, TaskContinuationOptions.OnlyOnFaulted);
153169
}
154170

Parse/Platform/LiveQueries/ParseLiveQuery.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class ParseLiveQuery<T> where T : ParseObject
3838

3939
internal ParseLiveQuery(IServiceHub serviceHub, string className, IDictionary<string, object> filters, IEnumerable<string> selectedKeys = null, IEnumerable<string> watchedKeys = null)
4040
{
41+
ArgumentNullException.ThrowIfNull(serviceHub);
42+
ArgumentException.ThrowIfNullOrWhiteSpace(className);
4143
ArgumentNullException.ThrowIfNull(filters);
4244

4345
Services = serviceHub;

0 commit comments

Comments
 (0)