支持Head获取对象元信息操作,支持从redis获取元信息;调整内部超时检查逻辑;

This commit is contained in:
zhangchengwei
2018-10-23 20:26:06 +08:00
committed by zhengchao
parent 46db35c9a5
commit 8edd964e21
15 changed files with 1244 additions and 62 deletions

View File

@@ -79,6 +79,40 @@ void get_future_failed(enum e_future_error err, const char * what, void * user)
printf("GET fail: %s\n", what);
}
void head_future_success(future_result_t* result, void * user)
{
struct tango_cache_result *res = tango_cache_read_result(result);
struct future_pdata *pdata = (struct future_pdata *)user;
char buffer[1024];
switch(res->type)
{
case RESULT_TYPE_USERTAG:
case RESULT_TYPE_HEADER:
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
buffer[res->size] = '\0';
printf("%s", buffer);
break;
case RESULT_TYPE_BODY:
assert(0);
break;
case RESULT_TYPE_MISS:
printf("cache not hit/fresh\n");
case RESULT_TYPE_END:
if(res->type != RESULT_TYPE_MISS)
printf("HEAD cache over, total length: %ld\n", res->tlength);
future_destroy(pdata->future);
free(pdata);
break;
default:break;
}
}
void head_future_failed(enum e_future_error err, const char * what, void * user)
{
printf("HEAD fail: %s\n", what);
}
void put_future_success(future_result_t* result, void * user)
{
struct future_pdata *pdata = (struct future_pdata *)user;
@@ -182,6 +216,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
p = method;
memset(&putmeta, 0, sizeof(struct tango_cache_meta_put));
memset(&getmeta, 0, sizeof(struct tango_cache_meta_get));
putmeta.url = s;
putmeta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
putmeta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
@@ -197,16 +232,22 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
sprintf(filename, "file_index_%u.bin", index++);
pdata->fp = fopen(filename, "w");
pdata->future = future_create(get_future_success, get_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
tango_cache_fetch_object(tango_instance, pdata->future, &getmeta);
}
else if(!strcasecmp(p, "HEAD"))
{
sprintf(filename, "file_index_%u.bin", index++);
pdata->fp = fopen(filename, "w");
pdata->future = future_create(head_future_success, head_future_failed, pdata);
tango_cache_head_object(tango_instance, pdata->future, &getmeta);
}
else if(!strcasecmp(p, "PUTONCE"))
{
size_t filelen;
p = get_file_content(s, &filelen);
pdata->future = future_create(put_future_success, put_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
tango_cache_upload_once_data(tango_instance, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256);
}
@@ -214,7 +255,6 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
{
size_t readlen;
pdata->future = future_create(put_future_success, put_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
struct evbuffer *evbuf = evbuffer_new();
char buffer[1024];
@@ -234,14 +274,12 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
else if(!strcasecmp(p, "DEL"))
{
pdata->future = future_create(del_future_success, del_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
sprintf(pdata->filename, "%s", s);
tango_cache_delete_object(tango_instance, pdata->future, s);
}
else if(!strcasecmp(p, "DELMUL")) //TODO
{
pdata->future = future_create(del_future_success, del_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
sprintf(pdata->filename, "%s", s);
for(pstart = strtok_r(s, ";", &save_ptr); pstart != NULL; pstart = strtok_r(NULL, ";", &save_ptr))
@@ -253,7 +291,6 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
else
{
pdata->future = future_create(put_future_success, put_future_failed, pdata);
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
ctx = tango_cache_update_start(tango_instance, pdata->future, &putmeta);
tango_cache_get_object_path(ctx, pdata->filename, 256);