Index: /trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 16561)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 16562)
@@ -622,5 +622,5 @@
              * See if we need a tcp_fasttimo
              */
-            if (    time_fasttimo == 0 
+            if (    time_fasttimo == 0
                     && so->so_tcpcb != NULL
                     && so->so_tcpcb->t_flags & TF_DELACK)
@@ -801,10 +801,10 @@
 
 #ifdef VBOX_WITH_SLIRP_MT
-            if (   so->so_state & SS_NOFDREF 
-                && so->so_deleted == 1) 
-            {   
+            if (   so->so_state & SS_NOFDREF
+                && so->so_deleted == 1)
+            {
                 struct socket *son, *sop = NULL;
                 QSOCKET_LOCK(tcb);
-                if (so->so_next != NULL) 
+                if (so->so_next != NULL)
                 {
                     if (so->so_next != &tcb)
@@ -813,5 +813,5 @@
                 }
                 if (    so->so_prev != &tcb
-                    && so->so_prev != NULL) 
+                    && so->so_prev != NULL)
                 {
                     SOCKET_LOCK(so->so_prev);
@@ -820,4 +820,5 @@
                 QSOCKET_UNLOCK(tcb);
                 remque(pData, so);
+                NSOCK_DEC();
                 SOCKET_UNLOCK(so);
                 SOCKET_LOCK_DESTROY(so);
@@ -1007,10 +1008,10 @@
          /* { */
 #ifdef VBOX_WITH_SLIRP_MT
-            if (   so->so_state & SS_NOFDREF 
-                && so->so_deleted == 1) 
-            {   
+            if (   so->so_state & SS_NOFDREF
+                && so->so_deleted == 1)
+            {
                 struct socket *son, *sop = NULL;
                 QSOCKET_LOCK(udb);
-                if (so->so_next != NULL) 
+                if (so->so_next != NULL)
                 {
                     if (so->so_next != &udb)
@@ -1019,5 +1020,5 @@
                 }
                 if (    so->so_prev != &udb
-                    && so->so_prev != NULL) 
+                    && so->so_prev != NULL)
                 {
                     SOCKET_LOCK(so->so_prev);
@@ -1026,4 +1027,5 @@
                 QSOCKET_UNLOCK(udb);
                 remque(pData, so);
+                NSOCK_DEC();
                 SOCKET_UNLOCK(so);
                 SOCKET_LOCK_DESTROY(so);
Index: /trunk/src/VBox/Devices/Network/slirp/slirp_state.h
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 16561)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 16562)
@@ -57,5 +57,5 @@
 {
         struct in_addr de_addr;
-        LIST_ENTRY(dns_entry) de_list; 
+        LIST_ENTRY(dns_entry) de_list;
 };
 LIST_HEAD(dns_list_head, dns_entry);
@@ -143,4 +143,18 @@
     struct socket icmp_socket;
     struct icmp_storage icmp_msg_head;
+# ifndef RT_OS_WINDOWS
+    /* counter of sockets needed for allocation enough room to
+     * process sockets with poll/epoll
+     *
+     * NSOCK_INC/DEC should be injected before every
+     * operation on socket queue (tcb, udb)
+     */
+    int nsock;
+#  define NSOCK_INC() do {pData->nsock++;} while (0)
+#  define NSOCK_DEC() do {pData->nsock--;} while (0)
+# else
+#  define NSOCK_INC() do {} while (0)
+#  define NSOCK_DEC() do {} while (0)
+# endif
 # ifdef RT_OS_WINDOWS
     void *pvIcmpBuffer;
@@ -345,5 +359,5 @@
     loop_end_ ## label ## _mt_nounlock:                                 \
     (so) = (sonext)
-    
+
 #define DO_TCP_OUTPUT(data, sotcb)                                      \
 do {                                                                    \
@@ -527,6 +541,6 @@
         }                                                               \
     }                                                                   \
-}while (0) 
-    
+}while (0)
+
 #else
 #define QSOCKET_LOCK(queue) do {} while (0)
Index: /trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 16561)
+++ /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 16562)
@@ -90,4 +90,5 @@
     if(so->so_next && so->so_prev)
         remque(pData, so);  /* crashes if so is not in a queue */
+        NSOCK_DEC();
     so->so_state = SS_NOFDREF; /* for debugging purposes */
 
@@ -378,5 +379,5 @@
         if (sb->sb_cc == 0)
         {
-            SOCKET_UNLOCK(so);    
+            SOCKET_UNLOCK(so);
             return 0;
         }
@@ -428,5 +429,5 @@
     if (nn < 0 && (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
     {
-        SOCKET_UNLOCK(so);    
+        SOCKET_UNLOCK(so);
         return 0;
     }
@@ -438,5 +439,5 @@
         sofcantsendmore(so);
         tcp_sockclosed(pData, sototcpcb(so));
-        SOCKET_UNLOCK(so);    
+        SOCKET_UNLOCK(so);
         return -1;
     }
@@ -466,5 +467,5 @@
         sofcantsendmore(so);
 
-    SOCKET_UNLOCK(so);    
+    SOCKET_UNLOCK(so);
     return nn;
 }
@@ -503,5 +504,5 @@
         QSOCKET_UNLOCK(udb);
 
-        if (!(m = m_get(pData))) 
+        if (!(m = m_get(pData)))
         {
             SOCKET_UNLOCK(so);
@@ -698,4 +699,5 @@
     QSOCKET_LOCK(tcb);
     insque(pData, so,&tcb);
+    NSOCK_INC();
     QSOCKET_UNLOCK(tcb);
 
Index: /trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/tcp_subr.c	(revision 16561)
+++ /trunk/src/VBox/Devices/Network/slirp/tcp_subr.c	(revision 16562)
@@ -356,5 +356,5 @@
     }
 /*  soisfdisconnecting(tp->t_socket); */
-    if (   tp 
+    if (   tp
         && tp->t_state >= TCPS_FIN_WAIT_2)
         soisfdisconnected(tp->t_socket);
@@ -500,5 +500,5 @@
     optlen = sizeof(int);
     status = getsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, &optlen);
-    if (status < 0) 
+    if (status < 0)
     {
         LogRel(("NAT: Error(%d) while getting RCV capacity\n", errno));
@@ -508,6 +508,6 @@
         LogRel(("NAT: old socket rcv size: %dKB\n", opt / 1024));
     opt *= 4;
-    status = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)); 
-    if (status < 0) 
+    status = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int));
+    if (status < 0)
     {
         LogRel(("NAT: Error(%d) while setting RCV capacity to (%d)\n", errno, opt));
@@ -516,5 +516,5 @@
     optlen = sizeof(int);
     status = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &opt, &optlen);
-    if (status < 0) 
+    if (status < 0)
     {
         LogRel(("NAT: Error(%d) while getting SND capacity\n", errno));
@@ -524,6 +524,6 @@
         LogRel(("NAT: old socket snd size: %dKB\n", opt / 1024));
     opt *= 4;
-    status = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(int)); 
-    if (status < 0) 
+    status = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(int));
+    if (status < 0)
     {
         LogRel(("NAT: Error(%d) while setting SND capacity to (%d)\n", errno, opt));
@@ -580,7 +580,8 @@
         return -1;
 
-    SOCKET_LOCK_CREATE(so); 
+    SOCKET_LOCK_CREATE(so);
     QSOCKET_LOCK(tcb);
     insque(pData, so, &tcb);
+    NSOCK_INC();
     QSOCKET_UNLOCK(tcb);
     return 0;
@@ -808,5 +809,5 @@
             if (   m->m_data[m->m_len-1] == '\0'
                 && lport != 0
-                && (so = solisten(pData, 0, so->so_laddr.s_addr, 
+                && (so = solisten(pData, 0, so->so_laddr.s_addr,
                                   htons(lport), SS_FACCEPTONCE)) != NULL)
                 m->m_len = sprintf(m->m_data, "%d", ntohs(so->so_fport))+1;
@@ -824,5 +825,5 @@
             if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3)
             {
-                if ((so = solisten(pData, 0, htonl(laddr), 
+                if ((so = solisten(pData, 0, htonl(laddr),
                                    htons(lport), SS_FACCEPTONCE)) == NULL)
                     return 1;
Index: /trunk/src/VBox/Devices/Network/slirp/udp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 16561)
+++ /trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 16562)
@@ -160,5 +160,5 @@
      *  handle TFTP
      */
-    if (   ntohs(uh->uh_dport) == TFTP_SERVER 
+    if (   ntohs(uh->uh_dport) == TFTP_SERVER
         && CTL_CHECK(ntohl(ip->ip_dst.s_addr), CTL_TFTP))
     {
@@ -391,4 +391,5 @@
             QSOCKET_LOCK(udb);
             insque(pData, so,&udb);
+            NSOCK_INC();
             QSOCKET_UNLOCK(udb);
         }
@@ -706,4 +707,5 @@
     QSOCKET_LOCK(udb);
     insque(pData, so,&udb);
+    NSOCK_INC();
     QSOCKET_UNLOCK(udb);
 
