Commit 4174ea50 authored by Samarth Joshi's avatar Samarth Joshi

Changing malloced variable newfd to local variable

parent 6d60454f
No preview for this file type
......@@ -18,9 +18,7 @@ void *worker(void *args) {
int read_pipe, conn_sock, nfds, i;
int epollfd;
int *newfd=malloc(sizeof(int));
char *name = (char *) malloc(5 * sizeof(char));
int newfd;
epollfd = epoll_create1(0);
if (epollfd == -1) {
......@@ -46,12 +44,12 @@ void *worker(void *args) {
for ( i= 0; i < nfds; ++i ) {
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));
read(read_pipe, &newfd, sizeof(newfd));
printf("\nread %d\n", read_pipe);
ev.data.fd=*newfd;
ev.data.fd=newfd;
ev.events = EPOLLIN | EPOLLRDHUP;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &ev) == -1) {
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, newfd, &ev) == -1) {
perror("epoll_ctl: read_pipe");
exit(EXIT_FAILURE);
}
......@@ -72,7 +70,7 @@ void *worker(void *args) {
/* Parse the actual message from client */
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);
printf("[Message Received from client] (%d, %s, %s)\n",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));
......@@ -133,8 +131,6 @@ int main (int argc, int argv) {
perror("ERROR on accept");
write(pipes[next_thread_to_assign][1], &newsockfd, sizeof(newsockfd));
printf("main thread value: %d\n",newsockfd);
fflush(stdout);
next_thread_to_assign = (next_thread_to_assign+1) % pool_thread_size;
}
......
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