slirp: Kill slirp_is_inited

Avoid the need for slirp_is_inited by refactoring the protected
slirp_select_* functions. This also avoids the clearing of all fd sets
on select errors.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Jan Kiszka 2009-06-24 14:42:30 +02:00 committed by Anthony Liguori
parent 8ec7f4edcf
commit d918f23efa
5 changed files with 32 additions and 35 deletions

9
net.c
View File

@ -120,9 +120,7 @@
#include "qemu_socket.h" #include "qemu_socket.h"
#include "qemu-log.h" #include "qemu-log.h"
#if defined(CONFIG_SLIRP) #include "slirp/libslirp.h"
#include "libslirp.h"
#endif
static VLANState *first_vlan; static VLANState *first_vlan;
@ -712,11 +710,6 @@ void slirp_output(const uint8_t *pkt, int pkt_len)
qemu_send_packet(slirp_vc, pkt, pkt_len); qemu_send_packet(slirp_vc, pkt, pkt_len);
} }
int slirp_is_inited(void)
{
return slirp_inited;
}
static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size) static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
#ifdef DEBUG_SLIRP #ifdef DEBUG_SLIRP

1
net.h
View File

@ -138,7 +138,6 @@ void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str);
void net_slirp_hostfwd_remove(Monitor *mon, const char *src_str); void net_slirp_hostfwd_remove(Monitor *mon, const char *src_str);
void net_slirp_redir(const char *redir_str); void net_slirp_redir(const char *redir_str);
void net_cleanup(void); void net_cleanup(void);
int slirp_is_inited(void);
void net_client_check(void); void net_client_check(void);
void net_set_boot_mask(int boot_mask); void net_set_boot_mask(int boot_mask);
void net_host_device_add(Monitor *mon, const char *device, const char *opts); void net_host_device_add(Monitor *mon, const char *device, const char *opts);

View File

@ -3,6 +3,8 @@
#include <qemu-common.h> #include <qemu-common.h>
#ifdef CONFIG_SLIRP
void slirp_init(int restricted, struct in_addr vnetwork, void slirp_init(int restricted, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost, struct in_addr vnetmask, struct in_addr vhost,
const char *vhostname, const char *tftp_path, const char *vhostname, const char *tftp_path,
@ -12,7 +14,8 @@ void slirp_init(int restricted, struct in_addr vnetwork,
void slirp_select_fill(int *pnfds, void slirp_select_fill(int *pnfds,
fd_set *readfds, fd_set *writefds, fd_set *xfds); fd_set *readfds, fd_set *writefds, fd_set *xfds);
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds); void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
int select_error);
void slirp_input(const uint8_t *pkt, int pkt_len); void slirp_input(const uint8_t *pkt, int pkt_len);
@ -32,4 +35,13 @@ void slirp_socket_recv(struct in_addr guest_addr, int guest_port,
const uint8_t *buf, int size); const uint8_t *buf, int size);
size_t slirp_socket_can_recv(struct in_addr guest_addr, int guest_port); size_t slirp_socket_can_recv(struct in_addr guest_addr, int guest_port);
#else /* !CONFIG_SLIRP */
static inline void slirp_select_fill(int *pnfds, fd_set *readfds,
fd_set *writefds, fd_set *xfds) { }
static inline void slirp_select_poll(fd_set *readfds, fd_set *writefds,
fd_set *xfds, int select_error) { }
#endif /* !CONFIG_SLIRP */
#endif #endif

View File

@ -271,6 +271,10 @@ void slirp_select_fill(int *pnfds,
int nfds; int nfds;
int tmp_time; int tmp_time;
if (!link_up) {
return;
}
/* fail safe */ /* fail safe */
global_readfds = NULL; global_readfds = NULL;
global_writefds = NULL; global_writefds = NULL;
@ -281,7 +285,7 @@ void slirp_select_fill(int *pnfds,
* First, TCP sockets * First, TCP sockets
*/ */
do_slowtimo = 0; do_slowtimo = 0;
if (link_up) {
/* /*
* *_slowtimo needs calling if there are IP fragments * *_slowtimo needs calling if there are IP fragments
* in the fragment queue, or there are TCP connections active * in the fragment queue, or there are TCP connections active
@ -375,7 +379,6 @@ void slirp_select_fill(int *pnfds,
UPD_NFDS(so->s); UPD_NFDS(so->s);
} }
} }
}
/* /*
* Setup timeout to use minimum CPU usage, especially when idle * Setup timeout to use minimum CPU usage, especially when idle
@ -413,11 +416,16 @@ void slirp_select_fill(int *pnfds,
*pnfds = nfds; *pnfds = nfds;
} }
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
int select_error)
{ {
struct socket *so, *so_next; struct socket *so, *so_next;
int ret; int ret;
if (!link_up) {
return;
}
global_readfds = readfds; global_readfds = readfds;
global_writefds = writefds; global_writefds = writefds;
global_xfds = xfds; global_xfds = xfds;
@ -428,7 +436,6 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
/* /*
* See if anything has timed out * See if anything has timed out
*/ */
if (link_up) {
if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) { if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
tcp_fasttimo(); tcp_fasttimo();
time_fasttimo = 0; time_fasttimo = 0;
@ -438,12 +445,11 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
tcp_slowtimo(); tcp_slowtimo();
last_slowtimo = curtime; last_slowtimo = curtime;
} }
}
/* /*
* Check sockets * Check sockets
*/ */
if (link_up) { if (!select_error) {
/* /*
* Check TCP sockets * Check TCP sockets
*/ */
@ -576,7 +582,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
/* /*
* See if we can start outputting * See if we can start outputting
*/ */
if (if_queued && link_up) if (if_queued)
if_start(); if_start();
/* clear global file descriptor sets. /* clear global file descriptor sets.

23
vl.c
View File

@ -165,9 +165,7 @@ int main(int argc, char **argv)
#include "qemu_socket.h" #include "qemu_socket.h"
#if defined(CONFIG_SLIRP) #include "slirp/libslirp.h"
#include "libslirp.h"
#endif
//#define DEBUG_UNUSED_IOPORT //#define DEBUG_UNUSED_IOPORT
//#define DEBUG_IOPORT //#define DEBUG_IOPORT
@ -4266,11 +4264,8 @@ void main_loop_wait(int timeout)
tv.tv_sec = timeout / 1000; tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000; tv.tv_usec = (timeout % 1000) * 1000;
#if defined(CONFIG_SLIRP) slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
if (slirp_is_inited()) {
slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
}
#endif
qemu_mutex_unlock_iothread(); qemu_mutex_unlock_iothread();
ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
qemu_mutex_lock_iothread(); qemu_mutex_lock_iothread();
@ -4297,16 +4292,8 @@ void main_loop_wait(int timeout)
pioh = &ioh->next; pioh = &ioh->next;
} }
} }
#if defined(CONFIG_SLIRP)
if (slirp_is_inited()) { slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
if (ret < 0) {
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&xfds);
}
slirp_select_poll(&rfds, &wfds, &xfds);
}
#endif
/* rearm timer, if not periodic */ /* rearm timer, if not periodic */
if (alarm_timer->flags & ALARM_FLAG_EXPIRED) { if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {