Commit a8ac017f authored by Samarth Joshi's avatar Samarth Joshi

Merging changes

parents 402105da 4b88969f
......@@ -9,9 +9,9 @@
#include <string.h>
#include "KVMessageFormat.h"
#define MAX_EVENTS 10
static int thread=0;
void *worker(void *args) {
thread++;
struct epoll_event ev,events[MAX_EVENTS];
struct epoll_event socketEvent;
socketEvent.events=EPOLLIN;
......@@ -47,7 +47,8 @@ void *worker(void *args) {
if (events[i].data.fd == read_pipe) {
/* if we get a request from main thread to add new client */
read(read_pipe, newfd, sizeof(newfd));
printf("[%s] read %d\n", name, *newfd);
printf("\nread %d\n", read_pipe);
ev.data.fd=*newfd;
ev.events = EPOLLIN | EPOLLRDHUP;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &ev) == -1) {
......@@ -72,7 +73,7 @@ void *worker(void *args) {
struct message *requestMessage= malloc(sizeof(struct message));
int readlength=read(events[i].data.fd , requestMessage, sizeof(struct message));
printf("\n[Message Received from client]\n[[Status:%d][Key:%s][Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
/*Process the message and send appropriate response to client*/
requestMessage->status=200;
write(events[i].data.fd,requestMessage, sizeof(struct message));
fflush(stdout);
......@@ -139,4 +140,4 @@ int main (int argc, int argv) {
}
return 0;
}
\ No newline at end of file
}
No preview for this file type
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