2009/10/05

spiritlooseさんがPSGIなapacheモジュールを書いてくれたのでWindowsにポーティングしてみた。
mod_psgi を実装してみた - spiritlooseのはてなダイアリー

PSGI を実装したApache2モジュール。

http://d.hatena.ne.jp/spiritloose/20091002/1254467284
ちょっと気持ち悪いpatchになるけど、一応動いている。
巷にあるライブラリなどではWindowsポーティングされた時にUN*Xライクな型を自前で定義している事があるんだけど、Apacheモジュールのapr.hなんかや、Perlなんかでuid_t/gid_t/pid_tなんかが定義されている事が多い。

apr.h
typedef int uid_t;

perl.h
typedef long uid_t;

もちろんこのヘッダを同時に読み込むとエラーになるんですが、こういう場合に私がよく使う手として
#define uid_t _uid_t
#include <apr.h>
#undef uid_t
#include <perl.h>
てな具合に前の宣言を逃してやって、後の宣言を有効に出来る。今回はこの気持ち悪いhackを使ってWindowsにポーティングしました。

Commit 03fb93ebf27f0b98c3fbcc616ce736129e747912 to mattn's mod_psgi - GitHub
http://github.com/mattn/mod_psgi/commit/03fb93ebf27f0b98c3fbcc616ce736129e747912
今の所ご機嫌よく動いていて use strict;
use warnings;
my $count = 0;
my $handler = sub {
    my $content = "Hello World".$count++;
    return [ 200, [ "Content-Type" => "text/plain", "Content-Length" => length($content) ], [ $content ] ];
};
# vim:set ft=perl:
こんなPSGIなアプリもうまくちゃんとリクエスト毎にカウントアップされています。
もちろんpreforkだと同じ結果が現れる事がありますが
まだマージして頂いていないので、捨てコードになるかもしれませんが...

AWSWORD:perl:
Posted at 23:45 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.