I have added a couple of changes to the Cygwin 1.x platform support
for the 1.3 branch. First of all this diff is against a recent cvs
tree. The patch applies cleanly to the current cvs tree.

What's new:

  * Supports now --enable-shared=max option for configure, which is
also used in src/helpers/binbuild.sh for the binary distribution. This
solves especially the mod_proxy compilation problem we had previosly.

  * Cygwin now has an additional configure rule CYGWIN_WINSOCK, which
enables to use Win32 native calls for the socket calls instead of
using POSIX.1 wrappers by the Cygwin emulation layer itself. This is
an performance gain of about 5-10%. Therefore we had to add a couple
of define statements in src/main/buff.c.

  * For accept mutexes we used previously fctnl, which seems to have a
cerious problem when using more then one Listen directive in
httpd.conf. Apache starts and serves on any port specified by Listen,
but does not shut down. Even using the Win32 task manager to kill the
parent httpd process did not suceed. We now use pthread as default
accept mutex mechanism, which works without any known problems.

  * Added #define wrapper for the timeout signal too, that is
different for Cygwin that for other Unixes to be more drastic on this
platform. We still encounter Keep-Alive hanging childs that do not go
away in the timeout limit. This seems to be a Cygwin OS layer problem,
still investigating.


The patch has been created with impact for other platforms in mind. So
there are no changes in behaviour for other OSs.

Here are the changes in the current 1.3 cvs tree:

  * src/Configuration.tmpl: added Rule CYGWIN_WINSOCK for Win32 native
socket support.
  * src/Configure: added checking for RULE_CYGWIN_WINSOCK in the
Cygwin case block. Changed OS_MODULE_INCLUDE to use the full
(relative) path, so we can find the additional Makefile in other
source directories too (i.e proxy).
  * src/helpers/binbuild.sh: Added pre-defined MAKERUN statement
(suggested by Martin) to make env safe. Cygwin needs to re-run "make"
due to the fact that linking shared modules requires to have the
shared core DLL present, which is in fact linked at the end.
  * src/helpers/install.sh: add .exe extension for executables on
Cygwin. Martin, this should be a satisfying solution and should work
for any OS (if any would use the script and .exe extensions)?!
  * src/include/ap_config.h: changed default to
USE_PTHREAD_SERIALIZED_ACCEPT.
  * src/main/buff.c: added #defines to include native Win32 socket
calls if CYGWIN_WINSOCK rule is used.
  * src/main/http_main.c: exluded pthread_mutexattr_setpshared() call
for Cygwin, which seems to have OS specific problems. Added aditional
#defines for CYGWIN_WINSOCK. Added wrapper #define SIG_TIMEOUT_KILL to
handle which signal is used for timeout shutdowns of the childs.
  * src/modules/proxy/Makefile.tmpl: the libproxy.dll Makefile rule
has been hard-coded for OS/2, which is not a good idea, Cygwin
produces also a libproxy.dll version, but with other tools, so we have
to introduce an if statement here to see on which OS we are.
  * src/modules/standard/Makefile.Cygwin: added an "empty" rule to
satisfy OS/2 specific dependancies. This won't hurt the build process.
Removing the shared core import library if existing to update
everything inside and use a dummy file to indicate if the re-run
warning has to be displayed. It should be displayed only once, in
order to not annoy the user.
  * src/os/cygwin/os.h: added necessary declarations for the
CYGWIN_WINSOCK rule.


Can someone, maybe Martin and Lars review the code and commit to cvs,
please?!


Stipe

[EMAIL PROTECTED]
-------------------------------------------------------------------
Wapme Systems AG

M�nsterstr. 248
40470 D�sseldorf

Tel: +49-211-74845-0
Fax: +49-211-74845-299

E-Mail: [EMAIL PROTECTED]
Internet: http://www.wapme-systems.de
-------------------------------------------------------------------
wapme.net - wherever you are
diff -ur apache-1.3/src/Configuration.tmpl apache-1.3-cygwin/src/Configuration.tmpl
--- apache-1.3/src/Configuration.tmpl   Mon Oct  8 17:52:12 2001
+++ apache-1.3-cygwin/src/Configuration.tmpl    Sat Nov 10 16:48:46 2001
@@ -173,6 +173,13 @@
 #  Rule EXPAT=default   : If Expat can be found at the system or
 #                         in lib/expat-lite, use it; otherwise
 #                         skip it
+# 
+# CYGWIN_WINSOCK: 
+#  Use Win32 API system calls for socket communication instead 
+#  of Cygwin's POSIX.1 wrappers. This avoids the Cygwin specific
+#  implementation and uses the Win32 native calls. Should be faster
+#  and more reliable for high-load systems.  
+# 
 
 Rule SOCKS4=no
 Rule SOCKS5=no
@@ -180,6 +187,7 @@
 Rule IRIXN32=yes
 Rule PARANOID=no
 Rule EXPAT=default
+Rule CYGWIN_WINSOCK=no 
 
 # DEV_RANDOM:
 #  Note: this rule is only used when compiling mod_auth_digest.
diff -ur apache-1.3/src/Configure apache-1.3-cygwin/src/Configure
--- apache-1.3/src/Configure    Mon Oct  8 20:59:36 2001
+++ apache-1.3-cygwin/src/Configure     Thu Dec 13 21:11:10 2001
@@ -235,6 +235,7 @@
 RULE_IRIXN32=`./helpers/CutRule IRIXN32 $file`
 RULE_PARANOID=`./helpers/CutRule PARANOID $file`
 RULE_EXPAT=`./helpers/CutRule EXPAT $file`
+RULE_CYGWIN_WINSOCK=`./helpers/CutRule CYGWIN_WINSOCK $file` 
 RULE_SHARED_CORE=`./helpers/CutRule SHARED_CORE $file`
 RULE_SHARED_CHAIN=`./helpers/CutRule SHARED_CHAIN $file`
 
@@ -849,6 +850,11 @@
        DEF_WANTHSREGEX=yes
        DBM_LIB="-lgdbm"
        LIBS="$LIBS -lcrypt $DBM_LIB"
+       if [ "x$RULE_CYGWIN_WINSOCK" = "xyes" ]; then 
+           CFLAGS="$CFLAGS -DCYGWIN_WINSOCK" 
+           LIBS="$LIBS -lwsock32" 
+       fi 
+
        ;;
     *atheos*)
        DEF_WANTSREGEX=yes
@@ -1419,7 +1425,7 @@
            LIBS_SHLIB='$(EXTRA_LIBS)'
            SHARED_CORE_EP='lib$(TARGET).ep'
            SHCORE_IMPLIB='lib$(TARGET).dll'
-           OS_MODULE_INCLUDE='Makefile.Cygwin'
+           OS_MODULE_INCLUDE='$(SRCDIR)/modules/standard/Makefile.Cygwin'
            ;;
        *)
            ##  ok, no known explict support for shared objects
diff -ur apache-1.3/src/helpers/binbuild.sh apache-1.3-cygwin/src/helpers/binbuild.sh
--- apache-1.3/src/helpers/binbuild.sh  Thu Oct 18 15:25:26 2001
+++ apache-1.3-cygwin/src/helpers/binbuild.sh   Sat Nov 10 17:00:42 2001
@@ -7,10 +7,11 @@
 # See http://www.apache.org/docs/LICENSE
 
 OS=`src/helpers/GuessOS`
+MAKERERUN="no"
 case "x$OS" in
   x*390*) CONFIGPARAM="--with-layout=BinaryDistribution --enable-module=most";;
-  *cygwin*) CONFIGPARAM="--with-layout=BinaryDistribution --enable-module=most \
-                         --enable-rule=SHARED_CORE --libexecdir=bin";;
+  *cygwin*) CONFIGPARAM="--with-layout=BinaryDistribution --enable-module=most 
+--enable-shared=max"
+            MAKERERUN="yes";;
       *) CONFIGPARAM="--with-layout=BinaryDistribution --enable-module=most 
--enable-shared=max";;
 esac
 APDIR=`pwd`
@@ -55,6 +56,7 @@
   rm -rf bindist install-bindist.sh *.bindist
   echo "----------------------------------------------------------------------" && \
   make && \
+  if [ "x$MAKERERUN" = "xyes" ]; then make; fi && \
   echo "----------------------------------------------------------------------" && \
   make install-quiet root="bindist/" && \
   echo "----------------------------------------------------------------------" && \
diff -ur apache-1.3/src/helpers/install.sh apache-1.3-cygwin/src/helpers/install.sh
--- apache-1.3/src/helpers/install.sh   Tue Jun 12 10:24:54 2001
+++ apache-1.3-cygwin/src/helpers/install.sh    Sat Nov 10 17:07:48 2001
@@ -88,13 +88,9 @@
 fi
 
 #  Check if we need to add an executable extension (such as ".exe") 
-#  on specific OS to src and dst
-if [ -f "$src.exe" ]; then
-  if [ -f "$src" ]; then
-    : # Cygwin [ test ] is too stupid to do [ -f "$src.exe" ] && [ ! -f "$src" ]
-  else
-    ext=".exe"
-  fi
+#  on specific OS to src and dst.
+if [ -f "$src.exe" ] && [ ! -f "$src." ] then
+  ext=".exe"
 fi
 src="$src$ext"
 dst="$dst$ext"
diff -ur apache-1.3/src/include/ap_config.h apache-1.3-cygwin/src/include/ap_config.h
--- apache-1.3/src/include/ap_config.h  Tue Oct  9 19:29:46 2001
+++ apache-1.3-cygwin/src/include/ap_config.h   Tue Jan  1 16:07:48 2002
@@ -1002,7 +1012,11 @@
 #define USE_MMAP_FILES
 #define HAVE_SYSLOG 1
 #define HAVE_FCNTL_SERIALIZED_ACCEPT
+#define HAVE_PTHREAD_SERIALIZED_ACCEPT
 #define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
+#if !defined(USE_FNCTL_SERIALIZED_ACCEPT)
+#define USE_PTHREAD_SERIALIZED_ACCEPT
+#endif
 
 
 #else
diff -ur apache-1.3/src/main/buff.c apache-1.3-cygwin/src/main/buff.c
--- apache-1.3/src/main/buff.c  Mon Jan 15 17:04:56 2001
+++ apache-1.3-cygwin/src/main/buff.c   Tue Jan  1 15:12:49 2002
@@ -121,7 +122,7 @@
  * futher I/O will be done
  */
 
-#if defined(WIN32) || defined(NETWARE)
+#if defined(WIN32) || defined(NETWARE) || defined(CYGWIN_WINSOCK) 
 
 /*
   select() sometimes returns 1 even though the write will block. We must work around 
this.
@@ -283,7 +282,7 @@
 {
     int rv;
 
-#if defined (WIN32) || defined(NETWARE)
+#if defined (WIN32) || defined(NETWARE) || defined(CYGWIN_WINSOCK) 
     if (fb->flags & B_SOCKET) {
        rv = recvwithtimeout(fb->fd_in, buf, nbyte, 0);
        if (rv == SOCKET_ERROR)
@@ -1465,7 +1477,7 @@
        rc1 = ap_bflush(fb);
     else
        rc1 = 0;
-#if defined(WIN32) || defined(NETWARE)
+#if defined(WIN32) || defined(NETWARE) || defined(CYGWIN_WINSOCK) 
     if (fb->flags & B_SOCKET) {
        rc2 = ap_pclosesocket(fb->pool, fb->fd);
        if (fb->fd_in != fb->fd) {
@@ -1475,7 +1487,7 @@
            rc3 = 0;
        }
     }
-#ifndef NETWARE
+#if !defined(NETWARE) && !defined(CYGWIN_WINSOCK) 
     else if (fb->hFH != INVALID_HANDLE_VALUE) {
         rc2 = ap_pcloseh(fb->pool, fb->hFH);
         rc3 = 0;
@@ -1500,7 +1512,7 @@
        else {
            rc3 = 0;
        }
-#if defined(WIN32) || defined (BEOS) || defined(NETWARE)
+#if defined(WIN32) || defined (BEOS) || defined(NETWARE) || defined(CYGWIN_WINSOCK) 
     }
 #endif
 
diff -ur apache-1.3/src/main/http_main.c apache-1.3-cygwin/src/main/http_main.c
--- apache-1.3/src/main/http_main.c     Wed Oct 17 14:45:30 2001
+++ apache-1.3-cygwin/src/main/http_main.c      Tue Jan  1 16:05:19 2002
@@ -662,11 +662,17 @@
        perror("pthread_mutexattr_init");
        exit(APEXIT_INIT);
     }
+    /*
+     * Cygwin has problems with this pthread call claiming that these 
+     * are "Invalid arguements", Stipe Tolj <[EMAIL PROTECTED]>
+     */
+#if !defined(CYGWIN)
     if ((errno = pthread_mutexattr_setpshared(&mattr,
                                                PTHREAD_PROCESS_SHARED))) {
        perror("pthread_mutexattr_setpshared");
        exit(APEXIT_INIT);
     }
+#endif
     if ((errno = pthread_mutex_init(accept_mutex, &mattr))) {
        perror("pthread_mutex_init");
        exit(APEXIT_INIT);
@@ -1494,7 +1570,7 @@
 #ifndef NETWARE
 static APACHE_TLS void (*volatile alarm_fn) (int) = NULL;
 #endif
-#ifdef WIN32
+#if defined(WIN32) || defined(CYGWIN_WINSOCK) 
 static APACHE_TLS unsigned int alarm_expiry_time = 0;
 #endif /* WIN32 */
 
@@ -1554,7 +1630,7 @@
 }
 
 
-#if defined(WIN32) || defined(NETWARE)
+#if defined(WIN32) || defined(NETWARE) || defined(CYGWIN_WINSOCK) 
 API_EXPORT(int) ap_check_alarm(void)
 {
 #ifdef NETWARE
@@ -3987,6 +4067,9 @@
 #ifdef AP_ACCEPTFILTER_OFF
     printf(" -D AP_ACCEPTFILTER_OFF\n");
 #endif
+#ifdef CYGWIN_WINSOCK 
+    printf(" -D CYGWIN_WINSOCK\n"); 
+#endif 
 
 /* This list displays the compiled-in default paths: */
 #ifdef HTTPD_ROOT
@@ -4152,11 +4235,15 @@
 #endif
 #endif
     signal(SIGALRM, alrm_handler);
-#ifdef TPF
+#ifdef CYGWIN
+    signal(SIGUSR2, alrm_handler);
+#endif
+#if defined(TPF) || defined(CYGWIN)
     signal(SIGHUP, just_die);
     signal(SIGTERM, just_die);
     signal(SIGUSR1, just_die);
-#endif /* TPF */
+#endif /* TPF || CYGWIN */
+
 
 #ifdef OS2
 /* Stop Ctrl-C/Ctrl-Break signals going to child processes */
@@ -4672,13 +4759,16 @@
  * is greater then ap_daemons_max_free. Usually we will use SIGUSR1
  * to gracefully shutdown, but unfortunatly some OS will need other 
  * signals to ensure that the child process is terminated and the 
- * scoreboard pool is not growing to infinity. This effect has been
+ * scoreboard pool is not growing to infinity. Also set the signal we
+ * use to kill of childs that exceed timeout. This effect has been
  * seen at least on Cygwin 1.x. -- Stipe Tolj <[EMAIL PROTECTED]>
  */
 #if defined(CYGWIN)
 #define SIG_IDLE_KILL SIGKILL
+#define SIG_TIMEOUT_KILL SIGUSR2
 #else
 #define SIG_IDLE_KILL SIGUSR1
+#define SIG_TIMEOUT_KILL SIGALRM
 #endif
 
 static void perform_idle_server_maintenance(void)
@@ -4750,7 +4840,7 @@
                else if (ps->last_rtime + ss->timeout_len < now) {
                    /* no progress, and the timeout length has been exceeded */
                    ss->timeout_len = 0;
-                   kill(ps->pid, SIGALRM);
+                   kill(ps->pid, SIG_TIMEOUT_KILL);
                }
            }
 #endif
diff -ur apache-1.3/src/modules/proxy/Makefile.tmpl 
apache-1.3-cygwin/src/modules/proxy/Makefile.tmpl
--- apache-1.3/src/modules/proxy/Makefile.tmpl  Thu Jun 22 23:22:36 2000
+++ apache-1.3-cygwin/src/modules/proxy/Makefile.tmpl   Sat Nov 10 17:02:58 2001
@@ -21,10 +21,18 @@
        rm -f $@
        $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(OBJS_PIC) $(LIBS_SHLIB)
 
-libproxy.dll: $(OBJS_PIC) mod_proxy.def
-       $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $* $(OBJS_PIC) $(LIBS_SHLIB)
-       emxbind -b -q -s -h0 -dmod_proxy.def $* && \
-       rm $*
+libproxy.dll: $(OBJS_PIC) mod_proxy.def 
+       if [ "x$(OS)" = "xCygwin" ]; then \
+           rm -f $@; \
+           if [ -f "$(SRCDIR)/$(SHCORE_IMPLIB)" ]; then \
+           $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $*.dll $(OBJS_PIC) $(LIBS_SHLIB) \
+           $(SRCDIR)/$(SHCORE_IMPLIB) $(LIBS1); \
+           fi \
+       else \
+           $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $* $(OBJS_PIC) $(LIBS_SHLIB); \
+           emxbind -b -q -s -h0 -dmod_proxy.def $* && \
+           rm $*; \
+       fi
 
 .SUFFIXES: .o .lo .dll
 
diff -ur apache-1.3/src/modules/standard/Makefile.Cygwin 
apache-1.3-cygwin/src/modules/standard/Makefile.Cygwin
--- apache-1.3/src/modules/standard/Makefile.Cygwin     Fri Sep 28 11:29:02 2001
+++ apache-1.3-cygwin/src/modules/standard/Makefile.Cygwin      Sat Nov 10 17:05:50 
+2001
@@ -28,23 +28,30 @@
         $(SRCDIR)/$(SHCORE_IMPLIB) $(LIBS1)
 endef
 
+%.def : %.c
+       touch $*.def
+
 %.lo : %.c
        $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $< && mv $*.o $*.lo
 
 %.dll : %.lo
        @if [ -f "$(SRCDIR)/$(SHCORE_IMPLIB)" ]; then \
+        rm -f $(SRCDIR)/$(SHCORE_IMPLIB).$$; \
         echo $(shared_dll); \
                $(shared_dll); \
        else \
-           echo "+--------------------------------------------------------+"; \
-               echo "| There is no shared core 'libhttpd.dll' available!      |"; \
-               echo "|                                                        |"; \
-               echo "| This is obviously your first 'make' run with configure |"; \
-               echo "| flag SHARED_CORE enabled and shared modules.           |"; \
-               echo "|                                                        |"; \
-               echo "| You will have to re-run 'make' after this run builds   |"; \
-               echo "| the required shared import library!                    |"; \
-           echo "+--------------------------------------------------------+"; \
-        sleep 10; \
+        if [ ! -f "$(SRCDIR)/$(SHCORE_IMPLIB).$$" ]; then \
+             echo "+--------------------------------------------------------+"; \
+                 echo "| There is no shared core 'libhttpd.dll' available!      |"; \
+                 echo "|                                                        |"; \
+                 echo "| This is obviously your first 'make' run with configure |"; \
+                 echo "| flag SHARED_CORE enabled and shared modules.           |"; \
+                 echo "|                                                        |"; \
+                 echo "| You will have to re-run 'make' after this run builds   |"; \
+                 echo "| the required shared import library!                    |"; \
+                 echo "+--------------------------------------------------------+"; \
+                 sleep 10; \
+          touch $(SRCDIR)/$(SHCORE_IMPLIB).$$; \
+        fi; \
        fi;
 
diff -ur apache-1.3/src/os/cygwin/os.h apache-1.3-cygwin/src/os/cygwin/os.h
--- apache-1.3/src/os/cygwin/os.h       Thu Sep 27 18:12:04 2001
+++ apache-1.3-cygwin/src/os/cygwin/os.h        Sat Nov 10 16:57:04 2001
@@ -88,6 +88,25 @@
 #define PLATFORM "Cygwin"
 #endif
 
+/* 
+ * Define winsock.h and winsock2.h stuff taken from Win32 API in case we  
+ * want to do socket communication in Win32 native way rather then using 
+ * Cygwin's POSIX wrapper to the native ones. These are needed for 
+ * main/buff.c and main/http_main.c. They are linked against libwsock32.a 
+ * for the import declarations of the corresponding Win32 native DLLs. 
+ */ 
+#ifdef CYGWIN_WINSOCK 
+#define WSAEWOULDBLOCK (10035) 
+#define SOCKET_ERROR (-1) 
+ 
+#define WIN32API_IMPORT(type)  __declspec(dllimport) type __stdcall 
+ 
+WIN32API_IMPORT(int) WSAGetLastError(void); 
+WIN32API_IMPORT(int) WSASetLastError(int); 
+WIN32API_IMPORT(int) ioctlsocket(unsigned int, long, unsigned long *); 
+WIN32API_IMPORT(void) Sleep(unsigned int); 
+#endif /* CYGWIN_WINSOCK */ 
+
 /*
  * This file in included in all Apache source code. It contains definitions
  * of facilities available on _this_ operating system (HAVE_* macros),

Reply via email to