Permalink
Browse files

win32 porting.

  • Loading branch information...
1 parent eb8adc4 commit 03fb93ebf27f0b98c3fbcc616ce736129e747912 @mattn mattn committed Oct 5, 2009
Showing with 50 additions and 23 deletions.
  1. +17 −0 Makefile.msc
  2. +33 −23 mod_psgi.c
View
@@ -0,0 +1,17 @@
+MOD_PSGI_VERSION=0.0.1
+APACHE_ROOT=c:/progra~1/apache~1/apache2.2
+PERL_ROOT=c:/perl
+
+all : mod_psgi.so
+
+mod_psgi.obj : mod_psgi.c ppport.h
+ cl /MD /c mod_psgi.c -DMP_SYS_DL_DLOPEN=1 -DNDEBUG -DWIN32 -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX /I"$(PERL_ROOT)/lib/CORE" /I"$(APACHE_ROOT)/include" -DMOD_PSGI_VERSION=\"$(MOD_PSGI_VERSION)\"
+
+mod_psgi.so : mod_psgi.obj
+ link /DLL /OUT:mod_psgi.so mod_psgi.obj /LIBPATH:"$(APACHE_ROOT)/lib" "$(PERL_ROOT)/lib/core/perl510.lib" "$(APACHE_ROOT)/lib/libapr-1.lib" "$(APACHE_ROOT)/lib/libaprutil-1.lib" "$(APACHE_ROOT)/lib/libhttpd.lib"
+
+ppport.h :
+ perl -MDevel::PPPort -e "Devel::PPPort::WriteFile"
+
+install :
+ cp mod_psgi.so "$(APACHE_ROOT)/modules/."
View
@@ -13,16 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifdef _WIN32
+/* avoid to define duplicate definition of uid_t/gid_t in perl/CORE.h */
+#define uid_t _uid_t
+#define gid_t _gid_t
+#endif
#include "httpd.h"
#include "http_log.h"
#include "http_config.h"
#include "http_protocol.h"
#include "util_script.h"
#include "ap_config.h"
#include "ap_mpm.h"
+#include "apr_buckets.h"
#include "apr_strings.h"
#include "apr_hash.h"
+#ifdef _WIN32
+/* use perl's uid_t/gid_t. disable apr's macros. */
+#undef uid_t
+#undef gid_t
+#undef exit
+#endif
+
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
@@ -31,6 +44,12 @@
#define NEED_sv_2pv_flags
#include "ppport.h"
+#ifdef _WIN32
+/* no use perl compatible macros. it break apr's structure. ex: bucket->link */
+#undef link
+#undef read
+#endif
+
#define PSGI_HANDLER_NAME "psgi"
#ifdef DEBUG
@@ -300,7 +319,7 @@ static int output_body_ary(request_rec *r, AV *bodys)
I32 lastidx;
char *buf;
STRLEN len;
- apr_off_t clen;
+ apr_off_t clen = 0;
lastidx = av_len(bodys);
for (i = 0; i <= lastidx; i++) {
@@ -321,6 +340,7 @@ static int output_body_obj(request_rec *r, SV *obj, int type)
SV *buf_sv, *rs;
apr_off_t clen = 0;
STRLEN len;
+ dSP;
char *buf;
int count;
@@ -329,7 +349,6 @@ static int output_body_obj(request_rec *r, SV *obj, int type)
return HTTP_INTERNAL_SERVER_ERROR;
}
- dSP;
ENTER;
SAVETMPS;
SAVESPTR(PL_rs);
@@ -499,20 +518,16 @@ static int psgi_handler(request_rec *r)
return output_response(r, res);
}
-static int supported_mpm()
-{
- int result;
- ap_mpm_query(AP_MPMQ_IS_FORKED, &result);
- return result;
-}
-
static apr_status_t psgi_child_exit(void *p)
{
- PerlInterpreter *my_perl = perlinterp;
- PL_perl_destruct_level = 1;
- perl_destruct(my_perl);
- perl_free(my_perl);
- PERL_SYS_TERM();
+ if (perlinterp == NULL) {
+ PERL_SET_CONTEXT(perlinterp);
+ PL_perl_destruct_level = 1;
+ perl_destruct(perlinterp);
+ perl_free(perlinterp);
+ PERL_SYS_TERM();
+ perlinterp = NULL;
+ }
return OK;
}
@@ -578,15 +593,10 @@ psgi_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_
static void psgi_register_hooks(apr_pool_t *p)
{
- if (supported_mpm()) {
- ap_hook_pre_config(psgi_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_post_config(psgi_post_config, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_child_init(psgi_child_init, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_handler(psgi_handler, NULL, NULL, APR_HOOK_MIDDLE);
- } else {
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
- "mod_psgi only supports prefork mpm");
- }
+ ap_hook_pre_config(psgi_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_post_config(psgi_post_config, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_child_init(psgi_child_init, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_handler(psgi_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
static void *create_dir_config(apr_pool_t *p, char *path)

0 comments on commit 03fb93e

Please sign in to comment.