mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 05:35:39 +00:00
util: drop qemu_socket_try_set_nonblock()
Now we can use qemu_set_blocking() in these cases. Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
committed by
Daniel P. Berrangé
parent
8cb17f9c36
commit
09759245cf
@@ -47,7 +47,6 @@ ssize_t qemu_send_full(int s, const void *buf, size_t count)
|
||||
int socket_set_cork(int fd, int v);
|
||||
int socket_set_nodelay(int fd);
|
||||
void qemu_socket_set_block(int fd);
|
||||
int qemu_socket_try_set_nonblock(int fd);
|
||||
int socket_set_fast_reuse(int fd);
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
12
net/dgram.c
12
net/dgram.c
@@ -287,7 +287,7 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
||||
Error **errp)
|
||||
{
|
||||
NetDgramState *s;
|
||||
int fd, ret;
|
||||
int fd;
|
||||
struct sockaddr_in *saddr;
|
||||
|
||||
if (remote->type != SOCKET_ADDRESS_TYPE_INET) {
|
||||
@@ -335,11 +335,8 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
||||
g_free(saddr);
|
||||
return -1;
|
||||
}
|
||||
ret = qemu_socket_try_set_nonblock(fd);
|
||||
if (ret < 0) {
|
||||
if (!qemu_set_blocking(fd, false, errp)) {
|
||||
g_free(saddr);
|
||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
||||
name, fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -572,10 +569,7 @@ int net_init_dgram(const Netdev *netdev, const char *name,
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
ret = qemu_socket_try_set_nonblock(fd);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
||||
name, fd);
|
||||
if (!qemu_set_blocking(fd, false, errp)) {
|
||||
return -1;
|
||||
}
|
||||
dest_addr = NULL;
|
||||
|
||||
@@ -718,7 +718,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
|
||||
}
|
||||
|
||||
if (sock->fd) {
|
||||
int fd, ret, so_type;
|
||||
int fd, so_type;
|
||||
|
||||
fd = monitor_fd_param(monitor_cur(), sock->fd, errp);
|
||||
if (fd == -1) {
|
||||
@@ -728,10 +728,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
|
||||
if (so_type < 0) {
|
||||
return -1;
|
||||
}
|
||||
ret = qemu_socket_try_set_nonblock(fd);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
||||
name, fd);
|
||||
if (!qemu_set_blocking(fd, false, errp)) {
|
||||
return -1;
|
||||
}
|
||||
switch (so_type) {
|
||||
|
||||
@@ -138,7 +138,6 @@ static void net_stream_server_listening(QIOTask *task, gpointer opaque)
|
||||
NetStreamData *d = opaque;
|
||||
QIOChannelSocket *listen_sioc = QIO_CHANNEL_SOCKET(d->listen_ioc);
|
||||
SocketAddress *addr;
|
||||
int ret;
|
||||
Error *err = NULL;
|
||||
|
||||
if (qio_task_propagate_error(task, &err)) {
|
||||
@@ -149,13 +148,11 @@ static void net_stream_server_listening(QIOTask *task, gpointer opaque)
|
||||
|
||||
addr = qio_channel_socket_get_local_address(listen_sioc, NULL);
|
||||
g_assert(addr != NULL);
|
||||
ret = qemu_socket_try_set_nonblock(listen_sioc->fd);
|
||||
if (addr->type == SOCKET_ADDRESS_TYPE_FD && ret < 0) {
|
||||
qemu_set_info_str(&d->nc, "can't use file descriptor %s (errno %d)",
|
||||
addr->u.fd.str, -ret);
|
||||
if (!qemu_set_blocking(listen_sioc->fd, false, &err)) {
|
||||
qemu_set_info_str(&d->nc, "error: %s", error_get_pretty(err));
|
||||
error_free(err);
|
||||
return;
|
||||
}
|
||||
g_assert(ret == 0);
|
||||
qapi_free_SocketAddress(addr);
|
||||
|
||||
d->nc.link_down = true;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "net/net.h"
|
||||
#include "io/channel.h"
|
||||
#include "io/net-listener.h"
|
||||
#include "qemu/sockets.h"
|
||||
|
||||
#include "stream_data.h"
|
||||
|
||||
@@ -154,7 +155,6 @@ int net_stream_data_client_connected(QIOTask *task, NetStreamData *d)
|
||||
{
|
||||
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(d->ioc);
|
||||
SocketAddress *addr;
|
||||
int ret;
|
||||
Error *err = NULL;
|
||||
|
||||
if (qio_task_propagate_error(task, &err)) {
|
||||
@@ -166,14 +166,12 @@ int net_stream_data_client_connected(QIOTask *task, NetStreamData *d)
|
||||
addr = qio_channel_socket_get_remote_address(sioc, NULL);
|
||||
g_assert(addr != NULL);
|
||||
|
||||
ret = qemu_socket_try_set_nonblock(sioc->fd);
|
||||
if (addr->type == SOCKET_ADDRESS_TYPE_FD && ret < 0) {
|
||||
qemu_set_info_str(&d->nc, "can't use file descriptor %s (errno %d)",
|
||||
addr->u.fd.str, -ret);
|
||||
if (!qemu_set_blocking(sioc->fd, false, &err)) {
|
||||
qemu_set_info_str(&d->nc, "error: %s", error_get_pretty(err));
|
||||
error_free(err);
|
||||
qapi_free_SocketAddress(addr);
|
||||
goto error;
|
||||
}
|
||||
g_assert(ret == 0);
|
||||
qapi_free_SocketAddress(addr);
|
||||
|
||||
net_socket_rs_init(&d->rs, net_stream_data_rs_finalize, false);
|
||||
|
||||
@@ -270,10 +270,6 @@ void qemu_socket_set_block(int fd)
|
||||
g_unix_set_fd_nonblocking(fd, false, NULL);
|
||||
}
|
||||
|
||||
int qemu_socket_try_set_nonblock(int fd)
|
||||
{
|
||||
return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno;
|
||||
}
|
||||
|
||||
int socket_set_fast_reuse(int fd)
|
||||
{
|
||||
|
||||
@@ -202,15 +202,6 @@ void qemu_socket_set_block(int fd)
|
||||
ioctlsocket(fd, FIONBIO, &opt);
|
||||
}
|
||||
|
||||
int qemu_socket_try_set_nonblock(int fd)
|
||||
{
|
||||
unsigned long opt = 1;
|
||||
if (ioctlsocket(fd, FIONBIO, &opt) != NO_ERROR) {
|
||||
return -socket_error();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int socket_set_fast_reuse(int fd)
|
||||
{
|
||||
/* Enabling the reuse of an endpoint that was used by a socket still in
|
||||
|
||||
Reference in New Issue
Block a user