@@ -77,6 +77,7 @@ namespace ix
77
77
78
78
WebSocketTransport::WebSocketTransport ()
79
79
: _useMask(true )
80
+ , _blockingSend(false )
80
81
, _compressedMessage(false )
81
82
, _readyState(ReadyState::CLOSED)
82
83
, _closeCode(WebSocketCloseConstants::kInternalErrorCode )
@@ -178,6 +179,7 @@ namespace ix
178
179
179
180
// Server should not mask the data it sends to the client
180
181
_useMask = false ;
182
+ _blockingSend = true ;
181
183
182
184
_socket = socket;
183
185
@@ -339,22 +341,9 @@ namespace ix
339
341
// there can be a lot of it for large messages.
340
342
if (pollResult == PollResultType::SendRequest)
341
343
{
342
- while (!isSendBufferEmpty () && !_requestInitCancellation )
344
+ if (!flushSendBuffer () )
343
345
{
344
- // Wait with a 10ms timeout until the socket is ready to write.
345
- // This way we are not busy looping
346
- PollResultType result = _socket->isReadyToWrite (10 );
347
-
348
- if (result == PollResultType::Error)
349
- {
350
- closeSocket ();
351
- setReadyState (ReadyState::CLOSED);
352
- break ;
353
- }
354
- else if (result == PollResultType::ReadyForWrite)
355
- {
356
- sendOnSocket ();
357
- }
346
+ return PollResult::CannotFlushSendBuffer;
358
347
}
359
348
}
360
349
else if (pollResult == PollResultType::ReadyForRead)
@@ -924,13 +913,21 @@ namespace ix
924
913
}
925
914
}
926
915
916
+ bool success = true ;
917
+
927
918
// Request to flush the send buffer on the background thread if it isn't empty
928
919
if (!isSendBufferEmpty ())
929
920
{
930
921
_socket->wakeUpFromPoll (Socket::kSendRequest );
922
+
923
+ // FIXME: we should have a timeout when sending large messages: see #131
924
+ if (_blockingSend && !flushSendBuffer ())
925
+ {
926
+ success = false ;
927
+ }
931
928
}
932
929
933
- return WebSocketSendInfo (true , compressionError, payloadSize, wireSize);
930
+ return WebSocketSendInfo (success , compressionError, payloadSize, wireSize);
934
931
}
935
932
936
933
void WebSocketTransport::sendFragment (wsheader_type::opcode_type type,
@@ -1168,4 +1165,27 @@ namespace ix
1168
1165
return _txbuf.size ();
1169
1166
}
1170
1167
1168
+ bool WebSocketTransport::flushSendBuffer ()
1169
+ {
1170
+ while (!isSendBufferEmpty () && !_requestInitCancellation)
1171
+ {
1172
+ // Wait with a 10ms timeout until the socket is ready to write.
1173
+ // This way we are not busy looping
1174
+ PollResultType result = _socket->isReadyToWrite (10 );
1175
+
1176
+ if (result == PollResultType::Error)
1177
+ {
1178
+ closeSocket ();
1179
+ setReadyState (ReadyState::CLOSED);
1180
+ return false ;
1181
+ }
1182
+ else if (result == PollResultType::ReadyForWrite)
1183
+ {
1184
+ sendOnSocket ();
1185
+ }
1186
+ }
1187
+
1188
+ return true ;
1189
+ }
1190
+
1171
1191
} // namespace ix
0 commit comments