Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions runtime/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ function caml_ml_flush (chanid) {
//Requires: caml_ml_flush,caml_ml_bytes_length
//Requires: caml_create_bytes, caml_blit_bytes, caml_raise_sys_error, caml_ml_channels, caml_string_of_bytes
//Requires: caml_jsbytes_of_string
var MAX_LENGTH = 65536;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where should I place this? At the top of the file and rename it to MAX_BUFFER_LENGTH?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only going to be used here. Just put it inside the funciton.

function caml_ml_output_bytes(chanid,buffer,offset,len) {
var chan = caml_ml_channels[chanid];
if(! chan.opened) caml_raise_sys_error("Cannot output to a closed channel");
Expand All @@ -379,12 +380,16 @@ function caml_ml_output_bytes(chanid,buffer,offset,len) {
var string = caml_string_of_bytes(bytes);
var jsstring = caml_jsbytes_of_string(string);
var id = jsstring.lastIndexOf("\n");
if(id < 0)
var total_length = jsstring.length + chan.buffer.length;
if (total_length > MAX_LENGTH) {
chan.buffer+=jsstring;
else {
caml_ml_flush (chanid);
} else if(id >= 0) {
chan.buffer+=jsstring.substr(0,id+1);
caml_ml_flush (chanid);
chan.buffer += jsstring.substr(id+1);
} else {
chan.buffer+=jsstring;
}
return 0;
}
Expand Down