forked from hzane/libhttpsvr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpio_http_apis.cc
More file actions
73 lines (67 loc) · 3 KB
/
tpio_http_apis.cc
File metadata and controls
73 lines (67 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "../libhttpsvr/precomp.h"
#include <memory>
#include "../libhttpsvr/common_defs.h"
#include "../libhttpsvr/tpio_defs.h"
#include "../libhttpsvr/tpio_http_apis.h"
#include "../libhttpsvr/http_chunks.h"
#include "../libhttpsvr/http_env.h"
auto tpio_http_receive_http_request( tpio_handle tpio, handle_t q, tpio_context* ctx ) ->void {
http_id rid = 0ui64;
auto flags = http_env::recv_reqeust_flag;
auto request = (http_request)( ctx->buffer );
auto buflen = ctx->size;
auto ovlp = static_cast<overlapped>( ctx );
tpio_env_addref(); // deref in tpio_callback
tpio_handle_start_io( tpio );
auto r = HttpReceiveHttpRequest( q, rid, flags, request, (uint32_t)buflen, nullptr, ovlp );
if ( tpio_is_failed( r ) ) {
tpio_handle_cancel_io( tpio );
tpio_callback( nullptr, nullptr, ovlp, r, 0, tpio->tpio );
}
}
auto tpio_http_receive_request_entity_body( tpio_handle tpio, handle_t q, http_id rid, tpio_context* ctx ) ->void {
auto flags = http_env::recv_request_entity_flag;
auto buf = ctx->buffer;
auto buflen = ctx->size;
auto ovlp = static_cast<overlapped>( ctx );
tpio_env_addref();
tpio_handle_start_io( tpio );
auto r = HttpReceiveRequestEntityBody( q, rid, flags, buf, (uint32_t)buflen, nullptr, ovlp );
if ( tpio_is_failed( r ) ) {
tpio_handle_cancel_io( tpio );
tpio_callback( nullptr, nullptr, ovlp, r, 0, tpio->tpio );
}
}
auto tpio_http_send_http_response( tpio_handle tpio, handle_t q, http_id rid, tpio_context* ctx, bool send_not_end ) ->void {
auto flags = http_env::send_response_flag | ( send_not_end ? http_env::send_not_end_flag : 0 );
auto resp = (http_response)ctx->buffer;
auto cpolicy = &http_env_cache_policy();
auto ovlp = static_cast<overlapped>( ctx );
tpio_env_addref();
tpio_handle_start_io( tpio );
auto r = HttpSendHttpResponse( q, rid, flags, resp, cpolicy, nullptr, nullptr, 0, ovlp, nullptr );
if ( tpio_is_failed( r ) ) {
tpio_handle_cancel_io( tpio );
tpio_callback( nullptr, nullptr, ovlp, r, 0, tpio->tpio );
}
}
auto tpio_http_send_response_entity_body( tpio_handle tpio, handle_t q, http_id rid, tpio_context* ctx, bool send_not_end ) ->void {
auto flags = http_env::send_response_entity_flag | ( send_not_end ? http_env::send_not_end_flag : 0 );
auto ovlp = static_cast<overlapped>( ctx );
tpio_env_addref();
tpio_handle_start_io( tpio );
auto r = HttpSendResponseEntityBody( q, rid, flags, 1, (PHTTP_DATA_CHUNK)ctx->buffer, nullptr, nullptr, 0, ovlp, nullptr );
if ( tpio_is_failed( r ) ) {
tpio_handle_cancel_io( tpio );
tpio_callback( nullptr, nullptr, ovlp, r, 0, tpio->tpio );
}
}
auto tpio_http_cancel_http_request( tpio_handle tpio, handle_t q, http_id rid, tpio_context* ctx )->void {
tpio_env_addref();
tpio_handle_start_io( tpio );
auto r = HttpCancelHttpRequest( q, rid, ctx );
if ( tpio_is_failed( r ) ) {
tpio_handle_cancel_io( tpio );
tpio_callback(nullptr, nullptr, static_cast<overlapped>(ctx), r, 0, tpio->tpio);
}
}