protocol-native: also handle 0 recvmsg as EOF

When recvmsg returns 0, also handle it like an EOF and close to
connection otherwise we keep spinning forever.
This commit is contained in:
Wim Taymans 2019-05-13 10:08:30 +02:00
parent a2bf4ce96e
commit 795b14f48b
2 changed files with 27 additions and 10 deletions

View file

@ -473,24 +473,30 @@ on_remote_data(void *data, int fd, enum spa_io mask)
struct pw_remote *this = impl->this.remote;
struct pw_protocol_native_connection *conn = impl->connection;
struct pw_core *core = pw_remote_get_core(this);
int res;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
pw_log_error("protocol-native %p: got connection error", impl);
pw_loop_destroy_source(pw_core_get_main_loop(core), impl->source);
impl->source = NULL;
pw_remote_disconnect(this);
return;
res = -EPIPE;
goto error;
}
if (mask & SPA_IO_IN) {
const struct pw_protocol_native_message *msg;
while (!impl->disconnecting
&& pw_protocol_native_connection_get_next(conn, &msg) == 1) {
while (!impl->disconnecting) {
struct pw_proxy *proxy;
const struct pw_protocol_native_demarshal *demarshal;
const struct pw_protocol_marshal *marshal;
res = pw_protocol_native_connection_get_next(conn, &msg);
if (res < 0) {
if (res == -EAGAIN)
break;
goto error;
}
if (res == 0)
break;
pw_log_trace("protocol-native %p: got message %d from %u seq:%d",
this, msg->opcode, msg->id, msg->seq);
@ -530,6 +536,12 @@ on_remote_data(void *data, int fd, enum spa_io mask)
}
}
}
return;
error:
pw_log_error("protocol-native %p: got connection error %d (%s)", impl, res, spa_strerror(res));
pw_loop_destroy_source(pw_core_get_main_loop(core), impl->source);
impl->source = NULL;
pw_remote_disconnect(this);
}

View file

@ -147,9 +147,12 @@ static int refill_buffer(struct pw_protocol_native_connection *conn, struct buff
struct iovec iov[1];
char cmsgbuf[CMSG_SPACE(MAX_FDS_MSG * sizeof(int))];
int n_fds = 0;
size_t avail;
avail = buf->buffer_maxsize - buf->buffer_size;
iov[0].iov_base = buf->buffer_data + buf->buffer_size;
iov[0].iov_len = buf->buffer_maxsize - buf->buffer_size;
iov[0].iov_len = avail;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
@ -158,7 +161,9 @@ static int refill_buffer(struct pw_protocol_native_connection *conn, struct buff
while (true) {
len = recvmsg(conn->fd, &msg, msg.msg_flags);
if (len <= 0) {
if (len == 0 && avail != 0)
return -EPIPE;
else if (len < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN || errno != EWOULDBLOCK)