Index: trunk/src/VBox/Devices/Network/slirp/if.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/if.c	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/if.c	(revision 14951)
@@ -28,18 +28,6 @@
 if_init(PNATState pData)
 {
-#if 0
-        /*
-         * Set if_maxlinkhdr to 48 because it's 40 bytes for TCP/IP,
-         * and 8 bytes for PPP, but need to have it on an 8byte boundary
-         */
-#ifdef USE_PPP
-        if_maxlinkhdr = 48;
-#else
-        if_maxlinkhdr = 40;
-#endif
-#else
         /* 2 for alignment, 14 for ethernet, 40 for TCP/IP */
         if_maxlinkhdr = 2 + 14 + 40;
-#endif
         if_queued = 0;
         if_thresh = 10;
Index: trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 14951)
@@ -15,5 +15,5 @@
 };
 
-#ifdef _WIN32
+#ifdef RT_OS_WINDOWS
 
 static int get_dns_addr_domain(PNATState pData, bool fVerbose,
@@ -230,12 +230,12 @@
     pData->netmask = u32Netmask;
 
-#ifdef _WIN32
+#ifdef RT_OS_WINDOWS
     {
         WSADATA Data;
         WSAStartup(MAKEWORD(2,0), &Data);
     }
-#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
+# if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC)
     pData->phEvents[VBOX_SOCKET_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL);
-#endif
+# endif
 #endif
 
@@ -331,5 +331,5 @@
 
     slirp_link_down(pData);
-#ifdef WIN32
+#ifdef RT_OS_WINDOWS
     WSACleanup();
 #endif
@@ -360,5 +360,5 @@
  * curtime kept to an accuracy of 1ms
  */
-#ifdef _WIN32
+#ifdef RT_OS_WINDOWS
 static void updtime(PNATState pData)
 {
@@ -416,13 +416,16 @@
          * triggering of fragment expiration should be the same but use new macroses
          */
-        for (i = 0; i < IPREASS_NHASH; i++)
-        {
-            if (!TAILQ_EMPTY(&ipq[i]))
-            {
-                do_slowtimo = 1;
-                break;
-            }
-        }
-        do_slowtimo |= (tcb.so_next != &tcb);
+        do_slowtimo = (tcb.so_next != &tcb);
+        if (!do_slowtimo)
+        {
+            for (i = 0; i < IPREASS_NHASH; i++)
+            {
+                if (!TAILQ_EMPTY(&ipq[i]))
+                {
+                    do_slowtimo = 1;
+                    break;
+                }
+            }
+        }
 #endif /* VBOX_WITH_BSD_REASS */
 
@@ -459,10 +462,12 @@
                 UPD_NFDS(so->s);
 #else
-                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_READ|FD_WRITE|FD_ACCEPT|FD_CONNECT|FD_OOB);
+engage_event:
+                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_ALL_EVENTS);
                 if (rc == SOCKET_ERROR)
                 {
-socket_error:
+                    /* This should not happen */
                     error = WSAGetLastError();
-                    LogRel(("WSAEventSelector error %d (so=%x, socket=%s, event=%x)\n", error, so, so->s, VBOX_SOCKET_EVENT));
+                    LogRel(("WSAEventSelector (TCP) error %d (so=%x, socket=%s, event=%x)\n",
+                             error, so, so->s, VBOX_SOCKET_EVENT));
                 }
 #endif
@@ -479,10 +484,8 @@
                 FD_SET(so->s, writefds);
                 UPD_NFDS(so->s);
-#else
-                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_READ|FD_WRITE|FD_ACCEPT|FD_CONNECT|FD_OOB);
-                if (rc == SOCKET_ERROR)
-                    goto socket_error;
-#endif
                 continue;
+#else
+                goto engage_event;
+#endif
             }
 
@@ -498,8 +501,5 @@
                 UPD_NFDS(so->s);
 #else
-                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_READ|FD_WRITE|FD_ACCEPT|FD_CONNECT|FD_OOB);
-                if (rc == SOCKET_ERROR)
-                    goto socket_error;
-                continue; /* we're using the widest mask for event */
+                goto engage_event;
 #endif
             }
@@ -517,15 +517,7 @@
                 UPD_NFDS(so->s);
 #else
-                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_OOB|FD_READ|FD_WRITE|FD_ACCEPT|FD_CONNECT);
-                if (rc == SOCKET_ERROR)
-                    goto socket_error;
-                continue; /* we're using the widest mask for event */
-#endif
-            }
-#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
-            rc = WSAEventSelect(so->s, NULL, 0);
-            if (rc == SOCKET_ERROR)
-                goto socket_error;
-#endif
+                goto engage_event;
+#endif
+            }
         }
 
@@ -573,18 +565,14 @@
                 UPD_NFDS(so->s);
 #else
-                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT);
+                rc = WSAEventSelect(so->s, VBOX_SOCKET_EVENT, FD_ALL_EVENTS);
                 if (rc == SOCKET_ERROR)
-                    goto socket_error;
-                continue;
-#endif
-            }
-#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
-            else
-            {
-                rc = WSAEventSelect(so->s, NULL, 0);
-                if (rc != SOCKET_ERROR)
-                    goto socket_error;
-            }
-#endif
+                {
+                    /* This should not happen */
+                    error = WSAGetLastError();
+                    LogRel(("WSAEventSelector (UDP) error %d (so=%x, socket=%s, event=%x)\n",
+                            error, so, so->s, VBOX_SOCKET_EVENT));
+                }
+#endif
+            }
         }
     }
@@ -608,4 +596,5 @@
     int error;
 #endif
+
     STAM_REL_PROFILE_START(&pData->StatPoll, a);
 
@@ -698,5 +687,8 @@
                 {
                     tcp_connect(pData, so);
-                    continue;
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
+                    if (!NetworkEvents.lNetworkEvents & FD_CLOSE)
+#endif
+                        continue;
                 }
 
@@ -706,4 +698,24 @@
                     tcp_output(pData, sototcpcb(so));
             }
+
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
+            /*
+             * Check for FD_CLOSE events.
+             */
+            if (NetworkEvents.lNetworkEvents & FD_CLOSE)
+            {
+                /*
+                 * drain the socket
+                 */
+                for (;;)
+                {
+                    ret = soread(pData, so);
+                    if (ret > 0)
+                        tcp_output(pData, sototcpcb(so));
+                    else
+                        break;
+                }
+            }
+#endif
 
             /*
@@ -752,11 +764,11 @@
                     tcp_input(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
                     /* continue; */
-                } else
+                }
+                else
                     ret = sowrite(pData, 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
+                 * XXX If we wrote something (a lot), there could be the need
+                 * for a window update. In the worst case, the remote will send
+                 * a window probe to get things going again.
                  */
             }
@@ -850,6 +862,6 @@
 }
 
-#define ETH_ALEN 6
-#define ETH_HLEN 14
+#define ETH_ALEN        6
+#define ETH_HLEN        14
 
 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
@@ -861,24 +873,24 @@
 struct ethhdr
 {
-        unsigned char   h_dest[ETH_ALEN];       /* destination eth addr */
-        unsigned char   h_source[ETH_ALEN];     /* source ether addr    */
-        unsigned short  h_proto;                /* packet type ID field */
+    unsigned char   h_dest[ETH_ALEN];           /* destination eth addr */
+    unsigned char   h_source[ETH_ALEN];         /* source ether addr    */
+    unsigned short  h_proto;                    /* packet type ID field */
 };
 
 struct arphdr
 {
-        unsigned short  ar_hrd;         /* format of hardware address   */
-        unsigned short  ar_pro;         /* format of protocol address   */
-        unsigned char   ar_hln;         /* length of hardware address   */
-        unsigned char   ar_pln;         /* length of protocol address   */
-        unsigned short  ar_op;          /* ARP opcode (command)         */
-
-         /*
-          *      Ethernet looks like this : This bit is variable sized however...
-          */
-        unsigned char           ar_sha[ETH_ALEN];       /* sender hardware address      */
-        unsigned char           ar_sip[4];              /* sender IP address            */
-        unsigned char           ar_tha[ETH_ALEN];       /* target hardware address      */
-        unsigned char           ar_tip[4];              /* target IP address            */
+    unsigned short  ar_hrd;             /* format of hardware address   */
+    unsigned short  ar_pro;             /* format of protocol address   */
+    unsigned char   ar_hln;             /* length of hardware address   */
+    unsigned char   ar_pln;             /* length of protocol address   */
+    unsigned short  ar_op;              /* ARP opcode (command)         */
+
+    /*
+     *      Ethernet looks like this : This bit is variable sized however...
+     */
+    unsigned char   ar_sha[ETH_ALEN];   /* sender hardware address      */
+    unsigned char   ar_sip[4];          /* sender IP address            */
+    unsigned char   ar_tha[ETH_ALEN];   /* target hardware address      */
+    unsigned char   ar_tip[4];          /* target IP address            */
 };
 
Index: trunk/src/VBox/Devices/Network/slirp/slirp.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp.h	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/slirp.h	(revision 14951)
@@ -23,10 +23,10 @@
 
 #ifndef CONFIG_QEMU
-#include "version.h"
+# include "version.h"
 #endif
 #define LOG_GROUP LOG_GROUP_DRV_NAT
 #include <VBox/log.h>
 #ifdef VBOX_WITH_SLIRP_MEMORY_CHECK
-#define RTMEM_WRAP_TO_EF_APIS
+# define RTMEM_WRAP_TO_EF_APIS
 #endif /* VBOX_WITH_SLIRP_MEMORY_CHECK */
 #include <iprt/mem.h>
@@ -40,15 +40,15 @@
 #include <VBox/types.h>
 
-# define malloc(a)       RTMemAlloc(a)
-# define free(a)         RTMemFree(a)
-# define realloc(a,b)    RTMemRealloc(a, b)
+#define malloc(a)       RTMemAlloc(a)
+#define free(a)         RTMemFree(a)
+#define realloc(a,b)    RTMemRealloc(a, b)
 
 #include "slirp_config.h"
 
-#ifdef _WIN32
-
-#ifndef _MSC_VER
-# include <inttypes.h>
-#endif
+#ifdef RT_OS_WINDOWS
+
+# ifndef _MSC_VER
+#  include <inttypes.h>
+# endif
 
 typedef uint8_t u_int8_t;
@@ -67,9 +67,12 @@
 # define ENETUNREACH WSAENETUNREACH
 # define ECONNREFUSED WSAECONNREFUSED
-#else
+
+#else /* !RT_OS_WINDOWS */
+
 # define ioctlsocket ioctl
 # define closesocket(s) close(s)
 # define O_BINARY 0
-#endif
+
+#endif /* !RT_OS_WINDOWS */
 
 #include <sys/types.h>
@@ -79,7 +82,7 @@
 
 #ifdef _MSC_VER
-#include <time.h>
+# include <time.h>
 #else /* !_MSC_VER */
-#include <sys/time.h>
+# include <sys/time.h>
 #endif /* !_MSC_VER */
 
@@ -125,5 +128,5 @@
 
 #ifndef HAVE_MEMMOVE
-#define memmove(x, y, z) bcopy(y, x, z)
+# define memmove(x, y, z) bcopy(y, x, z)
 #endif
 
@@ -145,6 +148,6 @@
 #endif
 
-#ifndef _WIN32
-#include <sys/uio.h>
+#ifndef RT_OS_WINDOWS
+# include <sys/uio.h>
 #endif
 
@@ -157,11 +160,11 @@
 #endif
 
-#ifndef _WIN32
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef RT_OS_WINDOWS
+# include <netinet/in.h>
+# include <arpa/inet.h>
 #endif
 
 #ifdef GETTIMEOFDAY_ONE_ARG
-#define gettimeofday(x, y) gettimeofday(x)
+# define gettimeofday(x, y) gettimeofday(x)
 #endif
 
@@ -183,5 +186,5 @@
 #include <fcntl.h>
 #ifndef NO_UNIX_SOCKETS
-#include <sys/un.h>
+# include <sys/un.h>
 #endif
 #include <signal.h>
@@ -189,6 +192,6 @@
 # include <sys/signal.h>
 #endif
-#ifndef _WIN32
-#include <sys/socket.h>
+#ifndef RT_OS_WINDOWS
+# include <sys/socket.h>
 #endif
 
@@ -209,25 +212,19 @@
 #endif
 
-#ifdef USE_PPP
-#include <ppp/slirppp.h>
-#endif
-
 #if defined(__STDC__) || defined(_MSC_VER)
-#include <stdarg.h>
-#else
-#include <varargs.h>
+# include <stdarg.h>
+#else
+# include <varargs.h>
 #endif
 
 #include <sys/stat.h>
 
-#if 1 /* ndef _MSC_VER */
 /* Avoid conflicting with the libc insque() and remque(), which
-   have different prototypes. */
+ * have different prototypes. */
 #define insque slirp_insque
 #define remque slirp_remque
-#endif /* !_MSC_VER */
 
 #ifdef HAVE_SYS_STROPTS_H
-#include <sys/stropts.h>
+# include <sys/stropts.h>
 #endif
 
@@ -250,9 +247,4 @@
 #include "misc.h"
 #include "ctl.h"
-#ifdef USE_PPP
-#include "ppp/pppd.h"
-#include "ppp/ppp.h"
-#endif
-
 #include "bootp.h"
 #include "tftp.h"
@@ -260,8 +252,8 @@
 #include "slirp_state.h"
 
-#undef PVM /* XXX Mac hack */
+#undef PVM /* XXX Mac OS X hack */
 
 #ifndef NULL
-#define NULL (void *)0
+# define NULL (void *)0
 #endif
 
@@ -318,5 +310,5 @@
 #endif
 
-#ifndef _WIN32
+#ifndef RT_OS_WINDOWS
 #include <netdb.h>
 #endif
@@ -382,21 +374,16 @@
 struct tcpcb *tcp_drop(PNATState, struct tcpcb *tp, int err);
 
-#ifdef USE_PPP
-#define MIN_MRU MINMRU
-#define MAX_MRU MAXMRU
-#else
 #define MIN_MRU 128
 #define MAX_MRU 16384
-#endif
-
-#ifndef _WIN32
-#define min(x,y) ((x) < (y) ? (x) : (y))
-#define max(x,y) ((x) > (y) ? (x) : (y))
-#endif
-
-#ifdef _WIN32
-#undef errno
-#define errno (WSAGetLastError())
-#endif
-
-#endif
+
+#ifndef RT_OS_WINDOWS
+# define min(x,y) ((x) < (y) ? (x) : (y))
+# define max(x,y) ((x) > (y) ? (x) : (y))
+#endif
+
+#ifdef RT_OS_WINDOWS
+# undef errno
+# define errno (WSAGetLastError())
+#endif
+
+#endif
Index: trunk/src/VBox/Devices/Network/slirp/slirp_config.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp_config.h	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/slirp_config.h	(revision 14951)
@@ -67,6 +67,6 @@
 /* Define if you have sys/ioctl.h */
 #undef HAVE_SYS_IOCTL_H
-#ifndef _WIN32
-#define HAVE_SYS_IOCTL_H
+#ifndef RT_OS_WINDOWS
+# define HAVE_SYS_IOCTL_H
 #endif
 
@@ -101,6 +101,6 @@
 /* Define if iovec needs to be declared */
 #undef DECLARE_IOVEC
-#ifdef _WIN32
-#define DECLARE_IOVEC
+#ifdef RT_OS_WINDOWS
+# define DECLARE_IOVEC
 #endif
 
@@ -113,6 +113,6 @@
 /* Define if you have sys/select.h */
 #undef HAVE_SYS_SELECT_H
-#ifndef _WIN32
-#define HAVE_SYS_SELECT_H
+#ifndef RT_OS_WINDOWS
+# define HAVE_SYS_SELECT_H
 #endif
 
@@ -122,6 +122,6 @@
 /* Define if you have arpa/inet.h */
 #undef HAVE_ARPA_INET_H
-#ifndef _WIN32
-#define HAVE_ARPA_INET_H
+#ifndef RT_OS_WINDOWS
+# define HAVE_ARPA_INET_H
 #endif
 
@@ -172,6 +172,6 @@
 /* Define if you have inet_aton */
 #undef HAVE_INET_ATON
-#ifndef _WIN32
-#define HAVE_INET_ATON
+#ifndef RT_OS_WINDOWS
+# define HAVE_INET_ATON
 #endif
 
@@ -199,6 +199,6 @@
 /* Define if you DON'T have unix-domain sockets */
 #undef NO_UNIX_SOCKETS
-#ifdef _WIN32
-#define NO_UNIX_SOCKETS
+#ifdef RT_OS_WINDOWS
+# define NO_UNIX_SOCKETS
 #endif
 
Index: trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 14951)
@@ -160,4 +160,15 @@
 #endif
         if (nn <= 0) {
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
+            /*
+             * Special case for WSAEnumNetworkEvents: If we receive 0 bytes that
+             * _could_ mean that the connection is closed. But we will receive an
+             * FD_CLOSE event later if the connection was _really_ closed. With
+             * www.youtube.com I see this very often. Closing the socket too early
+             * would be dangerous.
+             */
+                if (nn == 0)
+                        return 0;
+#endif
                 if (nn < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
                         return 0;
Index: trunk/src/VBox/Devices/Network/slirp/udp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 14925)
+++ trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 14951)
@@ -345,5 +345,5 @@
       closesocket(so->s);
       so->s=-1;
-#ifdef _WIN32
+#ifdef RT_OS_WINDOWS
       WSASetLastError(lasterrno);
 #else
