Diff
Not logged in

Differences From:

File src/main.c part of check-in [02f09cdd6c] - Add the http-port setting used to specify the default TCP/IP port for the built-in webserver. Ticket 7168128e09. by drh on 2008-11-09 16:23:30. [view]

To:

File src/main.c part of check-in [d8ceb4ad47] - The "ui" and "server" commands no longer quit if they cannot open TCP port 8080. They keep trying with consecutive ports until they find one that works - up to 100 ports. by drh on 2008-11-10 01:13:35. [view]

@@ -705,9 +705,9 @@
 ** The "ui" command automatically starts a web browser after initializing
 ** the web server.
 */
 void cmd_webserver(void){
-  int iPort;
+  int iPort, mxPort;
   const char *zPort;
   char *zBrowser;
   char *zBrowserCmd = 0;
 
@@ -722,11 +722,12 @@
   }else{
     db_open_repository(g.argv[2]);
   }
   if( zPort ){
-    iPort = atoi(zPort);
+    iPort = mxPort = atoi(zPort);
   }else{
     iPort = db_get_int("http-port", 8080);
+    mxPort = iPort+100;
   }
 #ifndef __MINGW32__
   /* Unix implementation */
   if( g.argv[1][0]=='u' ){
@@ -734,12 +735,12 @@
     zBrowser = db_get("web-browser", "firefox");
 #else
     zBrowser = db_get("web-browser", "open");
 #endif
-    zBrowserCmd = mprintf("%s http://localhost:%d/ &", zBrowser, iPort);
+    zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
   }
   db_close();
-  if( cgi_http_server(iPort, zBrowserCmd) ){
+  if( cgi_http_server(iPort, mxPort, zBrowserCmd) ){
     fossil_fatal("unable to listen on TCP socket %d", iPort);
   }
   g.httpIn = stdin;
   g.httpOut = stdout;
@@ -757,10 +758,10 @@
 #else
   /* Win32 implementation */
   if( g.argv[1][0]=='u' ){
     zBrowser = db_get("web-browser", "start");
-    zBrowserCmd = mprintf("%s http://127.0.0.1:%d/", zBrowser, iPort);
+    zBrowserCmd = mprintf("%s http://127.0.0.1:%%d/", zBrowser);
   }
   db_close();
-  win32_http_server(iPort, zBrowserCmd);
+  win32_http_server(iPort, mxPort, zBrowserCmd);
 #endif
 }