slirp: add unregister_poll_fd() callback

Add a counter-part to register_poll_fd() for completeness.

(so far, register_poll_fd() is called only on struct socket fd)

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
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:42 +04:00 committed by Samuel Thibault
parent 848c7092ba
commit f6e5aa366f
6 changed files with 14 additions and 1 deletions

View File

@ -191,6 +191,11 @@ static void net_slirp_register_poll_fd(int fd)
qemu_fd_register(fd);
}
static void net_slirp_unregister_poll_fd(int fd)
{
/* no qemu_fd_unregister */
}
static const SlirpCb slirp_cb = {
.output = net_slirp_output,
.guest_error = net_slirp_guest_error,
@ -199,6 +204,7 @@ static const SlirpCb slirp_cb = {
.timer_free = net_slirp_timer_free,
.timer_mod = net_slirp_timer_mod,
.register_poll_fd = net_slirp_register_poll_fd,
.unregister_poll_fd = net_slirp_unregister_poll_fd,
};
static int net_slirp_init(NetClientState *peer, const char *model,

View File

@ -114,6 +114,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
void icmp_detach(struct socket *so)
{
so->slirp->cb->unregister_poll_fd(so->s);
slirp_closesocket(so->s);
sofree(so);
}

View File

@ -29,6 +29,8 @@ typedef struct SlirpCb {
void (*timer_mod)(void *timer, int64_t expire_time);
/* Register a fd for future polling */
void (*register_poll_fd)(int fd);
/* Unregister a fd */
void (*unregister_poll_fd)(int fd);
} SlirpCb;

View File

@ -1015,7 +1015,8 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 &&
addr.sin_addr.s_addr == host_addr.s_addr &&
addr.sin_port == port) {
close(so->s);
so->slirp->cb->unregister_poll_fd(so->s);
slirp_closesocket(so->s);
sofree(so);
return 0;
}

View File

@ -337,6 +337,7 @@ tcp_close(struct tcpcb *tp)
/* clobber input socket cache if we're closing the cached connection */
if (so == slirp->tcp_last_so)
slirp->tcp_last_so = &slirp->tcb;
so->slirp->cb->unregister_poll_fd(so->s);
slirp_closesocket(so->s);
sbfree(&so->so_rcv);
sbfree(&so->so_snd);
@ -498,6 +499,7 @@ void tcp_connect(struct socket *inso)
/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
/* If we only accept once, close the accept() socket */
so->slirp->cb->unregister_poll_fd(so->s);
slirp_closesocket(so->s);
/* Don't select it yet, even though we have an FD */

View File

@ -292,6 +292,7 @@ udp_attach(struct socket *so, unsigned short af)
void
udp_detach(struct socket *so)
{
so->slirp->cb->unregister_poll_fd(so->s);
slirp_closesocket(so->s);
sofree(so);
}