1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
|
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
|
-
+
+
-
+
+
|
#define HTTP_SERVER_HAD_CHECKOUT 0x0008 /* Was a checkout open? */
#define HTTP_SERVER_REPOLIST 0x0010 /* Allow repo listing */
#endif /* INTERFACE */
/*
** Maximum number of child processes that we can have running
** at one time before we start slowing things down.
** at one time. Set this to 0 for "no limit".
*/
#ifndef FOSSIL_MAX_CONNECTIONS
#define MAX_PARALLEL 2
# define FOSSIL_MAX_CONNECTIONS 1000
#endif
/*
** Implement an HTTP server daemon listening on port iPort.
**
** As new connections arrive, fork a child and let child return
** out of this procedure call. The child will handle the request.
** The parent never returns from this procedure.
|
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
|
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
|
+
-
+
-
-
+
+
-
-
+
+
|
}else
#endif
if( system(zBrowser)<0 ){
fossil_warning("cannot start browser: %s\n", zBrowser);
}
}
while( 1 ){
#if FOSSIL_MAX_CONNECTIONS>0
if( nchildren>MAX_PARALLEL ){
while( nchildren>=FOSSIL_MAX_CONNECTIONS ){
/* Slow down if connections are arriving too fast */
sleep( nchildren-MAX_PARALLEL );
if( wait(0)>=0 ) nchildren--;
}
#endif
delay.tv_sec = 60;
delay.tv_usec = 0;
delay.tv_sec = 0;
delay.tv_usec = 100000;
FD_ZERO(&readfds);
assert( listener>=0 );
FD_SET( listener, &readfds);
select( listener+1, &readfds, 0, 0, &delay);
if( FD_ISSET(listener, &readfds) ){
lenaddr = sizeof(inaddr);
connection = accept(listener, (struct sockaddr*)&inaddr, &lenaddr);
|
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
|
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
|
+
+
-
-
-
+
+
+
+
+
+
+
|
if( fd!=1 ) nErr++;
if( !g.fAnyTrace ){
close(2);
fd = dup(connection);
if( fd!=2 ) nErr++;
}
close(connection);
g.nPendingRequest = nchildren+1;
return nErr;
}
}
}
/* Bury dead children */
if( nchildren ){
while( waitpid(0, 0, WNOHANG)>0 ){
nchildren--;
}
while(1){
int iStatus = 0;
pid_t x = waitpid(-1, &iStatus, WNOHANG);
if( x<=0 ) break;
nchildren--;
}
}
}
/* NOT REACHED */
fossil_exit(1);
#endif
/* NOT REACHED */
return 0;
}
|