connection: improve some return values

This commit is contained in:
Wim Taymans 2018-04-19 20:03:52 +02:00
parent ae905530ba
commit 1f73143d55
3 changed files with 13 additions and 12 deletions

View file

@ -578,7 +578,7 @@ static void do_flush_event(void *data, uint64_t count)
struct client *impl = data; struct client *impl = data;
impl->flush_signaled = false; impl->flush_signaled = false;
if (impl->connection) if (impl->connection)
if (!pw_protocol_native_connection_flush(impl->connection)) if (pw_protocol_native_connection_flush(impl->connection) < 0)
impl->this.disconnect(&impl->this); impl->this.disconnect(&impl->this);
} }

View file

@ -440,13 +440,13 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
/** Flush the connection object /** Flush the connection object
* *
* \param conn the connection object * \param conn the connection object
* \return true on success * \return 0 on success < 0 error code on error
* *
* Write the queued messages on the connection to the socket * Write the queued messages on the connection to the socket
* *
* \memberof pw_protocol_native_connection * \memberof pw_protocol_native_connection
*/ */
bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn) int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn)
{ {
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
ssize_t len; ssize_t len;
@ -454,14 +454,14 @@ bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *c
struct iovec iov[1]; struct iovec iov[1];
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
char cmsgbuf[CMSG_SPACE(MAX_FDS * sizeof(int))]; char cmsgbuf[CMSG_SPACE(MAX_FDS * sizeof(int))];
int *cm; int *cm, res = 0;
uint32_t i, fds_len; uint32_t i, fds_len;
struct buffer *buf; struct buffer *buf;
buf = &impl->out; buf = &impl->out;
if (buf->buffer_size == 0) if (buf->buffer_size == 0)
return true; return 0;
fds_len = buf->n_fds * sizeof(int); fds_len = buf->n_fds * sizeof(int);
@ -502,24 +502,25 @@ bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *c
buf->buffer_size -= len; buf->buffer_size -= len;
buf->n_fds = 0; buf->n_fds = 0;
return true; return 0;
/* ERRORS */ /* ERRORS */
send_error: send_error:
res = -errno;
pw_log_error("could not sendmsg: %s", strerror(errno)); pw_log_error("could not sendmsg: %s", strerror(errno));
return false; return res;
} }
/** Clear the connection object /** Clear the connection object
* *
* \param conn the connection object * \param conn the connection object
* \return true on success * \return 0 on success
* *
* Remove all queued messages from \a conn * Remove all queued messages from \a conn
* *
* \memberof pw_protocol_native_connection * \memberof pw_protocol_native_connection
*/ */
bool pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn) int pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn)
{ {
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
@ -527,5 +528,5 @@ bool pw_protocol_native_connection_clear(struct pw_protocol_native_connection *c
clear_buffer(&impl->in); clear_buffer(&impl->in);
impl->in.update = true; impl->in.update = true;
return true; return 0;
} }

View file

@ -87,10 +87,10 @@ void
pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn, pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
struct spa_pod_builder *builder); struct spa_pod_builder *builder);
bool int
pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn); pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn);
bool int
pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn); pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn);
#ifdef __cplusplus #ifdef __cplusplus