Adjust benchmark directory,enable HTTP test,rename variables,format codes
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
static const char *string_state_to_desc(enum string_state state)
|
||||
{
|
||||
switch (state) {
|
||||
switch (state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
return "init";
|
||||
break;
|
||||
@@ -25,22 +26,23 @@ static const char *string_state_to_desc(enum string_state state)
|
||||
}
|
||||
}
|
||||
|
||||
void http_decoder_string_refer(struct http_decoder_string *rstr,
|
||||
const char *at, size_t length)
|
||||
void http_decoder_string_refer(struct http_decoder_string *rstr, const char *at, size_t length)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->refer.iov_base = (char *)at;
|
||||
rstr->refer.iov_len = length;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->refer.iov_base = (char *)at;
|
||||
rstr->refer.iov_len = length;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
rstr->state = STRING_STATE_REFER;
|
||||
@@ -48,22 +50,28 @@ void http_decoder_string_refer(struct http_decoder_string *rstr,
|
||||
|
||||
static void string_refer2cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (0 == rstr->refer.iov_len) {
|
||||
if (0 == rstr->refer.iov_len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (rstr->cache.iov_len >= rstr->max_cache_size) {
|
||||
if (rstr->cache.iov_len >= rstr->max_cache_size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t length = rstr->cache.iov_len + rstr->refer.iov_len;
|
||||
if (length > rstr->max_cache_size) {
|
||||
if (length > rstr->max_cache_size)
|
||||
{
|
||||
length = rstr->max_cache_size;
|
||||
}
|
||||
|
||||
if (NULL == rstr->cache.iov_base) {
|
||||
if (NULL == rstr->cache.iov_base)
|
||||
{
|
||||
rstr->cache.iov_base = CALLOC(char, length + 1);
|
||||
memcpy(rstr->cache.iov_base, rstr->refer.iov_base, length);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rstr->cache.iov_base = REALLOC(char, rstr->cache.iov_base, length + 1);
|
||||
memcpy((char *)rstr->cache.iov_base + rstr->cache.iov_len, rstr->refer.iov_base,
|
||||
(length - rstr->cache.iov_len));
|
||||
@@ -77,24 +85,32 @@ static void string_refer2cache(struct http_decoder_string *rstr)
|
||||
static void string_commit2cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (rstr->cache.iov_len == rstr->commit.iov_len &&
|
||||
rstr->cache.iov_base == rstr->commit.iov_base) {
|
||||
rstr->cache.iov_base == rstr->commit.iov_base)
|
||||
{
|
||||
rstr->commit.iov_base = NULL;
|
||||
rstr->commit.iov_len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
//Only http header key need to backward to cache
|
||||
// Only http header key need to backward to cache
|
||||
size_t length = 0;
|
||||
if (rstr->commit.iov_len > rstr->max_cache_size) {
|
||||
if (rstr->commit.iov_len > rstr->max_cache_size)
|
||||
{
|
||||
length = rstr->max_cache_size;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
length = rstr->commit.iov_len;
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
if (NULL == rstr->cache.iov_base) {
|
||||
if (length > 0)
|
||||
{
|
||||
if (NULL == rstr->cache.iov_base)
|
||||
{
|
||||
rstr->cache.iov_base = CALLOC(char, length + 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
memcpy(rstr->cache.iov_base, rstr->commit.iov_base, length);
|
||||
@@ -107,18 +123,20 @@ static void string_commit2cache(struct http_decoder_string *rstr)
|
||||
|
||||
void http_decoder_string_cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_REFER:
|
||||
string_refer2cache(rstr);
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
break;
|
||||
case STRING_STATE_COMMIT:
|
||||
//commit backward to cache
|
||||
// commit backward to cache
|
||||
string_commit2cache(rstr);
|
||||
break;
|
||||
default:
|
||||
@@ -130,34 +148,39 @@ void http_decoder_string_cache(struct http_decoder_string *rstr)
|
||||
|
||||
void http_decoder_string_commit(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
case STRING_STATE_REFER:
|
||||
if (rstr->cache.iov_len) {
|
||||
http_decoder_string_cache(rstr);
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_REFER:
|
||||
if (rstr->cache.iov_len)
|
||||
{
|
||||
http_decoder_string_cache(rstr);
|
||||
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
} else {
|
||||
rstr->commit.iov_base = rstr->refer.iov_base;
|
||||
rstr->commit.iov_len = rstr->refer.iov_len;
|
||||
|
||||
rstr->refer.iov_base = NULL;
|
||||
rstr->refer.iov_len = 0;
|
||||
}
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
break;
|
||||
default:
|
||||
//abort();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
rstr->commit.iov_base = rstr->refer.iov_base;
|
||||
rstr->commit.iov_len = rstr->refer.iov_len;
|
||||
|
||||
rstr->refer.iov_base = NULL;
|
||||
rstr->refer.iov_len = 0;
|
||||
}
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
break;
|
||||
default:
|
||||
// abort();
|
||||
break;
|
||||
}
|
||||
|
||||
rstr->state = STRING_STATE_COMMIT;
|
||||
@@ -167,7 +190,8 @@ void http_decoder_string_reset(struct http_decoder_string *rstr)
|
||||
{
|
||||
assert(rstr);
|
||||
|
||||
switch (rstr->state) {
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_REFER:
|
||||
case STRING_STATE_CACHE:
|
||||
@@ -183,26 +207,27 @@ void http_decoder_string_reset(struct http_decoder_string *rstr)
|
||||
rstr->state = STRING_STATE_INIT;
|
||||
}
|
||||
|
||||
|
||||
void http_decoder_string_init(struct http_decoder_string *rstr,
|
||||
size_t max_cache_size)
|
||||
void http_decoder_string_init(struct http_decoder_string *rstr, size_t max_cache_size)
|
||||
{
|
||||
rstr->max_cache_size = max_cache_size;
|
||||
}
|
||||
|
||||
void http_decoder_string_reinit(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (rstr->state == STRING_STATE_CACHE) {
|
||||
if (rstr->state == STRING_STATE_CACHE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rstr->state == STRING_STATE_COMMIT &&
|
||||
rstr->cache.iov_base == rstr->commit.iov_base &&
|
||||
rstr->cache.iov_len == rstr->commit.iov_len) {
|
||||
rstr->cache.iov_len == rstr->commit.iov_len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rstr->cache.iov_base != NULL) {
|
||||
if (rstr->cache.iov_base != NULL)
|
||||
{
|
||||
FREE(rstr->cache.iov_base);
|
||||
rstr->cache.iov_len = 0;
|
||||
}
|
||||
@@ -213,7 +238,7 @@ void http_decoder_string_reinit(struct http_decoder_string *rstr)
|
||||
rstr->commit.iov_base = NULL;
|
||||
rstr->commit.iov_len = 0;
|
||||
rstr->state = STRING_STATE_INIT;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
enum string_state http_decoder_string_state(const struct http_decoder_string *rstr)
|
||||
@@ -223,14 +248,18 @@ enum string_state http_decoder_string_state(const struct http_decoder_string *rs
|
||||
|
||||
int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out)
|
||||
{
|
||||
if (NULL == rstr || NULL == out) {
|
||||
if (NULL == rstr || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (http_decoder_string_state(rstr) == STRING_STATE_COMMIT) {
|
||||
if (http_decoder_string_state(rstr) == STRING_STATE_COMMIT)
|
||||
{
|
||||
out->iov_base = rstr->commit.iov_base;
|
||||
out->iov_len = rstr->commit.iov_len;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
out->iov_base = NULL;
|
||||
out->iov_len = 0;
|
||||
}
|
||||
@@ -240,7 +269,8 @@ int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out
|
||||
|
||||
void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user