缓存能跑起来了。

This commit is contained in:
zhengchao
2018-10-14 18:45:02 +08:00
parent 12d4370b3f
commit 294201ecd8
12 changed files with 86 additions and 42 deletions

View File

@@ -1,7 +1,12 @@
#include "tango_cache_pending.h"
#include "pangu_web_cache.h"
#include <tango_cache_pending.h>
#include <tango_cache_client.h>
#include <tfe_proxy.h>
#include <tfe_http.h>
#include <tfe_utils.h>
#include <event2/event.h>
#include <event2/buffer.h>
@@ -30,7 +35,7 @@ struct cache_handle* create_web_cache_handle(const char* profile_path, const cha
return handle;
}
char* read_http1_hdr(const char* hdr, const char* field_name)
static char* read_http1_hdr(const char* hdr, const char* field_name)
{
const char *p=NULL, *q=NULL;
char* value=NULL;
@@ -50,7 +55,7 @@ char* read_http1_hdr(const char* hdr, const char* field_name)
{
return NULL;
}
value=calloc(sizeof(char), (q-p+1));
value=(char*) calloc(sizeof(char), (q-p+1));
memcpy(value, p, q-p);
return value;
}
@@ -95,8 +100,8 @@ struct cached_meta* cache_query_result_get_header(future_result_t * result)
return NULL;
}
meta= ALLOC(struct cached_meta, 1);
meta->content_length=read_http1_hdr(cache_result->data_frag, "content-length");
meta->content_type=read_http1_hdr(cache_result->data_frag, "content-type");
meta->content_length=read_http1_hdr((const char*)cache_result->data_frag, "content-length");
meta->content_type=read_http1_hdr((const char*)cache_result->data_frag, "content-type");
return meta;
}
void cache_query_result_append_data(struct evbuffer* buf, future_result_t * result)
@@ -118,8 +123,8 @@ enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsig
{
case UNDEFINED:
case FORBIDDEN:
case VERIFY:
return WEB_CACHE_NOT_APPLICABLE;
case VERIFY:
case ALLOWED:
break;
default:
@@ -129,8 +134,8 @@ enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsig
struct tango_cache_meta meta;
memset(&meta, 0, sizeof(meta));
meta->url=request->req_spec.url;
memcpy(&(meta->put), req_fresshness, sizeof(meta->put));
meta.url=request->req_spec.url;
memcpy(&(meta.put), &req_fresshness, sizeof(meta.put));
ret=tango_cache_fetch_object(handle->clients[thread_id], f, &meta);
assert(ret==0);
return WEB_CACHE_QUERING;
@@ -159,7 +164,7 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle,
snprintf(buffer, sizeof(buffer), "content-type:%s",session->resp->resp_spec.content_length);
meta.std_hdr[i]=buffer;
i++;
memcpy(&meta.put, resp_freshness, sizeof(resp_freshness));
memcpy(&meta.put, &resp_freshness, sizeof(resp_freshness));
write_ctx=tango_cache_update_start(handle->clients[thread_id], NULL, &meta);
if(write_ctx==NULL)
{
@@ -173,7 +178,7 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle,
}
void web_cache_update(struct cache_update_context* ctx, const unsigned char * body_frag, size_t frag_size)
{
tango_cache_update_frag_data(ctx->write_ctx, body_frag, frag_size);
tango_cache_update_frag_data(ctx->write_ctx, (const char*)body_frag, frag_size);
return;
}
void web_cache_update_end(struct cache_update_context* ctx)