void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,

                       int select_error)

{

    Slirp *slirp;

    struct socket *so, *so_next;

    int ret;



    if (QTAILQ_EMPTY(&slirp_instances)) {

        return;

    }



    global_readfds = readfds;

    global_writefds = writefds;

    global_xfds = xfds;



    curtime = qemu_get_clock_ms(rt_clock);



    QTAILQ_FOREACH(slirp, &slirp_instances, entry) {

	/*

	 * See if anything has timed out

	 */

		if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {

			tcp_fasttimo(slirp);

			time_fasttimo = 0;

		}

		if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {

			ip_slowtimo(slirp);

			tcp_slowtimo(slirp);

			last_slowtimo = curtime;

		}



	/*

	 * Check sockets

	 */

	if (!select_error) {

		/*

		 * Check TCP sockets

		 */

		for (so = slirp->tcb.so_next; so != &slirp->tcb;

		     so = so_next) {

			so_next = so->so_next;



			/*

			 * FD_ISSET is meaningless on these sockets

			 * (and they can crash the program)

			 */

			if (so->so_state & SS_NOFDREF || so->s == -1)

			   continue;



			/*

			 * Check for URG data

			 * This will soread as well, so no need to

			 * test for readfds below if this succeeds

			 */

			if (FD_ISSET(so->s, xfds))

			   sorecvoob(so);

			/*

			 * Check sockets for reading

			 */

			else if (FD_ISSET(so->s, readfds)) {

				/*

				 * Check for incoming connections

				 */

				if (so->so_state & SS_FACCEPTCONN) {

					tcp_connect(so);

					continue;

				} /* else */

				ret = soread(so);



				/* Output it if we read something */

				if (ret > 0)

				   tcp_output(sototcpcb(so));

			}



			/*

			 * Check sockets for writing

			 */

			if (FD_ISSET(so->s, writefds)) {

			  /*

			   * Check for non-blocking, still-connecting sockets

			   */

			  if (so->so_state & SS_ISFCONNECTING) {

			    /* Connected */

			    so->so_state &= ~SS_ISFCONNECTING;



			    ret = send(so->s, (const void *) &ret, 0, 0);

			    if (ret < 0) {

			      /* XXXXX Must fix, zero bytes is a NOP */

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;



			      /* else failed */

			      so->so_state &= SS_PERSISTENT_MASK;

			      so->so_state |= SS_NOFDREF;

			    }

			    /* else so->so_state &= ~SS_ISFCONNECTING; */



			    /*

			     * Continue tcp_input

			     */

			    tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);

			    /* continue; */

			  } else

			    ret = sowrite(so);

			  /*

			   * XXXXX If we wrote something (a lot), there

			   * could be a need for a window update.

			   * In the worst case, the remote will send

			   * a window probe to get things going again

			   */

			}



			/*

			 * Probe a still-connecting, non-blocking socket

			 * to check if it's still alive

	 	 	 */

#ifdef PROBE_CONN

			if (so->so_state & SS_ISFCONNECTING) {

                          ret = qemu_recv(so->s, &ret, 0,0);



			  if (ret < 0) {

			    /* XXX */

			    if (errno == EAGAIN || errno == EWOULDBLOCK ||

				errno == EINPROGRESS || errno == ENOTCONN)

			      continue; /* Still connecting, continue */



			    /* else failed */

			    so->so_state &= SS_PERSISTENT_MASK;

			    so->so_state |= SS_NOFDREF;



			    /* tcp_input will take care of it */

			  } else {

			    ret = send(so->s, &ret, 0,0);

			    if (ret < 0) {

			      /* XXX */

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;

			      /* else failed */

			      so->so_state &= SS_PERSISTENT_MASK;

			      so->so_state |= SS_NOFDREF;

			    } else

			      so->so_state &= ~SS_ISFCONNECTING;



			  }

			  tcp_input((struct mbuf *)NULL, sizeof(struct ip),so);

			} /* SS_ISFCONNECTING */

#endif

		}



		/*

		 * Now UDP sockets.

		 * Incoming packets are sent straight away, they're not buffered.

		 * Incoming UDP data isn't buffered either.

		 */

		for (so = slirp->udb.so_next; so != &slirp->udb;

		     so = so_next) {

			so_next = so->so_next;



			if (so->s != -1 && FD_ISSET(so->s, readfds)) {

                            sorecvfrom(so);

                        }

		}



                /*

                 * Check incoming ICMP relies.

                 */

                for (so = slirp->icmp.so_next; so != &slirp->icmp;

                     so = so_next) {

                     so_next = so->so_next;



                    if (so->s != -1 && FD_ISSET(so->s, readfds)) {

                        icmp_receive(so);

                    }

                }

	}



	/*

	 * See if we can start outputting

	 */

	if (slirp->if_queued) {

	    if_start(slirp);

	}

    }



	/* clear global file descriptor sets.

	 * these reside on the stack in vl.c

	 * so they're unusable if we're not in

	 * slirp_select_fill or slirp_select_poll.

	 */

	 global_readfds = NULL;

	 global_writefds = NULL;

	 global_xfds = NULL;

}

void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,

                       int select_error)

{

    Slirp *slirp;

    struct socket *so, *so_next;

    int ret;



    if (QTAILQ_EMPTY(&slirp_instances)) {

        return;

    }



    global_readfds = readfds;

    global_writefds = writefds;

    global_xfds = xfds;



    curtime = qemu_get_clock_ms(rt_clock);



    QTAILQ_FOREACH(slirp, &slirp_instances, entry) {

	





		if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {

			tcp_fasttimo(slirp);

			time_fasttimo = 0;

		}

		if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {

			ip_slowtimo(slirp);

			tcp_slowtimo(slirp);

			last_slowtimo = curtime;

		}



	





	if (!select_error) {

		





		for (so = slirp->tcb.so_next; so != &slirp->tcb;

		     so = so_next) {

			so_next = so->so_next;



			







			if (so->so_state & SS_NOFDREF || so->s == -1)

			   continue;



			









			if (FD_ISSET(so->s, xfds))

			   sorecvoob(so);

			





			else if (FD_ISSET(so->s, readfds)) {

				





				if (so->so_state & SS_FACCEPTCONN) {

					tcp_connect(so);

					continue;

				} 

				ret = soread(so);



				

				if (ret > 0)

				   tcp_output(sototcpcb(so));

			}



			





			if (FD_ISSET(so->s, writefds)) {

			  





			  if (so->so_state & SS_ISFCONNECTING) {

			    

			    so->so_state &= ~SS_ISFCONNECTING;



			    ret = send(so->s, (const void *) &ret, 0, 0);

			    if (ret < 0) {

			      

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;



			      

			      so->so_state &= SS_PERSISTENT_MASK;

			      so->so_state |= SS_NOFDREF;

			    }

			    



			    





			    tcp_input((struct mbuf *)NULL, sizeof(struct ip), so);

			    

			  } else

			    ret = sowrite(so);

			  











			}



			







#ifdef PROBE_CONN

			if (so->so_state & SS_ISFCONNECTING) {

                          ret = qemu_recv(so->s, &ret, 0,0);



			  if (ret < 0) {

			    

			    if (errno == EAGAIN || errno == EWOULDBLOCK ||

				errno == EINPROGRESS || errno == ENOTCONN)

			      continue; 



			    

			    so->so_state &= SS_PERSISTENT_MASK;

			    so->so_state |= SS_NOFDREF;



			    

			  } else {

			    ret = send(so->s, &ret, 0,0);

			    if (ret < 0) {

			      

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;

			      

			      so->so_state &= SS_PERSISTENT_MASK;

			      so->so_state |= SS_NOFDREF;

			    } else

			      so->so_state &= ~SS_ISFCONNECTING;



			  }

			  tcp_input((struct mbuf *)NULL, sizeof(struct ip),so);

			} 

#endif

		}



		









		for (so = slirp->udb.so_next; so != &slirp->udb;

		     so = so_next) {

			so_next = so->so_next;



			if (so->s != -1 && FD_ISSET(so->s, readfds)) {

                            sorecvfrom(so);

                        }

		}



                





                for (so = slirp->icmp.so_next; so != &slirp->icmp;

                     so = so_next) {

                     so_next = so->so_next;



                    if (so->s != -1 && FD_ISSET(so->s, readfds)) {

                        icmp_receive(so);

                    }

                }

	}



	





	if (slirp->if_queued) {

	    if_start(slirp);

	}

    }



	









	 global_readfds = NULL;

	 global_writefds = NULL;

	 global_xfds = NULL;

}

void FUNC_0(fd_set *VAR_0, fd_set *VAR_1, fd_set *VAR_2,

                       int VAR_3)

{

    Slirp *slirp;

    struct socket *VAR_4, *VAR_5;

    int VAR_6;



    if (QTAILQ_EMPTY(&slirp_instances)) {

        return;

    }



    global_readfds = VAR_0;

    global_writefds = VAR_1;

    global_xfds = VAR_2;



    curtime = qemu_get_clock_ms(rt_clock);



    QTAILQ_FOREACH(slirp, &slirp_instances, entry) {

	





		if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {

			tcp_fasttimo(slirp);

			time_fasttimo = 0;

		}

		if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {

			ip_slowtimo(slirp);

			tcp_slowtimo(slirp);

			last_slowtimo = curtime;

		}



	





	if (!VAR_3) {

		





		for (VAR_4 = slirp->tcb.VAR_5; VAR_4 != &slirp->tcb;

		     VAR_4 = VAR_5) {

			VAR_5 = VAR_4->VAR_5;



			







			if (VAR_4->so_state & SS_NOFDREF || VAR_4->s == -1)

			   continue;



			









			if (FD_ISSET(VAR_4->s, VAR_2))

			   sorecvoob(VAR_4);

			





			else if (FD_ISSET(VAR_4->s, VAR_0)) {

				





				if (VAR_4->so_state & SS_FACCEPTCONN) {

					tcp_connect(VAR_4);

					continue;

				} 

				VAR_6 = soread(VAR_4);



				

				if (VAR_6 > 0)

				   tcp_output(sototcpcb(VAR_4));

			}



			





			if (FD_ISSET(VAR_4->s, VAR_1)) {

			  





			  if (VAR_4->so_state & SS_ISFCONNECTING) {

			    

			    VAR_4->so_state &= ~SS_ISFCONNECTING;



			    VAR_6 = send(VAR_4->s, (const void *) &VAR_6, 0, 0);

			    if (VAR_6 < 0) {

			      

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;



			      

			      VAR_4->so_state &= SS_PERSISTENT_MASK;

			      VAR_4->so_state |= SS_NOFDREF;

			    }

			    



			    





			    tcp_input((struct mbuf *)NULL, sizeof(struct ip), VAR_4);

			    

			  } else

			    VAR_6 = sowrite(VAR_4);

			  











			}



			







#ifdef PROBE_CONN

			if (VAR_4->so_state & SS_ISFCONNECTING) {

                          VAR_6 = qemu_recv(VAR_4->s, &VAR_6, 0,0);



			  if (VAR_6 < 0) {

			    

			    if (errno == EAGAIN || errno == EWOULDBLOCK ||

				errno == EINPROGRESS || errno == ENOTCONN)

			      continue; 



			    

			    VAR_4->so_state &= SS_PERSISTENT_MASK;

			    VAR_4->so_state |= SS_NOFDREF;



			    

			  } else {

			    VAR_6 = send(VAR_4->s, &VAR_6, 0,0);

			    if (VAR_6 < 0) {

			      

			      if (errno == EAGAIN || errno == EWOULDBLOCK ||

				  errno == EINPROGRESS || errno == ENOTCONN)

				continue;

			      

			      VAR_4->so_state &= SS_PERSISTENT_MASK;

			      VAR_4->so_state |= SS_NOFDREF;

			    } else

			      VAR_4->so_state &= ~SS_ISFCONNECTING;



			  }

			  tcp_input((struct mbuf *)NULL, sizeof(struct ip),VAR_4);

			} 

#endif

		}



		









		for (VAR_4 = slirp->udb.VAR_5; VAR_4 != &slirp->udb;

		     VAR_4 = VAR_5) {

			VAR_5 = VAR_4->VAR_5;



			if (VAR_4->s != -1 && FD_ISSET(VAR_4->s, VAR_0)) {

                            sorecvfrom(VAR_4);

                        }

		}



                





                for (VAR_4 = slirp->icmp.VAR_5; VAR_4 != &slirp->icmp;

                     VAR_4 = VAR_5) {

                     VAR_5 = VAR_4->VAR_5;



                    if (VAR_4->s != -1 && FD_ISSET(VAR_4->s, VAR_0)) {

                        icmp_receive(VAR_4);

                    }

                }

	}



	





	if (slirp->if_queued) {

	    if_start(slirp);

	}

    }



	









	 global_readfds = NULL;

	 global_writefds = NULL;

	 global_xfds = NULL;

}

void FUNC_0(fd_set *VAR_0, fd_set *VAR_1, fd_set *VAR_2,
int VAR_3)
{ Slirp *slirp; struct socket *VAR_4, *VAR_5; int VAR_6; if (QTAILQ_EMPTY(&slirp_instances)) { return; } global_readfds = VAR_0; global_writefds = VAR_1; global_xfds = VAR_2; curtime = qemu_get_clock_ms(rt_clock); QTAILQ_FOREACH(slirp, &slirp_instances, entry) { if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) { tcp_fasttimo(slirp); time_fasttimo = 0; } if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) { ip_slowtimo(slirp); tcp_slowtimo(slirp); last_slowtimo = curtime; } if (!VAR_3) { for (VAR_4 = slirp->tcb.VAR_5; VAR_4 != &slirp->tcb; VAR_4 = VAR_5) { VAR_5 = VAR_4->VAR_5; if (VAR_4->so_state & SS_NOFDREF || VAR_4->s == -1)
continue; if (FD_ISSET(VAR_4->s, VAR_2))
sorecvoob(VAR_4); else if (FD_ISSET(VAR_4->s, VAR_0)) { if (VAR_4->so_state & SS_FACCEPTCONN) { tcp_connect(VAR_4); continue; } VAR_6 = soread(VAR_4); if (VAR_6 > 0)
tcp_output(sototcpcb(VAR_4)); } if (FD_ISSET(VAR_4->s, VAR_1)) { if (VAR_4->so_state & SS_ISFCONNECTING) { VAR_4->so_state &= ~SS_ISFCONNECTING; VAR_6 = send(VAR_4->s, (const void *) &VAR_6, 0, 0); if (VAR_6 < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue; VAR_4->so_state &= SS_PERSISTENT_MASK; VAR_4->so_state |= SS_NOFDREF; } tcp_input((struct mbuf *)NULL, sizeof(struct ip), VAR_4); } else VAR_6 = sowrite(VAR_4); } #ifdef PROBE_CONN
if (VAR_4->so_state & SS_ISFCONNECTING) { VAR_6 = qemu_recv(VAR_4->s, &VAR_6, 0,0); if (VAR_6 < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue; VAR_4->so_state &= SS_PERSISTENT_MASK; VAR_4->so_state |= SS_NOFDREF; } else { VAR_6 = send(VAR_4->s, &VAR_6, 0,0); if (VAR_6 < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK ||
errno == EINPROGRESS || errno == ENOTCONN)
continue; VAR_4->so_state &= SS_PERSISTENT_MASK; VAR_4->so_state |= SS_NOFDREF; } else VAR_4->so_state &= ~SS_ISFCONNECTING; } tcp_input((struct mbuf *)NULL, sizeof(struct ip),VAR_4); } #endif
} for (VAR_4 = slirp->udb.VAR_5; VAR_4 != &slirp->udb; VAR_4 = VAR_5) { VAR_5 = VAR_4->VAR_5; if (VAR_4->s != -1 && FD_ISSET(VAR_4->s, VAR_0)) { sorecvfrom(VAR_4); } } for (VAR_4 = slirp->icmp.VAR_5; VAR_4 != &slirp->icmp; VAR_4 = VAR_5) { VAR_5 = VAR_4->VAR_5; if (VAR_4->s != -1 && FD_ISSET(VAR_4->s, VAR_0)) { icmp_receive(VAR_4); } } } if (slirp->if_queued) { if_start(slirp); } } global_readfds = NULL; global_writefds = NULL; global_xfds = NULL; }