3

リクエストが何であれ、引数として渡されたファイルをHTTP経由で送信する単純なmoongoseベースのWebサーバーを開発していますが、リクエストごとにスタックオーバーフローエラーが発生します。

これが私のコードです:

#include <stdio.h>
#include <string.h>
#include "mongoose.h"

// file path
char *path;

static void *callback(enum mg_event event, struct mg_connection *conn) 
{
    const struct mg_request_info *request_info = mg_get_request_info(conn);
    mg_send_file(conn, path);

    return "";
}

int main(int argc,char *argv[]) 
{    
    struct mg_context *ctx;
    const char *options[] = {"listening_ports", "8081", NULL};

    // registers file
    path = argv[1];
    ctx = mg_start(&callback, NULL, options);
    printf("%s", path);
    getchar();  // Wait until user hits "enter"
    mg_stop(ctx);

    return 0;
}

プロジェクトのビルドにVisual Studio 2010を使用しています

このエラーの原因について何か考えがある人はいますか?

4

2 に答える 2

1

定義上、未定義の動作であるコールバック関数に戻り値を割り当てていません。void *は と同義ではないため、コールバックの適切な戻り値の要件を確認してくださいvoid。戻り値はコールバック イベントに依存していると確信していましたが、それについては引用しないでください。(くそ… 遅すぎる)。

提供されるコールバック関数の目的と責任を説明するマングースヘッダー(少なくとも私がアクセスできるバージョン)から取得しましたmg_start()

// Prototype for the user-defined function. Mongoose calls this function
// on every event mentioned above.
//
// Parameters:
//   event: which event has been triggered.
//   conn: opaque connection handler. Could be used to read, write data to the
//         client, etc. See functions below that accept "mg_connection *".
//   request_info: Information about HTTP request.
//
// Return:
//   If handler returns non-NULL, that means that handler has processed the
//   request by sending appropriate HTTP reply to the client. Mongoose treats
//   the request as served.
//   If callback returns NULL, that means that callback has not processed
//   the request. Handler must not send any data to the client in this case.
//   Mongoose proceeds with request handling as if nothing happened.

typedef void * (*mg_callback_t)(enum mg_event event,
                   struct mg_connection *conn,
                   const struct mg_request_info *request_info);
于 2013-01-07T21:56:28.430 に答える
0

「パス」が NULL でないことを確認してください。デフォルト値を割り当てます。

于 2013-12-04T09:57:23.830 に答える