Commit fd69388c authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

infinite looping problem!

parent aed86122
......@@ -20,7 +20,7 @@ client library interfaces to do the actual operations.
#include "KVMessageFormat.h"
#include <arpa/inet.h>
#define MAX 80
#define PORT 6969
#define PORT 8000
#define SA struct sockaddr
struct message *request(char status,char* key,char* value)
{
......@@ -51,7 +51,19 @@ struct message *request(char status,char* key,char* value)
return requestMessage;
}
struct message* requestMessage;
void func(int sockfd,struct message* requestMessage)
{
char buff[MAX];
int n;
for (;;) {
bzero(buff, sizeof(buff));
n = 0;
if((n++)==0)
write(sockfd, requestMessage, sizeof(struct message));
//printf("[Message sent to server]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
}
}
int main(int argc, char const *argv[])
{
int sock = 0, valread;
......@@ -83,11 +95,11 @@ int main(int argc, char const *argv[])
char value[256]="cde";
struct message *requestMessage= request('g',key,value);
struct message *replyMessage=malloc(sizeof(struct message));
send(sock , requestMessage ,sizeof(struct message) , 0 );
printf("Hello message sent\n");
valread = read( sock , replyMessage, sizeof(struct message));
printf("[Message Received from client]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",replyMessage->status,replyMessage->key,replyMessage->value);
///send(sock , requestMessage ,sizeof(struct message) , 0 );
///printf("Hello message sent\n");
func(sock,requestMessage);
// valread = read( sock , replyMessage, sizeof(struct message));
//printf("[Message Received from client]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",replyMessage->status,replyMessage->key,replyMessage->value);
return 0;
}
\ No newline at end of file
......@@ -74,14 +74,15 @@ error. (Assume each character to be 1 byte in size)
void *worker(void *args) {
struct epoll_event ev, events[MAX_EVENTS];
struct epoll_event ev,events[MAX_EVENTS];
struct epoll_event socketEvent;
socketEvent.events=EPOLLIN;
int read_pipe, conn_sock, nfds, i;
int epollfd;
int *newfd=malloc(sizeof(int));
read_pipe = ((int *) args)[0];
read_pipe = ((int *) args)[0]; //assigned the read end of the pipe
epollfd = epoll_create1(0);
if (epollfd == -1) {
perror("epoll_create1");
......@@ -105,18 +106,19 @@ void *worker(void *args) {
if (events[i].data.fd == read_pipe) {
fflush(stdout);
read(read_pipe, newfd, sizeof(newfd));
printf("\nread %d", *newfd);
ev.events = EPOLLIN;
ev.data.fd = *newfd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &ev) == -1) {
printf("\nread %d\n", *newfd);
socketEvent.data.fd=*newfd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, *newfd, &socketEvent) == -1) {
perror("epoll_ctl: read_pipe");
printf("haga\n");
exit(EXIT_FAILURE);
}
fflush(stdout);
}
else{
else if(events[i].data.fd == *newfd) {
struct message *requestMessage= malloc(sizeof(struct message));
read( events[i].data.fd , requestMessage, sizeof(struct message));
read( *newfd , requestMessage, sizeof(struct message));
printf("[Message Received from client]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
}
......@@ -132,7 +134,7 @@ int main (int argc, int argv) {
int i;
int next = 0; // to decide which worker thread to assign client in round robin fashion
pthread_t *threads; // set of all worker threads
int pool_thread_size = 5; // TODO: get pool thread size from config file
int pool_thread_size = 1; // TODO: get pool thread size from config file
int sockfd, newsockfd, portno, clilen, n;
struct sockaddr_in serv_addr, cli_addr;
......@@ -153,7 +155,7 @@ int main (int argc, int argv) {
exit(1);
}
memset(&serv_addr, 0, sizeof(serv_addr));
portno = 6969;
portno = 8000;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(portno);
serv_addr.sin_addr.s_addr = INADDR_ANY;
......
No preview for this file type
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