first commit
This commit is contained in:
3
CS4210/Project 3/server/CVS/Entries
Normal file
3
CS4210/Project 3/server/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src////
|
||||
/Makefile/1.3/Sun Apr 2 10:09:36 2006//
|
||||
/l33t_server.conf/1.3/Sun Apr 2 10:09:36 2006//
|
||||
3
CS4210/Project 3/server/CVS/Entries.Extra
Normal file
3
CS4210/Project 3/server/CVS/Entries.Extra
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src///////
|
||||
/Makefile////*///
|
||||
/l33t_server.conf////*///
|
||||
3
CS4210/Project 3/server/CVS/Entries.Extra.Old
Normal file
3
CS4210/Project 3/server/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src///////
|
||||
/l33t_server.conf////*///
|
||||
/Makefile////*///
|
||||
3
CS4210/Project 3/server/CVS/Entries.Old
Normal file
3
CS4210/Project 3/server/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src////
|
||||
/l33t_server.conf/0/dummy timestamp//
|
||||
/Makefile/0/dummy timestamp//
|
||||
1
CS4210/Project 3/server/CVS/Repository
Normal file
1
CS4210/Project 3/server/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/server
|
||||
1
CS4210/Project 3/server/CVS/Root
Normal file
1
CS4210/Project 3/server/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
43
CS4210/Project 3/server/Makefile
Normal file
43
CS4210/Project 3/server/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
CC = gcc
|
||||
OPT = -O2 -fomit-frame-pointer
|
||||
LIBS = -lpthread
|
||||
TARGET = l33t_server
|
||||
MISC = Makefile
|
||||
INCDIR = src/include
|
||||
SRCDIR = src
|
||||
BINDIR = ../bin/server
|
||||
COMMONDIR = ../common
|
||||
MAKE = make
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(BINDIR)/parser.o $(BINDIR)/settings.o $(BINDIR)/thread_pool.o $(BINDIR)/networking.o $(BINDIR)/sock_lib.o $(BINDIR)/http.o $(BINDIR)/shared_memory.o $(BINDIR)/main.o $(COMMONDIR)/defs.h
|
||||
$(CC) $(OPT) $(LIBS) -o $(BINDIR)/$(TARGET) $(BINDIR)/*.o
|
||||
|
||||
$(BINDIR)/parser.o: $(COMMONDIR)/config_parser/parser.h $(COMMONDIR)/config_parser/parser.c
|
||||
-mkdir -p $(BINDIR) > /dev/null
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/parser.o $(COMMONDIR)/config_parser/parser.c
|
||||
|
||||
$(BINDIR)/settings.o: $(SRCDIR)/settings.c $(INCDIR)/settings.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/settings.o $(SRCDIR)/settings.c
|
||||
|
||||
$(BINDIR)/thread_pool.o: $(COMMONDIR)/thread_pool/thread_pool.h $(COMMONDIR)/thread_pool/thread_pool.c
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/thread_pool.o $(COMMONDIR)/thread_pool/thread_pool.c
|
||||
|
||||
$(BINDIR)/networking.o: $(COMMONDIR)/networking/networking.h $(COMMONDIR)/networking/networking.c
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/networking.o $(COMMONDIR)/networking/networking.c
|
||||
|
||||
$(BINDIR)/sock_lib.o: $(SRCDIR)/sock_lib.c $(INCDIR)/sock_lib.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/sock_lib.o $(SRCDIR)/sock_lib.c
|
||||
|
||||
$(BINDIR)/http.o: $(COMMONDIR)/http/http.c $(COMMONDIR)/http/http.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/http.o $(COMMONDIR)/http/http.c
|
||||
|
||||
$(BINDIR)/shared_memory.o: $(COMMONDIR)/shared_memory/shared_memory.c $(COMMONDIR)/shared_memory/shared_memory.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/shared_memory.o $(COMMONDIR)/shared_memory/shared_memory.c
|
||||
|
||||
$(BINDIR)/main.o: $(SRCDIR)/main.c
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/main.o $(SRCDIR)/main.c
|
||||
|
||||
clean:
|
||||
rm -f $(BINDIR)/*.o $(BINDIR)/$(TARGET)
|
||||
19
CS4210/Project 3/server/l33t_server.conf
Normal file
19
CS4210/Project 3/server/l33t_server.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
# Lines beginning with # will be ignored
|
||||
#
|
||||
# l33t_server config file
|
||||
#
|
||||
# This file will override internal static compiled
|
||||
# default configurations for the server.
|
||||
#
|
||||
# Any settings in this file will be overwritten by any command line
|
||||
# arguments passed to the application.
|
||||
#
|
||||
|
||||
# Load Dir
|
||||
LOAD_DIR:../
|
||||
|
||||
# MAX_THREADS
|
||||
MAX_THREADS:16
|
||||
|
||||
# Port Number
|
||||
PORT_NUMBER:1337
|
||||
4
CS4210/Project 3/server/src/CVS/Entries
Normal file
4
CS4210/Project 3/server/src/CVS/Entries
Normal file
@@ -0,0 +1,4 @@
|
||||
D/include////
|
||||
/main.c/1.3/Sun Apr 2 10:09:36 2006//
|
||||
/settings.c/1.3/Sun Apr 2 10:09:36 2006//
|
||||
/sock_lib.c/1.3/Sun Apr 2 10:09:36 2006//
|
||||
4
CS4210/Project 3/server/src/CVS/Entries.Extra
Normal file
4
CS4210/Project 3/server/src/CVS/Entries.Extra
Normal file
@@ -0,0 +1,4 @@
|
||||
D/include///////
|
||||
/main.c////*///
|
||||
/settings.c////*///
|
||||
/sock_lib.c////*///
|
||||
4
CS4210/Project 3/server/src/CVS/Entries.Extra.Old
Normal file
4
CS4210/Project 3/server/src/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,4 @@
|
||||
D/include///////
|
||||
/main.c////*///
|
||||
/settings.c////*///
|
||||
/sock_lib.c////*///
|
||||
4
CS4210/Project 3/server/src/CVS/Entries.Old
Normal file
4
CS4210/Project 3/server/src/CVS/Entries.Old
Normal file
@@ -0,0 +1,4 @@
|
||||
D/include////
|
||||
/main.c/0/dummy timestamp//
|
||||
/settings.c/0/dummy timestamp//
|
||||
/sock_lib.c/0/dummy timestamp//
|
||||
1
CS4210/Project 3/server/src/CVS/Repository
Normal file
1
CS4210/Project 3/server/src/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/server/src
|
||||
1
CS4210/Project 3/server/src/CVS/Root
Normal file
1
CS4210/Project 3/server/src/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
3
CS4210/Project 3/server/src/include/CVS/Entries
Normal file
3
CS4210/Project 3/server/src/include/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/settings.h/1.3/Sun Apr 2 10:09:36 2006//
|
||||
/sock_lib.h/1.3/Sun Apr 2 10:09:36 2006//
|
||||
D
|
||||
2
CS4210/Project 3/server/src/include/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/server/src/include/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/settings.h////*///
|
||||
/sock_lib.h////*///
|
||||
@@ -0,0 +1,2 @@
|
||||
/settings.h////*///
|
||||
/sock_lib.h////*///
|
||||
3
CS4210/Project 3/server/src/include/CVS/Entries.Old
Normal file
3
CS4210/Project 3/server/src/include/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/settings.h/0/dummy timestamp//
|
||||
/sock_lib.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/server/src/include/CVS/Repository
Normal file
1
CS4210/Project 3/server/src/include/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/server/src/include
|
||||
1
CS4210/Project 3/server/src/include/CVS/Root
Normal file
1
CS4210/Project 3/server/src/include/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
21
CS4210/Project 3/server/src/include/settings.h
Normal file
21
CS4210/Project 3/server/src/include/settings.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _SETTINGS_H_
|
||||
#define _SETTINGS_H_
|
||||
|
||||
/////////////
|
||||
// Globals //
|
||||
/////////////
|
||||
|
||||
typedef struct {
|
||||
char* LOAD_DIR; // Server home directory
|
||||
char* CONFIG_FILE; // Config File, should be constant
|
||||
int MAX_THREADS; // Maximum number of threads to spawn
|
||||
unsigned short PORT_NUMBER; // Port number to use
|
||||
char useSHMEM;
|
||||
} settings_t;
|
||||
///////////////
|
||||
// Functions //
|
||||
///////////////
|
||||
|
||||
int init_settings(settings_t *s, int, char**);
|
||||
|
||||
#endif
|
||||
11
CS4210/Project 3/server/src/include/sock_lib.h
Normal file
11
CS4210/Project 3/server/src/include/sock_lib.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* Puyan Lotfi
|
||||
* Berkeley Sockets Abstaction
|
||||
*/
|
||||
|
||||
void *consumer(void*);
|
||||
void *producer(void* v_port_number);
|
||||
|
||||
int ContructTCPSocket(unsigned short port);
|
||||
int AcceptConnection(int server_socket);
|
||||
|
||||
|
||||
82
CS4210/Project 3/server/src/main.c
Normal file
82
CS4210/Project 3/server/src/main.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "include/sock_lib.h"
|
||||
#include "include/settings.h"
|
||||
#include "../../common/defs.h"
|
||||
#include "../../common/thread_pool/thread_pool.h"
|
||||
#include "../../common/shared_memory/shared_memory.h"
|
||||
|
||||
/* signal handler for SIGINT */
|
||||
void catch_int(int sig_num)
|
||||
{
|
||||
// TODO: Insert memory freeing stuff here
|
||||
printf("Signal %d received\n", sig_num);
|
||||
printf("Destroying the Shared Memory Segments...\n");
|
||||
destroy_shared_memory();
|
||||
printf("Done!\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
settings_t settings;
|
||||
int c = '\0'; //character to get
|
||||
|
||||
#ifndef LINUX
|
||||
sigset_t newmask;
|
||||
sigset_t oldmask;
|
||||
sigemptyset(&newmask);
|
||||
sigaddset(&newmask, SIGPIPE);
|
||||
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
|
||||
{
|
||||
fprintf(stderr, "can't set signal mask\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("* Beginning l33t_server Initialization *\n\n");
|
||||
|
||||
init_settings(&settings, argc, argv);
|
||||
|
||||
printf("** Using %d threads\n",settings.MAX_THREADS);
|
||||
printf("** Using home_dir: %s\n",settings.LOAD_DIR);
|
||||
printf( (settings.useSHMEM == 0 ? "** Not " : "** "));
|
||||
printf( "Using Shared Memory.\n");
|
||||
|
||||
if (settings.useSHMEM) {
|
||||
// Mask signals (fancy, isn't it?)
|
||||
signal(SIGINT, catch_int);
|
||||
signal(SIGABRT, catch_int);
|
||||
signal(SIGSEGV, catch_int);
|
||||
signal(SIGTERM, catch_int);
|
||||
signal(SIGBUS, catch_int);
|
||||
|
||||
init_shared_memory();
|
||||
}
|
||||
|
||||
if (chdir(settings.LOAD_DIR) < 0) {
|
||||
printf("*** Error setting home directory..Exiting\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
printf("* l33t_server started *\n\n");
|
||||
|
||||
init_thread_pool(&(settings.PORT_NUMBER), settings.MAX_THREADS,
|
||||
producer, consumer, &settings);
|
||||
|
||||
while (getchar() != 'q');
|
||||
|
||||
if (settings.useSHMEM) {
|
||||
catch_int(SIGINT);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
93
CS4210/Project 3/server/src/settings.c
Normal file
93
CS4210/Project 3/server/src/settings.c
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "include/settings.h"
|
||||
#include "../../common/config_parser/parser.h"
|
||||
#include "../../common/defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* Set the default values for all the variables
|
||||
*/
|
||||
static void setDefaults(settings_t *s) {
|
||||
s->LOAD_DIR = ".";
|
||||
s->CONFIG_FILE = "l33t_server.conf";
|
||||
s->MAX_THREADS = 7;
|
||||
s->PORT_NUMBER = 1337; // l33t
|
||||
s->useSHMEM = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize internal server parameters
|
||||
*/
|
||||
int init_settings(settings_t *s, int argc, char** argv) {
|
||||
ConfigFile* configFile;
|
||||
|
||||
VPRINTF(("** Reading Config File **\n\n"));
|
||||
|
||||
setDefaults(s);
|
||||
|
||||
switch (argc) {
|
||||
case 3:
|
||||
s->CONFIG_FILE = argv[2];
|
||||
s->useSHMEM = atoi(argv[1]);
|
||||
break;
|
||||
case 2:
|
||||
s->useSHMEM = atoi(argv[1]);
|
||||
break;
|
||||
default:
|
||||
cmdline_error:
|
||||
printf("Proper Usage: \n");
|
||||
printf(" ./l33t_server use_shared_memory [configFile]\n");
|
||||
printf(" e.g. ./l33t_server 1\n");
|
||||
printf(" e.g. ./l33t_server 0 l33t_server2.conf\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (s->useSHMEM != 0 && s->useSHMEM != 1) goto cmdline_error;
|
||||
|
||||
configFile = loadFile(s->CONFIG_FILE);
|
||||
|
||||
if (!configFile) {
|
||||
printf("*** configuration file \"%s\" not found.\n",s->CONFIG_FILE);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (nextSet(configFile)) {
|
||||
|
||||
if (!strcmp(configFile->currentParamter, "LOAD_DIR")) {
|
||||
VPRINTF(("*** Read LOAD_FILE Value: %s\n",configFile->currentValue));
|
||||
s->LOAD_DIR = malloc(strlen(configFile->currentValue)+1);
|
||||
strcpy(s->LOAD_DIR, configFile->currentValue);
|
||||
|
||||
} else if(!strcmp(configFile->currentParamter, "CONFIG_FILE")) {
|
||||
VPRINTF(("*** Read CONFIG_FILE Value: %s\n",configFile->currentValue));
|
||||
s->CONFIG_FILE = malloc(strlen(configFile->currentValue)+1);
|
||||
strcpy(s->CONFIG_FILE, configFile->currentValue);
|
||||
|
||||
} else if(!strcmp(configFile->currentParamter, "MAX_THREADS")) {
|
||||
s->MAX_THREADS = atoi(configFile->currentValue);
|
||||
|
||||
// In case some idiot tries to set the MAX_THREADS <=0
|
||||
if (s->MAX_THREADS < 1) {
|
||||
s->MAX_THREADS = 1;
|
||||
}
|
||||
|
||||
VPRINTF(("*** Read MAX_THREADS Value: %d\n",s->MAX_THREADS));
|
||||
|
||||
} else if(!strcmp(configFile->currentParamter, "PORT_NUMBER")) {
|
||||
s->PORT_NUMBER = atoi(configFile->currentValue);
|
||||
VPRINTF(("*** Read PORT_NUMBER Value: %d\n",s->PORT_NUMBER));
|
||||
|
||||
} else {
|
||||
printf("**** Illegal Parameter Exception in Config File:\n");
|
||||
printf("**** \"%s:%s\"\n", configFile->currentParamter, configFile->currentValue);
|
||||
printf("**** is not a legal Configuration Parameter.\n");
|
||||
}
|
||||
}
|
||||
|
||||
VPRINTF(("\n** Done Reading Config File **\n\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
202
CS4210/Project 3/server/src/sock_lib.c
Normal file
202
CS4210/Project 3/server/src/sock_lib.c
Normal file
@@ -0,0 +1,202 @@
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <unistd.h> /* close() */
|
||||
#include <sys/socket.h> /* Socket Functions */
|
||||
#include <sys/types.h> /* Socket Datatypes */
|
||||
#include <netinet/in.h> /* IP Datatypes */
|
||||
#include <arpa/inet.h> /* Address Structs */
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h> /* Standard IO */
|
||||
#include <stdlib.h> /* Standard Lib */
|
||||
#include <string.h> /* String Libs */
|
||||
|
||||
#include "include/sock_lib.h" /* My Functions */
|
||||
#include "include/settings.h"
|
||||
|
||||
#include "../../common/defs.h" /* Definitions */
|
||||
#include "../../common/http/http.h"
|
||||
#include "../../common/networking/networking.h"
|
||||
#include "../../common/shared_memory/shared_memory.h"
|
||||
|
||||
/*
|
||||
* Producer function
|
||||
*/
|
||||
void *producer(void* v_port_number) {
|
||||
int clntSock; /* client sock descriptor. */
|
||||
int servSock; /* Server sock descriptor. */
|
||||
|
||||
unsigned short port_number = *((unsigned short*)v_port_number);
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD threadID; /* ThreadID from CreateThread().*/
|
||||
WSADATA wsaData; /* Winsock struct. */
|
||||
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)/* Winsock 2.0 DLL. */
|
||||
DieWithError("WSAStartup() failed");
|
||||
#endif
|
||||
|
||||
VPRINTF((" Producer Port %d\n", port_number));
|
||||
|
||||
servSock = ContructTCPSocket(port_number);
|
||||
|
||||
#if _LOG_
|
||||
printf("[PRODUCER] Producer Initialized, listening for connections\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
for(;;) /* Loop forever */
|
||||
{
|
||||
clntSock = AcceptConnection(servSock);
|
||||
if (clntSock == -1) {
|
||||
continue;
|
||||
}
|
||||
addSocket(clntSock);
|
||||
}
|
||||
/* NEVER REACHED... */
|
||||
}
|
||||
|
||||
/*
|
||||
* Request looks as follows (it is assumed to be this way):
|
||||
* LOCAL_GET file shmem_buff_num \0
|
||||
* e.g.
|
||||
* LOCAL_GET /index.html 2
|
||||
* LOCAL_GET /files/panda.png 3
|
||||
*
|
||||
* Notes:
|
||||
* - LOCAL_GET does not support directory listing
|
||||
* - LOCAL_GET will send a simple 404 page
|
||||
*/
|
||||
void handleLocal(char *received) {
|
||||
char* fileName;
|
||||
int shmem_buff_num, i;
|
||||
FILE* fp;
|
||||
|
||||
if (!received) {
|
||||
return;
|
||||
}
|
||||
|
||||
//printf("Got: %s\n", received);
|
||||
|
||||
for (; *received != ' '; received++);
|
||||
received++;
|
||||
|
||||
for (i=0; received[i] != ' '; i++);
|
||||
|
||||
received[i] = '\0';
|
||||
fileName = received;
|
||||
|
||||
shmem_buff_num = atoi(received+i+1);
|
||||
|
||||
//printf("Got request for %s on shmem %d\n", fileName, shmem_buff_num);
|
||||
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
printf("File Not Found, sock_lib.c, %d\n",__LINE__);
|
||||
|
||||
// Put 404
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//printf("Work on: %d\n",shmem_buff_num);
|
||||
for (;;)
|
||||
{
|
||||
char buff[BUFFSIZE-sizeof(int)], *pc;
|
||||
int temp;
|
||||
struct sembuf sembuffer;
|
||||
|
||||
for (i=0; i<BUFFSIZE-sizeof(int); i++) {
|
||||
temp = fgetc(fp);
|
||||
|
||||
if (temp == EOF) {
|
||||
//printf("Got EOF\n");
|
||||
break;
|
||||
}
|
||||
|
||||
buff[i] = temp;
|
||||
}
|
||||
|
||||
// Put stuff on the shared memory segment
|
||||
sembuffer.sem_num = shmem_buff_num;
|
||||
sembuffer.sem_op = -1;
|
||||
sembuffer.sem_flg = 0;
|
||||
|
||||
//printf("Waiting for semserv to be 1\n");
|
||||
semop(semserv, &sembuffer, 1);
|
||||
|
||||
// Now semserv[num] == 0
|
||||
pc = buffptr[shmem_buff_num];
|
||||
|
||||
if (i == 0) {
|
||||
//Last packet
|
||||
*((int*)pc) = -1;
|
||||
|
||||
sembuffer.sem_op = 1;
|
||||
semop(semprox, &sembuffer, 1);
|
||||
|
||||
break;
|
||||
} else {
|
||||
*((int*)pc) = i; // Number of Bytes in this packet
|
||||
pc += sizeof(int);
|
||||
|
||||
for (i=0; i<BUFFSIZE-sizeof(int); i++, pc++) {
|
||||
*pc = buff[i];
|
||||
}
|
||||
|
||||
sembuffer.sem_op = 1;
|
||||
semop(semprox, &sembuffer, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//printf("Done on: %d\n",shmem_buff_num);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consumer Function
|
||||
*/
|
||||
void *consumer(void* dumb) {
|
||||
#if _LOG_
|
||||
#ifndef _WIN32
|
||||
printf("[CONSUMER] Consumer %ld started\n", (long)pthread_self());
|
||||
fflush(stdout);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
settings_t *settings = (settings_t*)dumb;
|
||||
|
||||
for (;;) {
|
||||
char *received;
|
||||
int clntSocket;
|
||||
|
||||
clntSocket = removeSocket(); //This is where it waits!!!
|
||||
uber_recv(clntSocket, BUFFERSIZE, "\0", &received);
|
||||
|
||||
if (strstr(received, LOCAL_GET) && settings->useSHMEM) {
|
||||
handleLocal(received);
|
||||
close(clntSocket);
|
||||
} else {
|
||||
http_proto(clntSocket, received);
|
||||
// Note: The socket isn't being close here.
|
||||
// This is because I use it as a FILE* and then close it.
|
||||
// close(clntSocket);
|
||||
// Don't forget to free()
|
||||
}
|
||||
|
||||
VPRINTF(("Socket %d says goodbye.\n", (int)clntSocket));
|
||||
fflush(stdout);
|
||||
|
||||
free(received);
|
||||
} //end main loop
|
||||
|
||||
return NULL; //never reached
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user