diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-09-05 14:27:18 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-09-05 14:27:18 +0000 |
commit | c4e21c814832ea94f64821a2360a28074d03be1a (patch) | |
tree | 5e0292327179920ca4b7dbc39d4539168a1f3b56 /audio | |
parent | 5e4e6d23323b869b36fb02d815dd4b928f94eacb (diff) |
Cleanup fd passing a little
Diffstat (limited to 'audio')
-rw-r--r-- | audio/pcm_bluetooth.c | 45 | ||||
-rw-r--r-- | audio/unix.c | 26 |
2 files changed, 28 insertions, 43 deletions
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c index 2c36bed9..da5927d0 100644 --- a/audio/pcm_bluetooth.c +++ b/audio/pcm_bluetooth.c @@ -907,22 +907,17 @@ static int bluetooth_a2dp_hw_constraint(snd_pcm_ioplug_t *io) static int bluetooth_recvmsg_fd(struct bluetooth_data *data) { - char cmsg_b[CMSG_SPACE(sizeof(int))]; - struct ipc_packet pkt; + char cmsg_b[CMSG_SPACE(sizeof(int))], m; int err, ret; - struct iovec iov = { - .iov_base = &pkt, - .iov_len = sizeof(pkt) - }; - struct msghdr msgh = { - .msg_name = 0, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = &cmsg_b, - .msg_controllen = CMSG_LEN(sizeof(int)), - .msg_flags = 0 - }; + struct iovec iov = { &m, sizeof(m) }; + struct msghdr msgh; + struct cmsghdr *cmsg; + + memset(&msgh, 0, sizeof(msgh)); + msgh.msg_iov = &iov; + msgh.msg_iovlen = 1; + msgh.msg_control = &cmsg_b; + msgh.msg_controllen = CMSG_LEN(sizeof(int)); ret = recvmsg(data->sock, &msgh, 0); if (ret < 0) { @@ -931,20 +926,16 @@ static int bluetooth_recvmsg_fd(struct bluetooth_data *data) return -err; } - if (pkt.type == PKT_TYPE_CFG_RSP) { - struct cmsghdr *cmsg; - /* Receive auxiliary data in msgh */ - for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msgh,cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET + /* Receive auxiliary data in msgh */ + for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; + cmsg = CMSG_NXTHDR(&msgh, cmsg)) { + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { - data->stream_fd = (*(int *) CMSG_DATA(cmsg)); - DBG("stream_fd=%d", data->stream_fd); - return 0; - } + data->stream_fd = (*(int *) CMSG_DATA(cmsg)); + DBG("stream_fd=%d", data->stream_fd); + return 0; } - } else - SNDERR("Unexpected packet type %d received", pkt.type); + } return -EINVAL; } diff --git a/audio/unix.c b/audio/unix.c index accf6efb..cf225ae5 100644 --- a/audio/unix.c +++ b/audio/unix.c @@ -122,24 +122,18 @@ static void client_free(struct unix_client *client) and the sendmsg() system call with the cmsg_type field of a "struct cmsghdr" set to SCM_RIGHTS and the data being an integer value equal to the handle of the file descriptor to be passed.*/ -static int unix_sendmsg_fd(int sock, int fd, struct ipc_packet *pkt) +static int unix_sendmsg_fd(int sock, int fd) { - char cmsg_b[CMSG_SPACE(sizeof(int))]; + char cmsg_b[CMSG_SPACE(sizeof(int))], m = 'm'; struct cmsghdr *cmsg; - struct iovec iov = { - .iov_base = pkt, - .iov_len = sizeof(struct ipc_packet) - }; + struct iovec iov = { &m, sizeof(m) }; + struct msghdr msgh; - struct msghdr msgh = { - .msg_name = 0, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = &cmsg_b, - .msg_controllen = CMSG_LEN(sizeof(int)), - .msg_flags = 0 - }; + memset(&msgh, 0, sizeof(msgh)); + msgh.msg_iov = &iov; + msgh.msg_iovlen = 1; + msgh.msg_control = &cmsg_b; + msgh.msg_controllen = CMSG_LEN(sizeof(int)); cmsg = CMSG_FIRSTHDR(&msgh); cmsg->cmsg_level = SOL_SOCKET; @@ -237,7 +231,7 @@ static int unix_send_cfg(int sock, struct ipc_data_cfg *cfg, int fd) debug("%d bytes sent", len); if (fd != -1) { - len = unix_sendmsg_fd(sock, fd, pkt); + len = unix_sendmsg_fd(sock, fd); if (len < 0) error("Error %s(%d)", strerror(errno), errno); debug("%d bytes sent", len); |