slirp: replace qemu_set_nonblock()

Replace qemu_set_nonblock() with slirp_set_nonblock()

qemu_set_nonblock() does some event registration with the main
loop. Add a new callback register_poll_fd() for that reason.

Always build the fd-register stub, to avoid #if WIN32.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
Marc-André Lureau 2019-01-17 15:43:41 +04:00 committed by Samuel Thibault
parent 707bd47ef3
commit 848c7092ba
7 changed files with 30 additions and 4 deletions

View File

@ -186,6 +186,11 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer)
timer_mod(timer, expire_timer);
}
static void net_slirp_register_poll_fd(int fd)
{
qemu_fd_register(fd);
}
static const SlirpCb slirp_cb = {
.output = net_slirp_output,
.guest_error = net_slirp_guest_error,
@ -193,6 +198,7 @@ static const SlirpCb slirp_cb = {
.timer_new = net_slirp_timer_new,
.timer_free = net_slirp_timer_free,
.timer_mod = net_slirp_timer_mod,
.register_poll_fd = net_slirp_register_poll_fd,
};
static int net_slirp_init(NetClientState *peer, const char *model,

View File

@ -27,6 +27,8 @@ typedef struct SlirpCb {
void (*timer_free)(void *timer);
/* Modify a timer to expire at @expire_time */
void (*timer_mod)(void *timer, int64_t expire_time);
/* Register a fd for future polling */
void (*register_poll_fd)(int fd);
} SlirpCb;

View File

@ -163,7 +163,8 @@ fork_exec(struct socket *so, const char *ex)
slirp_socket_set_fast_reuse(so->s);
opt = 1;
slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
qemu_set_nonblock(so->s);
slirp_set_nonblock(so->s);
so->slirp->cb->register_poll_fd(so->s);
return 1;
}

View File

@ -412,7 +412,8 @@ int tcp_fconnect(struct socket *so, unsigned short af)
int opt, s=so->s;
struct sockaddr_storage addr;
qemu_set_nonblock(s);
slirp_set_nonblock(s);
so->slirp->cb->register_poll_fd(so->s);
slirp_socket_set_fast_reuse(s);
opt = 1;
slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
@ -484,7 +485,8 @@ void tcp_connect(struct socket *inso)
tcp_close(sototcpcb(so)); /* This will sofree() as well */
return;
}
qemu_set_nonblock(s);
slirp_set_nonblock(s);
so->slirp->cb->register_poll_fd(so->s);
slirp_socket_set_fast_reuse(s);
opt = 1;
slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));

View File

@ -43,6 +43,20 @@ int inet_aton(const char *cp, struct in_addr *ia)
}
#endif
void slirp_set_nonblock(int fd)
{
#ifndef _WIN32
int f;
f = fcntl(fd, F_GETFL);
assert(f != -1);
f = fcntl(fd, F_SETFL, f | O_NONBLOCK);
assert(f != -1);
#else
unsigned long opt = 1;
ioctlsocket(fd, FIONBIO, &opt);
#endif
}
static void slirp_set_cloexec(int fd)
{
#ifndef _WIN32

View File

@ -68,6 +68,7 @@ int inet_aton(const char *cp, struct in_addr *ia);
#endif
int slirp_socket(int domain, int type, int protocol);
void slirp_set_nonblock(int fd);
static inline int slirp_socket_set_nodelay(int fd)
{

View File

@ -33,7 +33,7 @@ stub-obj-y += trace-control.o
stub-obj-y += uuid.o
stub-obj-y += vm-stop.o
stub-obj-y += vmstate.o
stub-obj-$(CONFIG_WIN32) += fd-register.o
stub-obj-y += fd-register.o
stub-obj-y += qmp_memory_device.o
stub-obj-y += target-monitor-defs.o
stub-obj-y += target-get-monitor-def.o