Index: trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp
===================================================================
--- trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp	(revision 54729)
+++ trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp	(revision 54730)
@@ -1,10 +1,9 @@
 /* $Id$ */
 /** @file
- * VBoxNetDHCP - DHCP Service for connecting to IntNet.
+ * VBoxNetBaseService - common services for VBoxNetDHCP and VBoxNetNAT.
  */
-/** @todo r=bird: Cut&Past rules... Please fix DHCP refs! */
 
 /*
- * Copyright (C) 2009-2011 Oracle Corporation
+ * Copyright (C) 2009-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -172,5 +171,5 @@
      * Close the interface connection.
      */
-    if (m != NULL)
+    if (m)
     {
         shutdown();
@@ -228,14 +227,13 @@
 {
     /**
-     * If child class need Main we start receving thread which calls doReceiveLoop and enter to event polling loop
-     * and for the rest clients we do receiving on the current (main) thread.
+     * If the child class needs Main we start the receving thread which calls
+     * doReceiveLoop and enter to event polling loop. For other clients we do
+     * receiving on the current (main) thread.
      */
     if (isMainNeeded())
         return startReceiveThreadAndEnterEventLoop();
-    else
-    {
-        doReceiveLoop();
-        return VINF_SUCCESS;
-    }
+
+    doReceiveLoop();
+    return VINF_SUCCESS;
 }
 
@@ -341,4 +339,5 @@
 
             default:
+            {
                 int rc1 = parseOpt(rc, Val);
                 if (RT_FAILURE(rc1))
@@ -348,4 +347,6 @@
                     return rc;
                 }
+                break;
+            }
         }
     }
@@ -464,5 +465,5 @@
     {
         int rc = abortWait();
-        AssertRC(rc);
+        AssertRC(rc == VINF_SUCCESS || rc == VERR_SEM_DESTROYED);
         rc = m->m_EventQ->interruptEventQueueProcessing();
         if (RT_SUCCESS(rc))
@@ -564,5 +565,4 @@
     AssertRCReturnVoid(rc);
     LogFlowFuncLeave();
-
 }
 
@@ -691,6 +691,8 @@
          * Wait for a packet to become available.
          */
-        /* 2. waiting for request for */
         rc = waitForIntNetEvent(2000);
+        if (rc == VERR_SEM_DESTROYED)
+            break;
+
         if (RT_FAILURE(rc))
         {
@@ -700,5 +702,5 @@
                 continue;
             }
-            LogRel(("VBoxNetNAT: waitForIntNetEvent returned %Rrc\n", rc));
+            LogRel(("VBoxNetBaseService: waitForIntNetEvent returned %Rrc\n", rc));
             AssertRCReturnVoid(rc);
         }
@@ -708,51 +710,50 @@
          */
         PCINTNETHDR pHdr;
-
         while ((pHdr = IntNetRingGetNextFrameToRead(pRingBuf)) != NULL)
         {
             uint8_t const u8Type = pHdr->u8Type;
-            size_t         cbFrame = pHdr->cbFrame;
+            size_t        cbFrame = pHdr->cbFrame;
             switch (u8Type)
             {
-
                 case INTNETHDR_TYPE_FRAME:
+                {
+                    void *pvFrame = IntNetHdrGetFramePtr(pHdr, m->m_pIfBuf);
+                    rc = processFrame(pvFrame, cbFrame);
+                    if (RT_FAILURE(rc) && rc == VERR_IGNORED)
                     {
-                        void *pvFrame = IntNetHdrGetFramePtr(pHdr, m->m_pIfBuf);
-                        rc = processFrame(pvFrame, cbFrame);
-                        if (RT_FAILURE(rc) && rc == VERR_IGNORED)
-                        {
-                            /* XXX: UDP + ARP for DHCP */
-                            VBOXNETUDPHDRS Hdrs;
-                            size_t  cb;
-                            void   *pv = VBoxNetUDPMatch(m->m_pIfBuf, RTNETIPV4_PORT_BOOTPS, &m->m_MacAddress,
-                                                         VBOXNETUDP_MATCH_UNICAST | VBOXNETUDP_MATCH_BROADCAST
-                                                         | VBOXNETUDP_MATCH_CHECKSUM
-                                                         | (m->m_cVerbosity > 2 ? VBOXNETUDP_MATCH_PRINT_STDERR : 0),
-                                                         &Hdrs, &cb);
-                            if (pv && cb)
-                                processUDP(pv, cb);
-                            else
-                                VBoxNetArpHandleIt(m->m_pSession, m->m_hIf, m->m_pIfBuf, &m->m_MacAddress, m->m_Ipv4Address);
-                        }
+                        /* XXX: UDP + ARP for DHCP */
+                        VBOXNETUDPHDRS Hdrs;
+                        size_t  cb;
+                        void   *pv = VBoxNetUDPMatch(m->m_pIfBuf, RTNETIPV4_PORT_BOOTPS, &m->m_MacAddress,
+                                                       VBOXNETUDP_MATCH_UNICAST
+                                                     | VBOXNETUDP_MATCH_BROADCAST
+                                                     | VBOXNETUDP_MATCH_CHECKSUM
+                                                     | (m->m_cVerbosity > 2 ? VBOXNETUDP_MATCH_PRINT_STDERR : 0),
+                                                     &Hdrs, &cb);
+                        if (pv && cb)
+                            processUDP(pv, cb);
+                        else
+                            VBoxNetArpHandleIt(m->m_pSession, m->m_hIf, m->m_pIfBuf, &m->m_MacAddress, m->m_Ipv4Address);
                     }
                     break;
+                }
                 case INTNETHDR_TYPE_GSO:
-                  {
-                      PCPDMNETWORKGSO pGso = IntNetHdrGetGsoContext(pHdr, m->m_pIfBuf);
-                      rc = processGSO(pGso, cbFrame);
-                      if (RT_FAILURE(rc) && rc == VERR_IGNORED)
-                          break;
-                  }
-                  break;
+                {
+                    PCPDMNETWORKGSO pGso = IntNetHdrGetGsoContext(pHdr, m->m_pIfBuf);
+                    rc = processGSO(pGso, cbFrame);
+                    if (RT_FAILURE(rc) && rc == VERR_IGNORED)
+                        break;
+                    break;
+                }
+
                 case INTNETHDR_TYPE_PADDING:
                     break;
+
                 default:
                     break;
             }
             IntNetRingSkipFrame(&m->m_pIfBuf->Recv);
-
         } /* loop */
     }
-
 }
 
@@ -768,5 +769,5 @@
                             128 * _1K, /* stack size */
                             RTTHREADTYPE_IO, /* type */
-                            0, /* flags, @todo: waitable ?*/
+                            RTTHREADFLAGS_WAITABLE, /* flags */
                             "RECV");
     AssertRCReturn(rc, rc);
@@ -822,5 +823,4 @@
         va_end(vaCopy);
     }
-
 }
 
