Skip to content

Commit

Permalink
socket: Add num connections to qio_channel_socket_sync()
Browse files Browse the repository at this point in the history
Reviewed-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
  • Loading branch information
Juan Quintela committed Sep 3, 2019
1 parent e5b6353 commit 4e2d8bf
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions include/io/channel-socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
* qio_channel_socket_listen_sync:
* @ioc: the socket channel object
* @addr: the address to listen to
* @num: the expected ammount of connections
* @errp: pointer to a NULL-initialized error object
*
* Attempt to listen to the address @addr. This method
Expand All @@ -132,6 +133,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
*/
int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
SocketAddress *addr,
int num,
Error **errp);

/**
Expand Down
7 changes: 4 additions & 3 deletions io/channel-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,

int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
SocketAddress *addr,
int num,
Error **errp)
{
int fd;

trace_qio_channel_socket_listen_sync(ioc, addr);
fd = socket_listen(addr, 1, errp);
trace_qio_channel_socket_listen_sync(ioc, addr, num);
fd = socket_listen(addr, num, errp);
if (fd < 0) {
trace_qio_channel_socket_listen_fail(ioc);
return -1;
Expand All @@ -226,7 +227,7 @@ static void qio_channel_socket_listen_worker(QIOTask *task,
SocketAddress *addr = opaque;
Error *err = NULL;

qio_channel_socket_listen_sync(ioc, addr, &err);
qio_channel_socket_listen_sync(ioc, addr, 1, &err);

qio_task_set_error(task, err);
}
Expand Down
2 changes: 1 addition & 1 deletion io/net-listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int qio_net_listener_open_sync(QIONetListener *listener,
for (i = 0; i < nresaddrs; i++) {
QIOChannelSocket *sioc = qio_channel_socket_new();

if (qio_channel_socket_listen_sync(sioc, resaddrs[i],
if (qio_channel_socket_listen_sync(sioc, resaddrs[i], 1,
err ? NULL : &err) == 0) {
success = true;

Expand Down
2 changes: 1 addition & 1 deletion io/trace-events
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ qio_channel_socket_connect_sync(void *ioc, void *addr) "Socket connect sync ioc=
qio_channel_socket_connect_async(void *ioc, void *addr) "Socket connect async ioc=%p addr=%p"
qio_channel_socket_connect_fail(void *ioc) "Socket connect fail ioc=%p"
qio_channel_socket_connect_complete(void *ioc, int fd) "Socket connect complete ioc=%p fd=%d"
qio_channel_socket_listen_sync(void *ioc, void *addr) "Socket listen sync ioc=%p addr=%p"
qio_channel_socket_listen_sync(void *ioc, void *addr, int num) "Socket listen sync ioc=%p addr=%p num=%d"
qio_channel_socket_listen_async(void *ioc, void *addr) "Socket listen async ioc=%p addr=%p"
qio_channel_socket_listen_fail(void *ioc) "Socket listen fail ioc=%p"
qio_channel_socket_listen_complete(void *ioc, int fd) "Socket listen complete ioc=%p fd=%d"
Expand Down
3 changes: 2 additions & 1 deletion scsi/qemu-pr-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ int main(int argc, char **argv)
.u.q_unix.path = socket_path,
};
server_ioc = qio_channel_socket_new();
if (qio_channel_socket_listen_sync(server_ioc, &saddr, &local_err) < 0) {
if (qio_channel_socket_listen_sync(server_ioc, &saddr,
1, &local_err) < 0) {
object_unref(OBJECT(server_ioc));
error_report_err(local_err);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions tests/test-char.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass,
char *optstr;
g_assert(!reconnect);
if (is_listen) {
qio_channel_socket_listen_sync(ioc, addr, &error_abort);
qio_channel_socket_listen_sync(ioc, addr, 1, &error_abort);
} else {
qio_channel_socket_connect_sync(ioc, addr, &error_abort);
}
Expand Down Expand Up @@ -892,7 +892,7 @@ static void char_socket_client_test(gconstpointer opaque)
*/
ioc = qio_channel_socket_new();
g_assert_nonnull(ioc);
qio_channel_socket_listen_sync(ioc, config->addr, &error_abort);
qio_channel_socket_listen_sync(ioc, config->addr, 1, &error_abort);
addr = qio_channel_socket_get_local_address(ioc, &error_abort);
g_assert_nonnull(addr);

Expand Down
2 changes: 1 addition & 1 deletion tests/test-io-channel-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr,
QIOChannelSocket *lioc;

lioc = qio_channel_socket_new();
qio_channel_socket_listen_sync(lioc, listen_addr, &error_abort);
qio_channel_socket_listen_sync(lioc, listen_addr, 1, &error_abort);

if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
Expand Down
2 changes: 1 addition & 1 deletion tests/tpm-emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void *tpm_emu_ctrl_thread(void *data)
QIOChannelSocket *lioc = qio_channel_socket_new();
QIOChannel *ioc;

qio_channel_socket_listen_sync(lioc, s->addr, &error_abort);
qio_channel_socket_listen_sync(lioc, s->addr, 1, &error_abort);

g_mutex_lock(&s->data_mutex);
s->data_cond_signal = true;
Expand Down

0 comments on commit 4e2d8bf

Please sign in to comment.