当前位置: 首页>>代码示例>>C++>>正文


C++ HttpServer::callback方法代码示例

本文整理汇总了C++中HttpServer::callback方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpServer::callback方法的具体用法?C++ HttpServer::callback怎么用?C++ HttpServer::callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpServer的用法示例。


在下文中一共展示了HttpServer::callback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: hc_process

/*! \brief Process an incoming message */
static void hc_process(HttpConnection* connection) {
    const char* tmp;
    const char* data;
    int content_size, header_size;
	HttpRequest hr;
    HttpServer* server = connection->server;

    /* get the content lenght */
    tmp = http_get_field(connection->header, "Content-Length");
    if(tmp == NULL) {
        content_size = 0;
    } else {
        content_size = atoi(tmp);
    }

    /* find the beginning of the content */
    data = strstr(connection->buffer, HTTP_LINE_SEP HTTP_LINE_SEP) + 4;

    header_size = data - connection->buffer;


    /* check if the message is bigger than current buffer size */
    if(content_size + header_size >= MAX_BUFFER_SIZE) {
        log(WARNING, "Message is too big");
        hc_report_error(connection, "Message is too big");
        return;
    }

    /* check if everything is here */
    if(connection->buffer_size >= header_size + content_size) {

        log(INFO, "Processing request Content-Length=%d", content_size);

        /* inform the request */
		hr.connection = connection;
		hr.header = connection->header;
		hr.data = data;
		hr.data_size = content_size;
		server->callback(server->user_data, &hr);

        /* free the header, we don't need it anymore */
		http_delete(connection->header);
		connection->header = NULL;

        /* move the buffer */
        if(connection->buffer_size > header_size + content_size) {
            memmove(connection->buffer, connection->buffer + header_size +
                    content_size, connection->buffer_size - header_size -
                    content_size);
            connection->buffer_size -= header_size + content_size;
        } else {
            connection->buffer_size = 0;
        }
    }
}
开发者ID:zhenglu,项目名称:meowboard,代码行数:56,代码来源:http_server.c

示例2: staticCallback

/*******************  FUNCTION  *********************/
void* HttpServer::staticCallback(mg_event event, mg_connection* conn)
{
    const struct mg_request_info *request_info = mg_get_request_info(conn);
    HttpServer * server = (HttpServer*)request_info->user_data;
    return server->callback(event,conn,request_info);
}
开发者ID:svalat,项目名称:htopml,代码行数:7,代码来源:HttpServer.cpp


注:本文中的HttpServer::callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。