Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
multiple get support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Kilibaba committed Mar 1, 2017
1 parent aa8b88d commit 4481119
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ debug:
build:
cc -O2 -DNDEBUG -pedantic -Wall -Wextra -o okdb okdb.c sophia.c -lpthread -levent -I/usr/local/include -L/usr/local/lib
run:
./okdb
./okdb -p 11213 -D
kill:
-pkill okdb && -rm ./okdb
36 changes: 15 additions & 21 deletions okdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static char
"Content-Type: text/html; charset=UTF-8\r\n"
"Content-Length: %d\r\n"
"Keep-Alive: timeout=20, max=200\r\n"
"Server: okdb/0.0.8\r\n"
"Server: okdb/0.1.0\r\n"
"\r\n%s";

static char
Expand All @@ -69,7 +69,7 @@ static char
"Connection: close\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"Content-Length: %d\r\n"
"Server: okdb/0.0.8\r\n"
"Server: okdb/0.1.0\r\n"
"\r\n%s";

static char
Expand Down Expand Up @@ -407,9 +407,6 @@ get_val(struct evbuffer *output, const char *key, int is_http)
}
INFO("key:'%s' not found\n",key);
}
if (is_http == 0) {
evbuffer_add(output, st_end, sizeof(st_end)-1);
}
return;
}

Expand Down Expand Up @@ -582,10 +579,8 @@ CONTINUE_LOOP:;
}
/* Find end command */
char *cmdget_end = strstr(data,nl);
INFO("D[%s]",strstr(data,"\n"));
if (!cmdget_end) {
/* no end in buffer - wait it in next packet */
INFO("Dd");
free(data);
return;
}
Expand All @@ -596,8 +591,8 @@ CONTINUE_LOOP:;

/* extract key from buffer */
data+=sizeof(cmd_get)-1;
/* Find ' ' or /r/n in buffer */
size_t key_end = strcspn(data, " \r\n");
/* Find /r/n in buffer */
size_t key_end = strcspn(data, "\r\n");
char *key = make_str(data, key_end);
/* Move pointer back */
data-=sizeof(cmd_get)-1;
Expand All @@ -610,18 +605,17 @@ CONTINUE_LOOP:;
}
INFO("key:'%s'\n", key);

/* Processing key */
get_val(output, key, 0);
size_t lenout = evbuffer_get_length(output);
INFO("out%d\n",(int)lenout);
/* command catched - send response
if (bufferevent_write_buffer(bev, output)) {
INFO("error send");
free(key);
free(data);
close_connection(bev, ctx, "Error sending data to client");
return;
}*/
/* Processing keys */
char *token;
token = strtok(key, " ");
while(token) {
printf( "token: [%s] len:[%d]\n", token,strlen(token) );
get_val(output, token, 0);
token = strtok(NULL, " ");
}

evbuffer_add(output, st_end, sizeof(st_end)-1);

free(key);
free(data);
/* client may send multiple commands in one buffer so continue processing */
Expand Down

0 comments on commit 4481119

Please sign in to comment.