From 7c3a6b3991a9b57377087c18375f60d68512b17e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 31 Mar 2016 06:38:37 -0700 Subject: sock-set-peer shouldn't mark dgram sockets connected. Merely setting a peer doesn't actually connect the socket, so it must not be marked connected. If it is wrongly marked connected, then dgram_flush will wrongly use send rather than sendto. * socket.c (dgram_set_sock_peer): Don't set sock_connected flag. (sock_connect): Set the sock_connected flag here, for dgram sockets. --- socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/socket.c b/socket.c index 07286974..39c4d931 100644 --- a/socket.c +++ b/socket.c @@ -602,7 +602,6 @@ static val dgram_set_sock_peer(val stream, val peer) { struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle); sockaddr_pack(peer, d->family, &d->peer_addr, &d->pa_len); - d->sock_connected = 1; return set(mkloc(d->peer, stream), peer); } @@ -736,6 +735,11 @@ static val sock_connect(val sock, val sockaddr, val timeout) sock_set_peer(sock, sockaddr); + if (sock_type(sock) == num_fast(SOCK_DGRAM)) { + struct dgram_stream *d = coerce(struct dgram_stream *, sock->co.handle); + d->sock_connected = 1; + } + return sock; } -- cgit v1.2.3