mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 06:49:35 -04:00
Add a variant of evhttp_send_reply_chunk() with a callback on evhttp_write_buffer()
evhttp_write_buffer() used by evhttp_send_reply_chunk() can take callback executed when (part of) the buffer has been written. Using this callback to schedule the next chunk avoids buffering large amounts of data in memory.
This commit is contained in:
parent
a60632a1ec
commit
8d8decf114
10
http.c
10
http.c
@ -2658,7 +2658,8 @@ evhttp_send_reply_start(struct evhttp_request *req, int code,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
|
evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *databuf,
|
||||||
|
void (*cb)(struct evhttp_connection *, void *), void *arg)
|
||||||
{
|
{
|
||||||
struct evhttp_connection *evcon = req->evcon;
|
struct evhttp_connection *evcon = req->evcon;
|
||||||
struct evbuffer *output;
|
struct evbuffer *output;
|
||||||
@ -2680,9 +2681,14 @@ evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
|
|||||||
if (req->chunked) {
|
if (req->chunked) {
|
||||||
evbuffer_add(output, "\r\n", 2);
|
evbuffer_add(output, "\r\n", 2);
|
||||||
}
|
}
|
||||||
evhttp_write_buffer(evcon, NULL, NULL);
|
evhttp_write_buffer(evcon, cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
|
||||||
|
{
|
||||||
|
evhttp_send_reply_chunk_with_cb(req, databuf, NULL, NULL);
|
||||||
|
}
|
||||||
void
|
void
|
||||||
evhttp_send_reply_end(struct evhttp_request *req)
|
evhttp_send_reply_end(struct evhttp_request *req)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,7 @@ extern "C" {
|
|||||||
struct evbuffer;
|
struct evbuffer;
|
||||||
struct event_base;
|
struct event_base;
|
||||||
struct bufferevent;
|
struct bufferevent;
|
||||||
|
struct evhttp_connection;
|
||||||
|
|
||||||
/** @file event2/http.h
|
/** @file event2/http.h
|
||||||
*
|
*
|
||||||
@ -407,6 +408,23 @@ void evhttp_send_reply_start(struct evhttp_request *req, int code,
|
|||||||
*/
|
*/
|
||||||
void evhttp_send_reply_chunk(struct evhttp_request *req,
|
void evhttp_send_reply_chunk(struct evhttp_request *req,
|
||||||
struct evbuffer *databuf);
|
struct evbuffer *databuf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send another data chunk as part of an ongoing chunked reply.
|
||||||
|
|
||||||
|
The reply chunk consists of the data in databuf. After calling
|
||||||
|
evhttp_send_reply_chunk() databuf will be empty, but the buffer is
|
||||||
|
still owned by the caller and needs to be deallocated by the caller
|
||||||
|
if necessary.
|
||||||
|
|
||||||
|
@param req a request object
|
||||||
|
@param databuf the data chunk to send as part of the reply.
|
||||||
|
@param cb callback funcion
|
||||||
|
@param call back's argument.
|
||||||
|
*/
|
||||||
|
void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *,
|
||||||
|
void (*cb)(struct evhttp_connection *, void *), void *arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Complete a chunked reply, freeing the request as appropriate.
|
Complete a chunked reply, freeing the request as appropriate.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user