]> sjero.net Git - iperf/blobdiff - src/main.cpp
Remove Win32 Support
[iperf] / src / main.cpp
index f0bb7b235550227696f5ea9d411df19602eab91e..167aed5b977a06b771d723660770cc2fcdb62d96 100644 (file)
 #include "List.h"
 #include "util.h"
 
-#ifdef WIN32
-#include "service.h"
-#endif 
-
 /* -------------------------------------------------------------------
  * prototypes
  * ------------------------------------------------------------------- */
@@ -125,20 +121,6 @@ int main( int argc, char **argv ) {
     my_signal( SIGTERM, Sig_Interupt );
     my_signal( SIGINT,  Sig_Interupt );
 
-#ifndef WIN32
-    // Ignore broken pipes
-    signal(SIGPIPE,SIG_IGN);
-#else
-    // Start winsock
-    WSADATA wsaData;
-    int rc = WSAStartup( 0x202, &wsaData );
-    WARN_errno( rc == SOCKET_ERROR, "WSAStartup" );
-       if (rc == SOCKET_ERROR)
-               return 0;
-
-    // Tell windows we want to handle our own signals
-    SetConsoleCtrlHandler( sig_dispatcher, true );
-#endif
 
     // Initialize global mutexes and conditions
     Condition_Initialize ( &ReportCond );
@@ -168,25 +150,6 @@ int main( int argc, char **argv ) {
     // Check for either having specified client or server
     if ( ext_gSettings->mThreadMode == kMode_Client 
          || ext_gSettings->mThreadMode == kMode_Listener ) {
-#ifdef WIN32
-        // Start the server as a daemon
-        // Daemon mode for non-windows in handled
-        // in the listener_spawn function
-        if ( isDaemon( ext_gSettings ) ) {
-            CmdInstallService(argc, argv);
-            return 0;
-        }
-
-        // Remove the Windows service if requested
-        if ( isRemoveService( ext_gSettings ) ) {
-            // remove the service
-            if ( CmdRemoveService() ) {
-                fprintf(stderr, "IPerf Service is removed.\n");
-
-                return 0;
-            }
-        }
-#endif
         // initialize client(s)
         if ( ext_gSettings->mThreadMode == kMode_Client ) {
             client_init( ext_gSettings );
@@ -214,23 +177,6 @@ int main( int argc, char **argv ) {
         // neither server nor client mode was specified
         // print usage and exit
 
-#ifdef WIN32
-        // In Win32 we also attempt to start a previously defined service
-        // Starting in 2.0 to restart a previously defined service
-        // you must call iperf with "iperf -D" or using the environment variable
-        SERVICE_TABLE_ENTRY dispatchTable[] =
-        {
-            { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main},
-            { NULL, NULL}
-        };
-
-        // Only attempt to start the service if "-D" was specified
-        if ( !isDaemon(ext_gSettings) ||
-             // starting the service by SCM, there is no arguments will be passed in.
-             // the arguments will pass into Service_Main entry.
-             !StartServiceCtrlDispatcher(dispatchTable) )
-            // If the service failed to start then print usage
-#endif
         fprintf( stderr, usage_short, argv[0], argv[0] );
 
         return 0;
@@ -278,10 +224,6 @@ void Sig_Interupt( int inSigno ) {
  * ------------------------------------------------------------------- */
 
 void cleanup( void ) {
-#ifdef WIN32
-    // Shutdown Winsock
-    WSACleanup();
-#endif
     // clean up the list of clients
     Iperf_destroy ( &clients );
 
@@ -289,116 +231,3 @@ void cleanup( void ) {
     thread_destroy( );
 } // end cleanup
 
-#ifdef WIN32
-/*--------------------------------------------------------------------
- * ServiceStart
- *
- * each time starting the service, this is the entry point of the service.
- * Start the service, certainly it is on server-mode
- * 
- *-------------------------------------------------------------------- */
-VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) {
-    
-    // report the status to the service control manager.
-    //
-    if ( !ReportStatusToSCMgr(
-                             SERVICE_START_PENDING, // service state
-                             NO_ERROR,              // exit code
-                             3000) )                 // wait hint
-        goto clean;
-
-    thread_Settings* ext_gSettings = new thread_Settings;
-
-    // Initialize settings to defaults
-    Settings_Initialize( ext_gSettings );
-    // read settings from environment variables
-    Settings_ParseEnvironment( ext_gSettings );
-    // read settings from command-line parameters
-    Settings_ParseCommandLine( dwArgc, lpszArgv, ext_gSettings );
-
-    // report the status to the service control manager.
-    //
-    if ( !ReportStatusToSCMgr(
-                             SERVICE_START_PENDING, // service state
-                             NO_ERROR,              // exit code
-                             3000) )                 // wait hint
-        goto clean;
-
-    // if needed, redirect the output into a specified file
-    if ( !isSTDOUT( ext_gSettings ) ) {
-        redirect( ext_gSettings->mOutputFileName );
-    }
-
-    // report the status to the service control manager.
-    //
-    if ( !ReportStatusToSCMgr(
-                             SERVICE_START_PENDING, // service state
-                             NO_ERROR,              // exit code
-                             3000) )                 // wait hint
-        goto clean;
-    
-    // initialize client(s)
-    if ( ext_gSettings->mThreadMode == kMode_Client ) {
-        client_init( ext_gSettings );
-    }
-
-    // start up the reporter and client(s) or listener
-    {
-        thread_Settings *into = NULL;
-#ifdef HAVE_THREAD
-        Settings_Copy( ext_gSettings, &into );
-        into->mThreadMode = kMode_Reporter;
-        into->runNow = ext_gSettings;
-#else
-        into = ext_gSettings;
-#endif
-        thread_start( into );
-    }
-    
-    // report the status to the service control manager.
-    //
-    if ( !ReportStatusToSCMgr(
-                             SERVICE_RUNNING,       // service state
-                             NO_ERROR,              // exit code
-                             0) )                    // wait hint
-        goto clean;
-
-    clean:
-    // wait for other (client, server) threads to complete
-    thread_joinall();
-}
-
-
-//
-//  FUNCTION: ServiceStop
-//
-//  PURPOSE: Stops the service
-//
-//  PARAMETERS:
-//    none
-//
-//  RETURN VALUE:
-//    none
-//
-//  COMMENTS:
-//    If a ServiceStop procedure is going to
-//    take longer than 3 seconds to execute,
-//    it should spawn a thread to execute the
-//    stop code, and return.  Otherwise, the
-//    ServiceControlManager will believe that
-//    the service has stopped responding.
-//    
-VOID ServiceStop() {
-#ifdef HAVE_THREAD
-    Sig_Interupt( 1 );
-#else
-    sig_exit(1);
-#endif
-}
-
-#endif
-
-
-
-
-