Skip to content

Commit 4400b97

Browse files
committed
async: flush output after writing frames
1 parent 3edc21a commit 4400b97

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

async/websocket_async.ml

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ let client ?(name = "websocket.client") ?(extra_headers = Header.init ())
9595
>>= fun () -> forward_frames_to_app ws_to_app
9696
in
9797
let forward_frames_to_net ws_to_net app_to_ws =
98-
Writer.transfer ws_to_net app_to_ws (fun fr ->
99-
Buffer.clear buf;
100-
write_frame_to_buf ~mode:(Client random_string) buf fr;
101-
let contents = Buffer.contents buf in
102-
Writer.write ws_to_net contents)
98+
Writer.transfer' ws_to_net app_to_ws (fun frs ->
99+
Queue.iter frs ~f:(fun fr ->
100+
Buffer.clear buf;
101+
write_frame_to_buf ~mode:(Client random_string) buf fr;
102+
let contents = Buffer.contents buf in
103+
Writer.write ws_to_net contents);
104+
Writer.flushed ws_to_net)
103105
in
104106
Deferred.any_unit
105107
[
@@ -350,7 +352,7 @@ let upgrade_connection ?(select_protocol = fun _ -> None)
350352
| true -> Deferred.unit
351353
| false ->
352354
Writer.write writer ping_frame_string;
353-
ping_loop ()
355+
Writer.flushed writer >>= fun () -> ping_loop ()
354356
in
355357
ping_loop ()
356358
in

0 commit comments

Comments
 (0)