aboutsummaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-01-17 15:43:41 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-07 15:49:08 +0200
commit848c7092ba69318e7bc72a9c0c1f6cd443c439ad (patch)
treea5f4a80e8be467676ce6d8dce38dc4dc6669bf8d /slirp
parent707bd47ef3cf778b691d9e0df2ede3ec4c3fe771 (diff)
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>
Diffstat (limited to 'slirp')
-rw-r--r--slirp/libslirp.h2
-rw-r--r--slirp/misc.c3
-rw-r--r--slirp/tcp_subr.c6
-rw-r--r--slirp/util.c14
-rw-r--r--slirp/util.h1
5 files changed, 23 insertions, 3 deletions
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 3e75dadfa3..70e99139bf 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -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;
diff --git a/slirp/misc.c b/slirp/misc.c
index 32ec02a525..4ee20a10e4 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -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;
}
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 3567f320ff..8087ffc047 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -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));
diff --git a/slirp/util.c b/slirp/util.c
index b1a36b27bc..59f6713c8b 100644
--- a/slirp/util.c
+++ b/slirp/util.c
@@ -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
diff --git a/slirp/util.h b/slirp/util.h
index fe6f1fbb62..4f6e80c3ed 100644
--- a/slirp/util.h
+++ b/slirp/util.h
@@ -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)
{