示例#1
0
/*
 * @METHOD_NAME: end
 * @METHOD_DESC: It indicate that the full response for the request has been ended. No
 * extra calls will take place after invoke this method as it contains an implicit return
 * for the active callback.
 *
 * Internally, this function send the HTTP response headers, flush the enqueued body content
 * and release the resources used by the service. The connection could keep open depending
 * of the HTTP transaction.
 *
 * @METHOD_PARAM: dr the request context information hold by a duda_request_t type
 * @METHOD_PARAM: end_cb Defines a callback function to be invoked once the response object
 * finish flushing the pending data and clearing up the resources used.
 * @METHOD_RETURN: Upon successful completion it returns 0, otherwise it can generate an explicit
 * program exit due to bad API usage.
 */
int duda_response_end(duda_request_t *dr, void (*end_cb) (duda_request_t *))
{
    int ret;

    /* Make sure the caller set a valid HTTP response code */
    if (dr->sr->headers.status == 0 && dr->_st_http_headers_off == MK_FALSE) {
        duda_api_exception(dr, "Callback did not set the HTTP response status");
        abort();
    }

    dr->end_callback = end_cb;
    ret = duda_response_send_headers(dr);
    if (ret == -1) {
        return -1;
    }

    /* flush some enqueued content */
    ret = duda_queue_flush(dr);

    /*
     * The lesson of the day Feb 2, 2013: I must NEVER forget that when sending the
     * HTTP headers, Monkey sets the TCP_CORK flag ON in the socket in case the caller
     * wanted to send more data so we let know the Kernel to buffer a little more bytes.
     * If we do not set TCP_CORK to OFF we will face some delays in the response.
     *
     * KeepAlive was very slow due to this bug. More than 4 hours to found this silly bug.
     */
    mk_api->socket_cork_flag(dr->cs->socket, TCP_CORK_OFF);

    if (ret == 0) {
        duda_service_end(dr);
    }

    return 0;
}
示例#2
0
文件: duda_api.c 项目: ankitku/monkey
/* Finalize the response process */
int end_response(duda_request_t *dr, void (*end_cb) (duda_request_t *))
{
    int ret;

    dr->end_callback = end_cb;
    __http_send_headers_safe(dr);
    ret = duda_queue_flush(dr);

    if (ret == 0) {
        duda_service_end(dr);
    }

    return 0;
}
示例#3
0
/*
 * @METHOD_NAME: flush
 * @METHOD_DESC: It flush the enqueued body content, this cover any data enqueued through
 * print(), printf() or sendfile() methods. This method should not be used inside the middle
 * of a callback routine, it's expected to be used at the end of a callback as the content
 * is flushed in asynchronous mode.
 * @METHOD_PARAM: dr the request context information hold by a duda_request_t type
 * @METHOD_RETURN: Upon successful completion it returns 0, on error returns -1.
 */
int duda_response_flush(duda_request_t *dr)
{
    return duda_queue_flush(dr);
}