增加HTTP业务层、解析层Suspend接口定义。

This commit is contained in:
Lu
2018-08-20 15:46:35 +08:00
parent 86c18a15c3
commit 64d6022fa7
4 changed files with 50 additions and 10 deletions

View File

@@ -1,4 +1,6 @@
#include "tfe_connection.h"
#include <tfe_future.h>
#include <tfe_connection.h>
#include <stdint.h>
struct tfe_http_req_spec
@@ -16,8 +18,10 @@ struct tfe_http_resp_spec
int minor_version; //HTTP 1.1 or 1.0
char* content_encoding;
};
#define HTTP_REQUEST 1
#define HTTP_RESPONSE 2
struct tfe_http_half
{
int direction; //HTTP_REQUEST or HTTP_RESPONSE
@@ -33,6 +37,7 @@ struct tfe_http_half
struct evbuffer *body;
void * fields; //hide by protocol layer
};
struct tfe_http_session
{
int session_sequence;//?
@@ -41,6 +46,7 @@ struct tfe_http_session
struct tfe_http_half* resp;//value is NULL before response received.
void* proto_spec;
};
enum tfe_http_std_field
{
HTTP_UNKNOWN_FIELD=0,
@@ -73,6 +79,7 @@ enum tfe_http_std_field
HTTP_X_FLASH_VERSION,
HTTP_TRANSFER_LENGTH
};
struct http_field_name
{
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_CONT ((uint64_t)1<<REQ_BODY_CONT_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_RESP_HDR ((uint64_t)1<<RESP_HDR_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_ANSWER,
BIZ_ACTION_DROP,
BIZ_ACTION_PASSTHROUGH
BIZ_ACTION_PASSTHROUGH,
};
//@param event: bit AND of EV_HTTP_**
//@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_response_create(int major_version,int resp_code, struct evbuff* body);
int tfe_http_append_body(const struct tfe_http_half* half, char* buff, size_t size);
struct tfe_http_half *tfe_http_response_create(int major_version,int resp_code);
//@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);
//@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);
/*
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();
};
*/