summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2019-03-28 11:11:18 +0000
committerratchov <ratchov@openbsd.org>2019-03-28 11:11:18 +0000
commit14d6d4a21eb7b3e96341ed261e326b8f09c8abc8 (patch)
treed85f96ca424093b196e801228b8e626b83eeb62e
parentEnable uxrcom(4). (diff)
downloadwireguard-openbsd-14d6d4a21eb7b3e96341ed261e326b8f09c8abc8.tar.xz
wireguard-openbsd-14d6d4a21eb7b3e96341ed261e326b8f09c8abc8.zip
Wait until server disconnects before closing the socket. Otherwise,
last bytes sent may be lost by the server.
-rw-r--r--lib/libsndio/aucat.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index 7a439e34e49..2edd216b615 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.73 2018/09/26 08:33:22 miko Exp $ */
+/* $OpenBSD: aucat.c,v 1.74 2019/03/28 11:11:18 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -512,7 +512,8 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode)
void
_aucat_close(struct aucat *hdl, int eof)
{
- char dummy[1];
+ char dummy[sizeof(struct amsg)];
+ ssize_t n;
if (!eof) {
AMSG_INIT(&hdl->wmsg);
@@ -520,8 +521,20 @@ _aucat_close(struct aucat *hdl, int eof)
hdl->wtodo = sizeof(struct amsg);
if (!_aucat_wmsg(hdl, &eof))
goto bad_close;
- while (read(hdl->fd, dummy, 1) < 0 && errno == EINTR)
- ; /* nothing */
+
+ /*
+ * block until the peer disconnects
+ */
+ while (1) {
+ n = read(hdl->fd, dummy, sizeof(dummy));
+ if (n < 0) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+ if (n == 0)
+ break;
+ }
}
bad_close:
while (close(hdl->fd) < 0 && errno == EINTR)