增加HTTP业务层、解析层Suspend接口定义。
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "tfe_connection.h"
|
|
||||||
|
#include <tfe_future.h>
|
||||||
|
#include <tfe_connection.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct tfe_http_req_spec
|
struct tfe_http_req_spec
|
||||||
@@ -16,8 +18,10 @@ struct tfe_http_resp_spec
|
|||||||
int minor_version; //HTTP 1.1 or 1.0
|
int minor_version; //HTTP 1.1 or 1.0
|
||||||
char* content_encoding;
|
char* content_encoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HTTP_REQUEST 1
|
#define HTTP_REQUEST 1
|
||||||
#define HTTP_RESPONSE 2
|
#define HTTP_RESPONSE 2
|
||||||
|
|
||||||
struct tfe_http_half
|
struct tfe_http_half
|
||||||
{
|
{
|
||||||
int direction; //HTTP_REQUEST or HTTP_RESPONSE
|
int direction; //HTTP_REQUEST or HTTP_RESPONSE
|
||||||
@@ -33,6 +37,7 @@ struct tfe_http_half
|
|||||||
struct evbuffer *body;
|
struct evbuffer *body;
|
||||||
void * fields; //hide by protocol layer
|
void * fields; //hide by protocol layer
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tfe_http_session
|
struct tfe_http_session
|
||||||
{
|
{
|
||||||
int session_sequence;//?
|
int session_sequence;//?
|
||||||
@@ -41,6 +46,7 @@ struct tfe_http_session
|
|||||||
struct tfe_http_half* resp;//value is NULL before response received.
|
struct tfe_http_half* resp;//value is NULL before response received.
|
||||||
void* proto_spec;
|
void* proto_spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum tfe_http_std_field
|
enum tfe_http_std_field
|
||||||
{
|
{
|
||||||
HTTP_UNKNOWN_FIELD=0,
|
HTTP_UNKNOWN_FIELD=0,
|
||||||
@@ -73,6 +79,7 @@ enum tfe_http_std_field
|
|||||||
HTTP_X_FLASH_VERSION,
|
HTTP_X_FLASH_VERSION,
|
||||||
HTTP_TRANSFER_LENGTH
|
HTTP_TRANSFER_LENGTH
|
||||||
};
|
};
|
||||||
|
|
||||||
struct http_field_name
|
struct http_field_name
|
||||||
{
|
{
|
||||||
enum tfe_http_std_field field_id;
|
enum tfe_http_std_field field_id;
|
||||||
@@ -117,7 +124,7 @@ enum http_ev_bit_number
|
|||||||
#define EV_HTTP_REQ_BODY_BEGIN ((uint64_t)1<<REQ_HDR_BITNUM)
|
#define EV_HTTP_REQ_BODY_BEGIN ((uint64_t)1<<REQ_HDR_BITNUM)
|
||||||
#define EV_HTTP_REQ_BODY_CONT ((uint64_t)1<<REQ_BODY_CONT_BITNUM)
|
#define EV_HTTP_REQ_BODY_CONT ((uint64_t)1<<REQ_BODY_CONT_BITNUM)
|
||||||
#define EV_HTTP_REQ_BODY_END ((uint64_t)1<<REQ_BODY_END_BITNUM)
|
#define EV_HTTP_REQ_BODY_END ((uint64_t)1<<REQ_BODY_END_BITNUM)
|
||||||
#define EV_HTTP_BODY_FULL (EV_HTTP_REQ_BODY_BEGIN|EV_HTTP_REQ_BODY_CONT|EV_HTTP_REQ_BODY_END)
|
#define EV_HTTP_REQ_BODY_FULL (EV_HTTP_REQ_BODY_BEGIN|EV_HTTP_REQ_BODY_CONT|EV_HTTP_REQ_BODY_END)
|
||||||
#define EV_HTTP_REQ_END EV_HTTP_REQ_BODY_END
|
#define EV_HTTP_REQ_END EV_HTTP_REQ_BODY_END
|
||||||
#define EV_HTTP_RESP_HDR ((uint64_t)1<<RESP_HDR_BITNUM)
|
#define EV_HTTP_RESP_HDR ((uint64_t)1<<RESP_HDR_BITNUM)
|
||||||
#define EV_HTTP_RESP_BODY_BEGIN ((uint64_t)1<<RESP_BODY_BEGIN_BITNUM)
|
#define EV_HTTP_RESP_BODY_BEGIN ((uint64_t)1<<RESP_BODY_BEGIN_BITNUM)
|
||||||
@@ -133,17 +140,43 @@ enum tfe_bussiness_action
|
|||||||
BIZ_ACTION_MODIFIED,
|
BIZ_ACTION_MODIFIED,
|
||||||
BIZ_ACTION_ANSWER,
|
BIZ_ACTION_ANSWER,
|
||||||
BIZ_ACTION_DROP,
|
BIZ_ACTION_DROP,
|
||||||
BIZ_ACTION_PASSTHROUGH
|
BIZ_ACTION_PASSTHROUGH,
|
||||||
};
|
};
|
||||||
|
|
||||||
//@param event: bit AND of EV_HTTP_**
|
//@param event: bit AND of EV_HTTP_**
|
||||||
//@param body_frag: NULL for no body data.
|
//@param body_frag: NULL for no body data.
|
||||||
typedef tfe_bussiness_action (*http_read_func)(const struct tfe_stream* stream, const struct tfe_http_session* session, uint64_t event,struct evbuffer *body_frag, void **pme);
|
typedef tfe_bussiness_action (*http_read_func)(const struct tfe_stream* stream,
|
||||||
|
const struct tfe_http_session* session, uint64_t event,struct evbuffer *body_frag, void **pme);
|
||||||
|
|
||||||
struct tfe_http_half *tfe_http_request_create(int major_version,int method, const char* uri, const char* host);
|
struct tfe_http_half *tfe_http_request_create(int major_version,int method, const char* uri, const char* host);
|
||||||
struct tfe_http_half *tfe_http_response_create(int major_version,int resp_code, struct evbuff* body);
|
struct tfe_http_half *tfe_http_response_create(int major_version,int resp_code);
|
||||||
int tfe_http_append_body(const struct tfe_http_half* half, char* buff, size_t size);
|
|
||||||
|
//@flag EV_HTTP_RESP_BODY_END, EV_HTTP_RESP_BODY_FULL,
|
||||||
|
//suspend stream on EV_HTTP_REQ_BODY_BEGIN, resume when EV_HTTP_REQ_BODY_END.
|
||||||
|
int tfe_http_append_body(const struct tfe_http_half* half, char* buff, size_t size, int flag);
|
||||||
void tfe_http_half_free(struct tfe_http_half *half);
|
void tfe_http_half_free(struct tfe_http_half *half);
|
||||||
|
|
||||||
//@param half: ownership has been transfered to session, do NOT free half after setting.
|
//@param half: ownership has been transfered to session, do NOT free half after setting.
|
||||||
void tfe_http_session_set_half(const struct tfe_http_session* session, struct tfe_http_half* half);
|
void tfe_http_session_set_half(const struct tfe_http_session* session, struct tfe_http_half* half);
|
||||||
|
|
||||||
|
/*
|
||||||
|
handler_
|
||||||
|
{
|
||||||
|
tfe_http_response_frag_create;
|
||||||
|
tfe_http_session_set_half;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_cb_
|
||||||
|
{
|
||||||
|
tfe_http_set_field
|
||||||
|
tfe_http_append_body
|
||||||
|
|
||||||
|
tfe_http_write();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rpc_finish_cb_
|
||||||
|
{
|
||||||
|
tfe_http_write_finish();
|
||||||
|
};
|
||||||
|
*/
|
||||||
@@ -85,6 +85,8 @@ typedef void stream_close_cb_t(const struct tfe_stream* stream, unsigned int th
|
|||||||
|
|
||||||
void tfe_stream_detach(const struct tfe_stream* stream);
|
void tfe_stream_detach(const struct tfe_stream* stream);
|
||||||
int tfe_stream_preempt(const struct tfe_stream* stream);
|
int tfe_stream_preempt(const struct tfe_stream* stream);
|
||||||
|
struct promise * tfe_stream_suspend(const struct tfe_stream * stream);
|
||||||
|
void tfe_stream_resume(struct promisc * promisc);
|
||||||
|
|
||||||
int stream_shutdown(const struct tfe_stream* stream);//close both sides of the stream.
|
int stream_shutdown(const struct tfe_stream* stream);//close both sides of the stream.
|
||||||
int stream_shutdown_dir(const struct tfe_stream* stream, enum tfe_conn_dir dir);
|
int stream_shutdown_dir(const struct tfe_stream* stream, enum tfe_conn_dir dir);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
add_executable(tfe src/cert.cpp src/future.cpp src/io_module_kni.cpp src/session_cache.cpp src/ssl.cc
|
||||||
|
src/ssl_stream.cpp src/tfe_main.cpp src/tfe_proxy.cpp src/tfe_stream.cpp src/tfe_util.cpp)
|
||||||
@@ -132,7 +132,8 @@ int tfe_stream_write(const struct tfe_stream* stream, enum tfe_conn_dir dir, con
|
|||||||
#define ON_DATA_CALL 1
|
#define ON_DATA_CALL 1
|
||||||
#define ON_CLOSE_CALL 2
|
#define ON_CLOSE_CALL 2
|
||||||
enum tfe_stream_action tfe_stream_call_plugin(struct tfe_stream_private* _stream, enum tfe_conn_dir dir, int what, struct evbuffer * inbuf)
|
enum tfe_stream_action tfe_stream_call_plugin(struct tfe_stream_private* _stream, enum tfe_conn_dir dir, int what, struct evbuffer * inbuf)
|
||||||
{
|
{
|
||||||
|
|
||||||
size_t contigous_len=evbuffer_get_length(inbuf),drain_size=0;
|
size_t contigous_len=evbuffer_get_length(inbuf),drain_size=0;
|
||||||
const char* contiguous_data=evbuffer_pullup(inbuf,contigous_len);
|
const char* contiguous_data=evbuffer_pullup(inbuf,contigous_len);
|
||||||
int i=0,ret=0;
|
int i=0,ret=0;
|
||||||
@@ -233,10 +234,10 @@ static void tfe_stream_readcb(struct bufferevent * bev, void * arg)
|
|||||||
{
|
{
|
||||||
_stream->calling_idx=i;
|
_stream->calling_idx=i;
|
||||||
plug_ctx=_stream->plug_ctx+i;
|
plug_ctx=_stream->plug_ctx+i;
|
||||||
plug_ctx=_stream->plug_ctx+i;
|
if(_stream->is_first_read==1)
|
||||||
{
|
{
|
||||||
action_tmp=plugins[i].on_open(&_stream.head, _stream->thrmgr_ref->thread_id, dir, contiguous_data,contigous_len, &(plug_ctx->pme));
|
action_tmp=plugins[i].on_open(&_stream.head, _stream->thrmgr_ref->thread_id, dir, contiguous_data,contigous_len, &(plug_ctx->pme));
|
||||||
action_tmp=plugins[i].on_open(&_stream.head, _stream->thrmgr_ref->thread_id, dir, contiguous_data,contigous_len, &(plug_ctx->pme));
|
_stream->is_first_read=0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -248,6 +249,7 @@ static void tfe_stream_readcb(struct bufferevent * bev, void * arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (action_final)
|
switch (action_final)
|
||||||
|
|
||||||
{
|
{
|
||||||
case ACTION_FORWARD_DATA:
|
case ACTION_FORWARD_DATA:
|
||||||
if(_stream->forward_bytes>0)
|
if(_stream->forward_bytes>0)
|
||||||
@@ -501,7 +503,7 @@ struct tfe_stream_private* tfe_stream_create(evutil_socket_t fd_downstream, evut
|
|||||||
conn_private->fd_downstream=fd_downstream;
|
conn_private->fd_downstream=fd_downstream;
|
||||||
conn_private->fd_upstream=fd_upstream;
|
conn_private->fd_upstream=fd_upstream;
|
||||||
conn_private->thrmgr_ref=thread;
|
conn_private->thrmgr_ref=thread;
|
||||||
conn_private->thrmgr_ref=thread;
|
conn_private->is_first_read=1;
|
||||||
conn_public=&(conn_private->head);
|
conn_public=&(conn_private->head);
|
||||||
addr_sock2layer(conn_public->downstream.addr,peeraddr,peeraddrlen);
|
addr_sock2layer(conn_public->downstream.addr,peeraddr,peeraddrlen);
|
||||||
thread->stat.value[STREAM_NUM]++;
|
thread->stat.value[STREAM_NUM]++;
|
||||||
|
|||||||
Reference in New Issue
Block a user