unbreak midi

This commit is contained in:
Alexandre Ratchov 2011-04-19 01:52:03 +02:00
parent 787883791f
commit 369b2b9faf
4 changed files with 18 additions and 29 deletions

View File

@ -31,7 +31,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "sndio.h"
#include "aucat.h"
#include "debug.h"
@ -288,7 +287,7 @@ bad_gen:
}
int
aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, unsigned mode)
aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, int isaudio)
{
int s, error;
struct addrinfo *ailist, *ai, aihints;
@ -299,14 +298,10 @@ aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, unsigned mode)
DPRINTF("%s: bad unit number\n", unit);
return 0;
}
if (mode & (MIO_IN | MIO_OUT)) {
port += MIDICAT_PORT;
} else if (mode & (SIO_PLAY | SIO_REC)) {
if (isaudio)
port += AUCAT_PORT;
} else {
DPRINTF("aucat_connect_tcp: unknown mode\n");
abort();
}
else
port += MIDICAT_PORT;
snprintf(serv, sizeof(serv), "%u", port);
memset(&aihints, 0, sizeof(struct addrinfo));
aihints.ai_socktype = SOCK_STREAM;
@ -326,6 +321,7 @@ aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, unsigned mode)
if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) {
DPERROR("connect");
close(s);
s = -1;
continue;
}
break;
@ -338,7 +334,7 @@ aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, unsigned mode)
}
int
aucat_connect_un(struct aucat *hdl, char *unit, unsigned mode)
aucat_connect_un(struct aucat *hdl, char *unit, int isaudio)
{
struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un);
@ -346,15 +342,8 @@ aucat_connect_un(struct aucat *hdl, char *unit, unsigned mode)
uid_t uid;
int s;
if (mode & (MIO_IN | MIO_OUT)) {
sock = MIDICAT_PATH;
} else if (mode & (SIO_PLAY | SIO_REC)) {
sock = AUCAT_PATH;
} else {
DPRINTF("aucat_connect_un: unknown mode\n");
abort();
}
uid = geteuid();
sock = isaudio ? AUCAT_PATH : MIDICAT_PATH;
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat-%u/%s%s", uid, sock, unit);
ca.sun_family = AF_UNIX;
@ -364,14 +353,14 @@ aucat_connect_un(struct aucat *hdl, char *unit, unsigned mode)
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
DPERROR("aucat_init: connect");
DPERROR(ca.sun_path);
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat/%s%s", sock, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
DPERROR("aucat_init: connect");
DPERROR(ca.sun_path);
close(s);
return 0;
}
@ -382,7 +371,7 @@ aucat_connect_un(struct aucat *hdl, char *unit, unsigned mode)
}
int
aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nbio)
aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
{
extern char *__progname;
int eof, hashost;
@ -416,10 +405,10 @@ aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nb
}
DPRINTF("aucat_init: trying %s -> %s.%s\n", str, unit, opt);
if (hashost) {
if (!aucat_connect_tcp(hdl, host, unit, mode))
if (!aucat_connect_tcp(hdl, host, unit, isaudio))
return 0;
} else {
if (!aucat_connect_un(hdl, unit, mode))
if (!aucat_connect_un(hdl, unit, isaudio))
return 0;
}
if (fcntl(hdl->fd, F_SETFD, FD_CLOEXEC) < 0) {

View File

@ -20,7 +20,7 @@ int aucat_rmsg(struct aucat *, int *);
int aucat_wmsg(struct aucat *, int *);
size_t aucat_rdata(struct aucat *, void *, size_t, int *);
size_t aucat_wdata(struct aucat *, const void *, size_t, unsigned, int *);
int aucat_open(struct aucat *, const char *, char *, unsigned, int);
int aucat_open(struct aucat *, const char *, unsigned, int);
void aucat_close(struct aucat *, int);
int aucat_pollfd(struct aucat *, struct pollfd *, int);
int aucat_revents(struct aucat *, struct pollfd *);

View File

@ -55,14 +55,14 @@ static struct mio_ops mio_aucat_ops = {
};
static struct mio_hdl *
mio_xxx_open(const char *str, char *sock, unsigned mode, int nbio)
mio_xxx_open(const char *str, unsigned mode, int nbio, int isaudio)
{
struct mio_aucat_hdl *hdl;
hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == NULL)
return NULL;
if (!aucat_open(&hdl->aucat, str, sock, mode, nbio))
if (!aucat_open(&hdl->aucat, str, mode, isaudio))
goto bad;
mio_create(&hdl->mio, &mio_aucat_ops, mode, nbio);
if (!aucat_setfl(&hdl->aucat, nbio, &hdl->mio.eof))
@ -76,13 +76,13 @@ bad:
struct mio_hdl *
mio_midithru_open(const char *str, unsigned mode, int nbio)
{
return mio_xxx_open(str, MIDICAT_PATH, mode, nbio);
return mio_xxx_open(str, mode, nbio, 0);
}
struct mio_hdl *
mio_aucat_open(const char *str, unsigned mode, int nbio)
{
return mio_xxx_open(str, AUCAT_PATH, mode, nbio);
return mio_xxx_open(str, mode, nbio, 1);
}
static void

View File

@ -149,7 +149,7 @@ sio_aucat_open(const char *str, unsigned mode, int nbio)
hdl = malloc(sizeof(struct sio_aucat_hdl));
if (hdl == NULL)
return NULL;
if (!aucat_open(&hdl->aucat, str, AUCAT_PATH, mode, nbio)) {
if (!aucat_open(&hdl->aucat, str, mode, 1)) {
free(hdl);
return NULL;
}