Commit 3aca97f5 authored by Saikumar's avatar Saikumar

modified by sai

parent acf37be8
...@@ -25,4 +25,4 @@ server:all ...@@ -25,4 +25,4 @@ server:all
./server_s ./server_s
client: client:
./client_c 127.1.1.3 20000 ./client_c 127.1.1.2 20000
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#include "cs_thread.h" // #include "cs_thread.h"
#include "cache.h" #include "cache.h"
#include "storage.h" #include "storage.h"
using namespace std; using namespace std;
...@@ -112,6 +112,7 @@ string GET(string key) { ...@@ -112,6 +112,7 @@ string GET(string key) {
// //uncLock // //uncLock
// } // }
// return value; // return value;
return "ERROR";
} }
return ans; return ans;
...@@ -119,7 +120,7 @@ string GET(string key) { ...@@ -119,7 +120,7 @@ string GET(string key) {
} }
string PUT(string key, string value) { string PUT(string key, string value) {
cout << "PUT started" << endl; // cout << "PUT started" << endl;
pthread_mutex_lock(&cLock); pthread_mutex_lock(&cLock);
string ans = search(key); string ans = search(key);
if(ans == "") { if(ans == "") {
......
...@@ -83,7 +83,7 @@ void sendToServer(int sockfd) { ...@@ -83,7 +83,7 @@ void sendToServer(int sockfd) {
} }
int GET(char* key, char *request) { int GET(char* key, char *request) {
printf("GET called!\n"); // printf("GET called!\n");
// char request[513]; // char request[513];
memset(request, '0', 513); memset(request, '0', 513);
request[0] = '1'; request[0] = '1';
...@@ -93,19 +93,19 @@ int GET(char* key, char *request) { ...@@ -93,19 +93,19 @@ int GET(char* key, char *request) {
} }
int PUT(char* key, char* value, char *request) { int PUT(char* key, char* value, char *request) {
printf("PUT called!\n"); // printf("PUT called!\n");
// char request[513]; // char request[513];
memset(request, '0', 513); memset(request, '0', 513);
request[0] = '2'; request[0] = '2';
// memcpy(request+1, key, strlen(key)); // memcpy(request+1, key, strlen(key));
memcpy(request+257-strlen(key), key, strlen(key)); memcpy(request+257-strlen(key), key, strlen(key));
memcpy(request+513-strlen(value), value, strlen(value)); memcpy(request+513-strlen(value), value, strlen(value));
printf("key at index: %ld\n", 257-strlen(key)); // printf("key at index: %ld\n", 257-strlen(key));
printf("value at index: %ld\n", 513-strlen(value)); // printf("value at index: %ld\n", 513-strlen(value));
} }
int DELETE(char* key, char *request) { int DELETE(char* key, char *request) {
// char request[513]; // char request[513];
printf("DELETE called!\n"); // printf("DELETE called!\n");
memset(request, '0', 513); memset(request, '0', 513);
request[0] = '3'; request[0] = '3';
// memcpy(request+1, key, strlen(key)); // memcpy(request+1, key, strlen(key));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <pthread.h> #include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
#include "cache.h" #include "cache.h"
#include "cs_thread.h" // #include "cs_thread.h"
using namespace std; using namespace std;
// struct lock cLock; // struct lock cLock;
...@@ -52,7 +52,7 @@ void *respondToClient(void *args) { ...@@ -52,7 +52,7 @@ void *respondToClient(void *args) {
string key_string, value_string; string key_string, value_string;
switch(todo) { switch(todo) {
case '1': case '1':
printf("GET recvd\n"); // printf("GET recvd\n");
// printf("Key: %s\n", key); // printf("Key: %s\n", key);
// j = search(key); // j = search(key);
// printf("j=%d\n", j); // printf("j=%d\n", j);
...@@ -67,7 +67,7 @@ void *respondToClient(void *args) { ...@@ -67,7 +67,7 @@ void *respondToClient(void *args) {
write(clientFd, converted_output, output.length()); write(clientFd, converted_output, output.length());
break; break;
case '2': case '2':
printf("PUT recvd\n"); // printf("PUT recvd\n");
// printf("Key: %s\n", key); // printf("Key: %s\n", key);
// printf("Value: %s\n", value); // printf("Value: %s\n", value);
key_string = key; key_string = key;
...@@ -80,7 +80,7 @@ void *respondToClient(void *args) { ...@@ -80,7 +80,7 @@ void *respondToClient(void *args) {
write(clientFd, converted_output, output.length()); write(clientFd, converted_output, output.length());
break; break;
case '3': case '3':
printf("DELETE recvd\n"); // printf("DELETE recvd\n");
// printf("Key: %s\n", key); // printf("Key: %s\n", key);
key_string = key; key_string = key;
// pthread_mutex_lock(&cLock); // pthread_mutex_lock(&cLock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment