Avoid gratuitous mutation

This commit is contained in:
Tony Garnock-Jones 2012-03-06 17:29:44 -05:00
parent a7dded3b99
commit c9441e50da
1 changed files with 9 additions and 7 deletions

View File

@ -83,14 +83,16 @@ let deserialize_header buf =
(body_size, read_properties class_id buf) (body_size, read_properties class_id buf)
let send_content_body conn channel body = let send_content_body conn channel body =
let offset = ref 0 in
let len = String.length body in let len = String.length body in
while (!offset) < len do let rec send_remainder offset =
let snip_len = min conn.frame_max (len - !offset) in if offset >= len
Buffer.add_substring conn.output_buf body (!offset) snip_len; then ()
write_frame conn frame_body channel; else
offset := !offset + snip_len let snip_len = min conn.frame_max (len - offset) in
done Buffer.add_substring conn.output_buf body offset snip_len;
write_frame conn frame_body channel;
send_remainder (offset + snip_len)
in send_remainder 0
let next_frame conn required_type = let next_frame conn required_type =
let (frame_type, channel, length) = read_frame conn in let (frame_type, channel, length) = read_frame conn in