-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added API for client and created test client. Also cleaned up code. #73
Open
kstats
wants to merge
24
commits into
gwAdvNet2015:master
Choose a base branch
from
thelimeburner:client_api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2072ea4
Merge branch 'client-dev' of https://github.com/gwAdvNet2015/gw-kv-st…
kstats b3b3986
Merge branch 'apiclientversion' of https://github.com/sacul29/gw-kv-s…
kstats 682e258
Merge branch 'cleanup' of https://github.com/sacul29/gw-kv-store into…
kstats 53e3934
Merge branch 'cleanup' of https://github.com/sacul29/gw-kv-store into…
kstats 1e7e9be
created api for client
jdk514 50cace5
fixed api logic
jdk514 7939849
fixed Makefile, but still broken
jdk514 372470a
basic test...
kstats 2d758c7
Merge branch 'client_api' of https://github.com/sacul29/gw-kv-store i…
kstats 01a0262
added header file for api
5b824fe
Merge branch 'client_api' of github.com:sacul29/gw-kv-store into clie…
4c79e51
Merge branch 'client_api' of github.com:sacul29/gw-kv-store into clie…
2997182
added set too...
kstats 547f86c
fixed my silly imports
kstats 5655cd4
fixed my silly imports
kstats 1828bad
removed random free
kstats b93b77f
code cleanup and commenting
kstats d7f30ed
updated testing for api
e56e344
fixed problem with merge
179b70c
Fixed issue with compiling api
8bb81c4
commented client api test
kstats b6c699a
fixed memory issue
89b76ae
Merge branch 'client_api' of https://github.com/sacul29/gw-kv-store i…
kstats 6fbd714
Fixed makefile and api, added test to folder for another group to finish
kstats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <netdb.h> | ||
#include <unistd.h> | ||
#include <inttypes.h> | ||
#include <string.h> | ||
#include "client_api.h" | ||
/************************************************ | ||
* GW KV | ||
* https://github.com/gwAdvNet2015/gw-kv-store | ||
* | ||
* Copyright 2015 Lucas Chaufournier, Joel Klein, | ||
* and Katie Stasaski | ||
* | ||
* This program is licensed under the MIT license. | ||
* | ||
* client_api.c- creates client api and modularizes | ||
*************************************************/ | ||
int | ||
set_mem(int sockfd, struct operation * msg) | ||
{ | ||
char * temp; | ||
int num_bytes, rc; | ||
int status = 0; | ||
|
||
gwkv_marshal_client(msg, &temp); | ||
|
||
rc = send(sockfd,temp,strlen(temp), 0); | ||
if(rc < 0) { | ||
status = -1; | ||
} | ||
|
||
return status; | ||
} | ||
|
||
int | ||
get_mem(int sockfd, struct operation * msg) | ||
{ | ||
char * temp; | ||
int num_bytes, rc; | ||
int status = 0; | ||
|
||
gwkv_marshal_client(msg, &temp); | ||
|
||
rc = send(sockfd,temp,strlen(temp), 0); | ||
if(rc < 0) { | ||
status = -1; | ||
return status; | ||
} | ||
|
||
status = __read_get_msg(sockfd, msg); | ||
|
||
return status; | ||
} | ||
|
||
int | ||
__read_get_msg(int sockfd, struct operation * msg) | ||
{ | ||
int bytes_received, status; | ||
|
||
status = __demarshal_msg(sockfd, msg); | ||
if (status < 0) { | ||
return -1; | ||
} else { | ||
msg->value = malloc(msg->value_length); | ||
bytes_received = recv(sockfd, msg->value, msg->value_length, 0); | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
int | ||
__demarshal_msg(int sockfd, struct operation * marshal_msg) | ||
{ | ||
char curr_char; | ||
int count = 0; | ||
int i; | ||
char* msg = malloc(1024); | ||
int * status = malloc(sizeof(int)); | ||
int stat = 0; | ||
struct operation* op; | ||
recv(sockfd,&curr_char,1,0); | ||
if(curr_char == 'E') | ||
{ | ||
stat = -1; | ||
} else { | ||
msg[count] = curr_char; | ||
count++; | ||
|
||
for(i=0; i<3; i++) { | ||
while(1) { | ||
recv(sockfd, &curr_char, 1, 0); | ||
msg[count] = curr_char; | ||
count++; | ||
|
||
if(curr_char == ' ') { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
while(1) { | ||
recv(sockfd, &curr_char, 1, 0); | ||
if (curr_char == '\r') { | ||
msg[count] = curr_char; | ||
count++; | ||
recv(sockfd, &curr_char, 1, 0); | ||
if (curr_char == '\n') { | ||
msg[count] = curr_char; | ||
count++; | ||
break; | ||
} | ||
} else { | ||
msg[count] = curr_char; | ||
} | ||
count++; | ||
} | ||
gwkv_demarshal_client(msg, &op, status); | ||
marshal_msg->value_length = op-> value_length; | ||
free(op); | ||
} | ||
free(status); | ||
free(msg); | ||
return stat; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef __CLIENT_API__ | ||
#define __CLIENT_API__ | ||
|
||
#include "../lib/marshal/marshal.h" | ||
|
||
/************************************************ | ||
* GW KV | ||
* https://github.com/gwAdvNet2015/gw-kv-store | ||
* | ||
* Copyright 2015 Lucas Chaufournier, Joel Klein, | ||
* and Katie Stasaski | ||
* | ||
* This program is licensed under the MIT license. | ||
* | ||
* client_api.h - sets up functions for client's | ||
* api | ||
*************************************************/ | ||
|
||
int | ||
get_mem(int sockfd, struct operation *msg); | ||
|
||
int | ||
send_mem(int sockfd, struct operation * msg); | ||
|
||
#endif//__CLIENT_API__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-o
flag is unnecessary (you're only compiling one field and it defaults to the name), but you can leave it