summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--socket.c22
-rw-r--r--stream.h2
2 files changed, 20 insertions, 4 deletions
diff --git a/socket.c b/socket.c
index e9fccae0..c40f01ef 100644
--- a/socket.c
+++ b/socket.c
@@ -70,6 +70,7 @@ struct dgram_stream {
int rx_max, rx_size, rx_pos;
int tx_pos;
unsigned is_connected : 1;
+ unsigned is_byte_oriented : 1;
};
val sockaddr_in_s, sockaddr_in6_s, sockaddr_un_s, addrinfo_s;
@@ -444,8 +445,17 @@ static val dgram_get_char(val stream)
if (d->unget_c) {
return rcyc_pop(&d->unget_c);
} else {
- wint_t ch = utf8_decode(&d->ud, dgram_get_byte_callback,
- coerce(mem_t *, d));
+ wint_t ch;
+
+ if (d->is_byte_oriented) {
+ ch = dgram_get_byte_callback(coerce(mem_t *, d));
+ if (ch == 0)
+ ch = 0xDC00;
+ } else {
+ ch = utf8_decode(&d->ud, dgram_get_byte_callback,
+ coerce(mem_t *, d));
+ }
+
return (ch != WEOF) ? chr(ch) : nil;
}
}
@@ -543,6 +553,8 @@ static val dgram_get_prop(val stream, val ind)
return format(nil, lit("connected ~s"), d->peer, nao);
return lit("disconnected");
+ } else if (ind == byte_oriented_k) {
+ return d->is_byte_oriented ? t : nil;
}
return nil;
@@ -550,10 +562,14 @@ static val dgram_get_prop(val stream, val ind)
static val dgram_set_prop(val stream, val ind, val prop)
{
+ struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle);
+
if (ind == addr_k) {
- struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle);
set(mkloc(d->addr, stream), prop);
return t;
+ } else if (ind == byte_oriented_k) {
+ d->is_byte_oriented = prop ? 1 : 0;
+ return t;
}
return nil;
diff --git a/stream.h b/stream.h
index db054730..786af45d 100644
--- a/stream.h
+++ b/stream.h
@@ -107,7 +107,7 @@ struct stdio_mode {
loc lookup_var_l(val env, val sym);
extern val from_start_k, from_current_k, from_end_k;
-extern val real_time_k, name_k, addr_k, fd_k;
+extern val real_time_k, name_k, addr_k, fd_k, byte_oriented_k;
extern val format_s;
extern val stdio_stream_s;