From feb85af5ec767988ce6e5414e5cae1ebc15b0f74 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 14 Mar 2016 06:33:55 -0700 Subject: All stdio streams get line buffering with i mode. * socket.c (open_sockfd): We no longer need to set stream sockets to line buffered mode here; it's done in set_mode_props. * stream.c (set_mode_props): If the mode specifies interactive, streams open for writing are also switched to line buffering. * txr.1: Documented under open-file, and open-socket. --- socket.c | 1 - stream.c | 7 ++++++- txr.1 | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/socket.c b/socket.c index ae07c816..17949a7c 100644 --- a/socket.c +++ b/socket.c @@ -829,7 +829,6 @@ val open_sockfd(val fd, val family, val type, val mode_str_in) fd, num(errno), string_utf8(strerror(errno)), nao); } - setvbuf(f, (char *) NULL, _IOLBF, 0); return set_mode_props(m, make_sock_stream(f, family, type)); } } diff --git a/stream.c b/stream.c index a3d60863..b98d7948 100644 --- a/stream.c +++ b/stream.c @@ -1236,8 +1236,13 @@ val normalize_mode(struct stdio_mode *m, val mode_str) val set_mode_props(const struct stdio_mode m, val stream) { - if (m.interactive) + if (m.interactive) { + struct stdio_handle *h = coerce(struct stdio_handle *, + cobj_handle(stream, stdio_stream_s)); + if (h->f && m.write) + setvbuf(h->f, (char *) NULL, _IOLBF, 0); stream_set_prop(stream, real_time_k, t); + } return stream; } diff --git a/txr.1 b/txr.1 index a09f1abe..0953ae26 100644 --- a/txr.1 +++ b/txr.1 @@ -34398,7 +34398,14 @@ is used. The option letter .str i is supported. If present, it will create a stream which has the real-time -property set. +property set. For a description of the semantics, see the +.code real-time-stream-p +function. Briefly, this property affects the semantics of lazy lists which draw +input from the stream. +In addition, for a stream opened for writing or reading and writing, the +.str i +mode letter specifies that the stream will be line-buffered. This means that an +implicit flush operation takes place whenever the newline character is output. .coNP Function @ open-tail .synb @@ -37780,9 +37787,13 @@ data flow, the default mode string is rather than the usual .strn r . -Stream sockets are created line-buffered. Therefore, programs which communicate -using textual, line-oriented protocols over sockets need not execute flush operations -after each line. +Like other stream times, stream sockets are buffered and marked as no +non-real-time streams. Specifying the +.str i +mode in +.metn mode-string +marks a socket as a real-time-stream, and, if it is opened for writing +or reading and writing, changes it to use line buffering. .coNP Functions @ sock-family and @ sock-type .synb -- cgit v1.2.3