Commit a8ac017f authored by Samarth Joshi's avatar Samarth Joshi

Merging changes

parents 402105da 4b88969f
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include <string.h> #include <string.h>
#include "KVMessageFormat.h" #include "KVMessageFormat.h"
#define MAX_EVENTS 10 #define MAX_EVENTS 10
static int thread=0;
void *worker(void *args) { void *worker(void *args) {
thread++;
struct epoll_event ev,events[MAX_EVENTS]; struct epoll_event ev,events[MAX_EVENTS];
struct epoll_event socketEvent; struct epoll_event socketEvent;
socketEvent.events=EPOLLIN; socketEvent.events=EPOLLIN;
...@@ -47,7 +47,8 @@ void *worker(void *args) { ...@@ -47,7 +47,8 @@ void *worker(void *args) {
if (events[i].data.fd == read_pipe) { if (events[i].data.fd == read_pipe) {
/* if we get a request from main thread to add new client */ /* if we get a request from main thread to add new client */
read(read_pipe, newfd, sizeof(newfd)); read(read_pipe, newfd, sizeof(newfd));
printf("[%s] read %d\n", name, *newfd);
printf("\nread %d\n", read_pipe);
ev.data.fd=*newfd; ev.data.fd=*newfd;
ev.events = EPOLLIN | EPOLLRDHUP; ev.events = EPOLLIN | EPOLLRDHUP;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &ev) == -1) { if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &ev) == -1) {
...@@ -72,7 +73,7 @@ void *worker(void *args) { ...@@ -72,7 +73,7 @@ void *worker(void *args) {
struct message *requestMessage= malloc(sizeof(struct message)); struct message *requestMessage= malloc(sizeof(struct message));
int readlength=read(events[i].data.fd , requestMessage, 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); 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; requestMessage->status=200;
write(events[i].data.fd,requestMessage, sizeof(struct message)); write(events[i].data.fd,requestMessage, sizeof(struct message));
fflush(stdout); fflush(stdout);
......
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