various modernizations

This commit is contained in:
Lennart Poettering 2010-02-23 01:23:41 +01:00
parent 028aa734f8
commit dbdc666fb6
3 changed files with 32 additions and 33 deletions

View file

@ -55,11 +55,10 @@ struct pa_iochannel {
pa_iochannel_cb_t callback;
void*userdata;
pa_bool_t readable;
pa_bool_t writable;
pa_bool_t hungup;
pa_bool_t no_close;
pa_bool_t readable:1;
pa_bool_t writable:1;
pa_bool_t hungup:1;
pa_bool_t no_close:1;
pa_io_event* input_event, *output_event;
};
@ -258,7 +257,12 @@ ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) {
#ifdef HAVE_CREDS
pa_bool_t pa_iochannel_creds_supported(pa_iochannel *io) {
struct sockaddr_un sa;
struct {
struct sockaddr sa;
struct sockaddr_un un;
struct sockaddr_storage storage;
} sa;
socklen_t l;
pa_assert(io);
@ -266,11 +270,10 @@ pa_bool_t pa_iochannel_creds_supported(pa_iochannel *io) {
pa_assert(io->ofd == io->ifd);
l = sizeof(sa);
if (getsockname(io->ifd, &sa.sa, &l) < 0)
return FALSE;
if (getsockname(io->ifd, (struct sockaddr*) &sa, &l) < 0)
return 0;
return sa.sun_family == AF_UNIX;
return sa.sa.sa_family == AF_UNIX;
}
int pa_iochannel_creds_enable(pa_iochannel *io) {
@ -302,11 +305,11 @@ ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l
pa_assert(l);
pa_assert(io->ofd >= 0);
memset(&iov, 0, sizeof(iov));
pa_zero(iov);
iov.iov_base = (void*) data;
iov.iov_len = l;
memset(&cmsg, 0, sizeof(cmsg));
pa_zero(cmsg);
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_CREDENTIALS;
@ -352,25 +355,21 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
pa_assert(creds);
pa_assert(creds_valid);
memset(&iov, 0, sizeof(iov));
pa_zero(iov);
iov.iov_base = data;
iov.iov_len = l;
memset(&cmsg, 0, sizeof(cmsg));
memset(&mh, 0, sizeof(mh));
mh.msg_name = NULL;
mh.msg_namelen = 0;
pa_zero(cmsg);
pa_zero(mh);
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
mh.msg_control = &cmsg;
mh.msg_controllen = sizeof(cmsg);
mh.msg_flags = 0;
if ((r = recvmsg(io->ifd, &mh, 0)) >= 0) {
struct cmsghdr *cmh;
*creds_valid = 0;
*creds_valid = FALSE;
for (cmh = CMSG_FIRSTHDR(&mh); cmh; cmh = CMSG_NXTHDR(&mh, cmh)) {

View file

@ -328,12 +328,12 @@ static int format_native2esd(pa_sample_spec *ss) {
return format;
}
#define CHECK_VALIDITY(expression, ...) do { \
if (!(expression)) { \
pa_log_warn(__FILE__ ": " __VA_ARGS__); \
return -1; \
} \
} while(0);
#define CHECK_VALIDITY(expression, ...) do { \
if (PA_UNLIKELY(!(expression))) { \
pa_log_warn(__FILE__ ": " __VA_ARGS__); \
return -1; \
} \
} while(0);
/*** esound commands ***/
@ -631,7 +631,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
memset(terminator, 0, sizeof(terminator));
for (conn = pa_idxset_first(c->protocol->connections, &idx); conn; conn = pa_idxset_next(c->protocol->connections, &idx)) {
PA_IDXSET_FOREACH(conn, c->protocol->connections, idx) {
int32_t id, format = ESD_BITS16 | ESD_STEREO, rate = 44100, lvolume = ESD_VOLUME_BASE, rvolume = ESD_VOLUME_BASE;
char name[ESD_NAME_MAX];
@ -689,7 +689,8 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
pa_scache_entry *ce;
idx = PA_IDXSET_INVALID;
for (ce = pa_idxset_first(c->protocol->core->scache, &idx); ce; ce = pa_idxset_next(c->protocol->core->scache, &idx)) {
PA_IDXSET_FOREACH(ce, c->protocol->core->scache, idx) {
int32_t id, rate, lvolume, rvolume, format, len;
char name[ESD_NAME_MAX];
pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } };
@ -1130,7 +1131,7 @@ static int do_read(connection *c) {
/* pa_log("STREAMING_DATA"); */
if (!(l = (size_t) pa_atomic_load(&c->playback.missing)))
if ((l = (size_t) pa_atomic_load(&c->playback.missing)) <= 0)
return 0;
if (c->playback.current_memblock) {
@ -1172,8 +1173,8 @@ static int do_read(connection *c) {
c->playback.memblock_index += (size_t) r;
pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, &chunk, NULL);
pa_atomic_sub(&c->playback.missing, (int) r);
pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, &chunk, NULL);
}
return 0;
@ -1381,10 +1382,9 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
} else {
size_t m;
chunk->length = PA_MIN(length, chunk->length);
c->playback.underrun = FALSE;
chunk->length = PA_MIN(length, chunk->length);
pa_memblockq_drop(c->input_memblockq, chunk->length);
m = pa_memblockq_pop_missing(c->input_memblockq);

View file

@ -1037,7 +1037,7 @@ static playback_stream* playback_stream_new(
pa_assert(ret);
/* Find syncid group */
for (ssync = pa_idxset_first(c->output_streams, &idx); ssync; ssync = pa_idxset_next(c->output_streams, &idx)) {
PA_IDXSET_FOREACH(ssync, c->output_streams, idx) {
if (!playback_stream_isinstance(ssync))
continue;