#include<fcntl.h>
#include<cstdio>
#include<unistd.h>
#include<cstdlib>
#include<sys/socket.h>
#include<sys/epoll.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<errno.h>
#include<cstring>
#include<pthread.h>
const int EPOLL_SIZE=5000;
const int EVENT_ARR=5000;
const int PORT=8002;
const int BUF_SIZE=5000;
const int BACK_QUEUE=100;
const int THREAD_MAX=100;
static unsigned int s_thread_para[THREAD_MAX][8]; //线程参数
static pthread_t s_tid[THREAD_MAX]; //线程ID
pthread_mutex_t s_mutex[THREAD_MAX]; //线程锁
int epFd; //epoll
struct epoll_event ev,evs[EVENT_ARR];
char *get_type(char *url,char *buf)
{
const char *t=url+strlen(url);
char type[64];
for(;t>=url&&*t!='.';--t) ;
strcpy(type,t+1);
if(strcmp(type,"html")==0||strcmp(type,"htm")==0)
sprintf(buf,"text/%s",type);
else if(strcmp(type,"gif")==0||
strcmp(type,"jpg")==0||
strcmp(type,"jpeg")==0||
strcmp(type,"png")==0)
sprintf(buf,"image/%s",type);
else if(strcmp(type,"/")==0)
sprintf(buf,"text/html");
else if(strcmp(type,"css")==0)
sprintf(buf,"text/css");
else if(strcmp(type,"js")==0)
sprintf(buf,"application/x-
java script");
else
{
sprintf( buf, "unknown" );
}
return buf;
}
void* http_server(int thread_para[])
{
int pool_index; //thread pool ID
int clientFd; //client socket
char buf[BUF_SIZE];
pthread_detach(pthread_self());
pool_index=thread_para[7];
wait_unlock:
pthread_mutex_lock(s_mutex+pool_index); //wait for thread unlock
clientFd=thread_para[1]; //client socket ID
&