summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2009-08-28 06:37:06 +0000
committerratchov <ratchov@openbsd.org>2009-08-28 06:37:06 +0000
commit2eb6711f96a714d8bdb5fdb37512584acb59c8d7 (patch)
treec4ee78c6347dd55692d687acb4b04f444d466876
parenttop device before closing it. It's necessary to ensure that if we (diff)
downloadwireguard-openbsd-2eb6711f96a714d8bdb5fdb37512584acb59c8d7.tar.xz
wireguard-openbsd-2eb6711f96a714d8bdb5fdb37512584acb59c8d7.zip
add a new AMSG_BYE, sent by the client to requst the server to
free resources and drop the connection. This allows the client to ensuire that at any time it's using only one connection, thus only one MIDI control channel.
-rw-r--r--lib/libsndio/aucat.c8
-rw-r--r--lib/libsndio/sndio.c6
-rw-r--r--usr.bin/aucat/amsg.h3
-rw-r--r--usr.bin/aucat/sock.c8
4 files changed, 21 insertions, 4 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index e7be5694107..4a9919825a2 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.25 2009/08/26 05:33:01 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.26 2009/08/28 06:37:06 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -271,6 +271,12 @@ aucat_close(struct sio_hdl *sh)
{
struct aucat_hdl *hdl = (struct aucat_hdl *)sh;
+ if (!hdl->sio.eof) {
+ AMSG_INIT(&hdl->wmsg);
+ hdl->wmsg.cmd = AMSG_BYE;
+ hdl->wtodo = sizeof(struct amsg);
+ (void)aucat_wmsg(hdl);
+ }
while (close(hdl->fd) < 0 && errno == EINTR)
; /* nothing */
free(hdl);
diff --git a/lib/libsndio/sndio.c b/lib/libsndio/sndio.c
index 96b21732acf..23127bb722e 100644
--- a/lib/libsndio/sndio.c
+++ b/lib/libsndio/sndio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio.c,v 1.21 2009/07/27 06:30:34 ratchov Exp $ */
+/* $OpenBSD: sndio.c,v 1.22 2009/08/28 06:37:06 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -237,6 +237,10 @@ sio_create(struct sio_hdl *hdl, struct sio_ops *ops, unsigned mode, int nbio)
void
sio_close(struct sio_hdl *hdl)
{
+ if (!hdl->eof && hdl->started) {
+ DPRINTF("sio_close: not stopped\n");
+ hdl->eof = 1;
+ }
hdl->ops->close(hdl);
}
diff --git a/usr.bin/aucat/amsg.h b/usr.bin/aucat/amsg.h
index f0563e9019a..7536f99c7b9 100644
--- a/usr.bin/aucat/amsg.h
+++ b/usr.bin/aucat/amsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amsg.h,v 1.9 2009/07/25 10:52:18 ratchov Exp $ */
+/* $OpenBSD: amsg.h,v 1.10 2009/08/28 06:37:06 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -39,6 +39,7 @@ struct amsg {
#define AMSG_GETCAP 7 /* get capabilities */
#define AMSG_SETVOL 8 /* set volume */
#define AMSG_HELLO 9 /* say hello, check versions and so ... */
+#define AMSG_BYE 10 /* ask server to drop connection */
uint32_t cmd;
uint32_t __pad;
union {
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index 2c0e0705366..d79ec01f04d 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.27 2009/08/27 06:54:23 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.28 2009/08/28 06:37:06 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -947,6 +947,12 @@ sock_execmsg(struct sock *f)
f->rstate = SOCK_RRET;
f->rtodo = sizeof(struct amsg);
break;
+ case AMSG_BYE:
+ DPRINTFN(2, "sock_execmsg: %p: BYE\n", f);
+ if (f->pstate != SOCK_INIT)
+ DPRINTF("sock_execmsg: %p: BYE, bad state\n", f);
+ aproc_del(f->pipe.file.rproc);
+ return 0;
default:
DPRINTF("sock_execmsg: %p bogus command\n", f);
aproc_del(f->pipe.file.rproc);