Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2502,3 +2502,7 @@ Version 1.8.4, in progress
builtin functions can now cause other kinds of aborts
-- added caching regime for server options other than
.protect_<function>

Version X, in progress
**** Changes relevant to programmers / wizards:
-- Setting binary mode immediately flushes the connection's buffer, if any
44 changes: 36 additions & 8 deletions net_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,32 @@ pull_input(nhandle * h)
for (ptr = buffer, end = buffer + count; ptr < end; ptr++) {
unsigned char c = *ptr;

if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(s, c);
if (c == '\r' || (c == '\n' && !h->last_input_was_CR)) {
int fcount = stream_length(s);
char *fptr = reset_stream(s);
Stream *fs = new_stream(count + 1);
int i;

h->last_input_was_CR = (c == '\r');
for (i = 0; i < fcount; ++i) {
c = fptr[i];

if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(fs, c);
#ifdef INPUT_APPLY_BACKSPACE
else if (c == 0x08 || c == 0x7F)
stream_delete_char(s);
else if (c == 0x08 || c == 0x7F)
stream_delete_char(fs);
#endif
else if (c == '\r' || (c == '\n' && !h->last_input_was_CR))
server_receive_line(h->shandle, reset_stream(s));

h->last_input_was_CR = (c == '\r');
}
server_receive_line(h->shandle, stream_contents(fs));
free_stream(fs);
}
else if (c == '\n')
h->last_input_was_CR = 0;
else {
stream_add_char(s, c);
h->last_input_was_CR = 0;
}
}
}
return 1;
Expand Down Expand Up @@ -620,6 +636,18 @@ network_set_connection_binary(network_handle nh, int do_binary)
nhandle *h = nh.ptr;

h->binary = do_binary;

if (do_binary) {
int count = stream_length(h->input);

if (count) {
Stream *s = new_stream(count + 1);
stream_add_raw_bytes_to_binary(s, reset_stream(h->input), count);
server_receive_line(h->shandle, stream_contents(s));
h->last_input_was_CR = 0;
free_stream(s);
}
}
}

#if NETWORK_PROTOCOL == NP_LOCAL
Expand Down
41 changes: 33 additions & 8 deletions net_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ static enum {
} state = STATE_CLOSED;
static int listening = 0;
static server_listener slistener;
static server_handle sh;
static int binary = 0;
static Stream *input = 0;

const char *
network_protocol_name(void)
Expand Down Expand Up @@ -114,6 +116,17 @@ void
network_set_connection_binary(network_handle nh, int do_binary)
{
binary = do_binary;

if (do_binary) {
int count = stream_length(input);

if (count) {
Stream *s = new_stream(count + 1);
stream_add_raw_bytes_to_binary(s, reset_stream(input), count);
server_receive_line(sh, stream_contents(s));
free_stream(s);
}
}
}

#define NETWORK_CO_TABLE(DEFINE, nh, value, _)
Expand Down Expand Up @@ -160,8 +173,7 @@ int
network_process_io(int timeout)
{
network_handle nh;
static server_handle sh;
static Stream *s = 0;
Stream *s = input;
char buffer[1024];
int count;
char *ptr, *end;
Expand Down Expand Up @@ -202,14 +214,27 @@ network_process_io(int timeout)
ptr++) {
unsigned char c = *ptr;

if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(s, c);
if (c == '\n') {
int fcount = stream_length(s);
char *fptr = reset_stream(s);
Stream *fs = new_stream(count + 1);
int i;

for (i = 0; i < fcount; ++i) {
c = fptr[i];

if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(fs, c);
#ifdef INPUT_APPLY_BACKSPACE
else if (c == 0x08 || c == 0x7F)
stream_delete_char(s);
else if (c == 0x08 || c == 0x7F)
stream_delete_char(fs);
#endif
else if (c == '\n')
server_receive_line(sh, reset_stream(s));
}
server_receive_line(sh, stream_contents(fs));
free_stream(fs);
}
else
stream_add_char(s, c);
}
}

Expand Down