From 54ab368d20df1796106e2dae222a3b926c331dd9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Mar 2016 06:45:20 -0700 Subject: Sockets are r+b by default, not r+. * socket.c (open_sockfd): Default mode string is "r+b". * txr.1: Documented. --- socket.c | 2 +- txr.1 | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/socket.c b/socket.c index 2ea639fe..4e596a90 100644 --- a/socket.c +++ b/socket.c @@ -943,7 +943,7 @@ val open_sockfd(val fd, val family, val type, val mode_str_in) return make_dgram_sock_stream(c_num(fd), family, nil, 0, 0, 0, 0); } else { struct stdio_mode m; - val mode_str = default_arg(mode_str_in, lit("r+")); + val mode_str = default_arg(mode_str_in, lit("r+b")); FILE *f = (errno = 0, w_fdopen(c_num(fd), c_str(normalize_mode(&m, mode_str)))); if (!f) { diff --git a/txr.1 b/txr.1 index 8dcc2c6b..8c3ea260 100644 --- a/txr.1 +++ b/txr.1 @@ -37845,10 +37845,19 @@ argument is different under .code open-socket from other functions. Because sockets are almost always used for bidirectional data flow, the default mode string is -.str r+ +.str r+b rather than the usual .strn r . +Rationale for including the +.str b +flag in the default mode string is that network protocols are usually defined +in a way that is independent of machine and operating system, down to the byte +level, even when they are textual. It doesn't make sense for the same \*(TX +program to see a network stream differently based on what platform it is +running on. Line ending conversion has to do with how a platform locally stores +text files, whereas network streams are almost always external formats. + Like other stream times, stream sockets are buffered and marked as no non-real-time streams. Specifying the .str i -- cgit v1.2.3