Web サーバーを実装する C ライブラリを探した後、Mongoose について教えてもらいました。受信データと送信データを実際に処理するコールバック関数を呼び出すいくつかの例を使用して、実際に機能させました。私は Windows で使用し、Visual Studio 2008 でコンパイルおよびデバッグしています。
私はそれをセッションと呼び、それは次のとおりです。
int CHttpsCom::Session( void )
{
struct mg_context *ctx;
const char *options[] = {
"listening_ports", "443s",
#ifdef _DEBUG
"ssl_certificate", "c:\\temp\\cert.pem",
#else
"ssl_certificate", "cert.pem",
#endif
NULL
};
ctx = mg_start( &callback, NULL, options );
if( !ctx )
return 1;
//getchar(); // Wait until user hits "enter"
while ( LeaveIt == false );
Sleep(3500);// without this it won't work
mg_stop( ctx );
return 0;
}
私が気付いた例の 100% では、ほとんどの例で getchar を使用して、セッションの終了をコールバック実行の終了と同期させています。投稿メッセージを受け取った後に設定されるこの LeaveIt フラグがあります。上記の Sleep を使用しないと、ライブラリ内部でデッドロックが発生します。コールバックが終了するまでこの待機を処理するより良い方法はありますか?
ありがとう。