-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
118 lines (97 loc) · 2.79 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// main.h
// octopamine
//
// Created by quake0day on 10/28/12.
// Copyright (c) 2012 quake0day. All rights reserved.
//
#ifndef octopamine_main_h
#define octopamine_main_h
#include <limits.h>
#include <inttypes.h>
#include <stdarg.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h> /* uname() */
#include <semaphore.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/stat.h>
#include <string.h>
#include <arpa/inet.h>
#include <dirent.h> //
#define MAXCLIENT 32
extern int DEBUG_MODE;
extern int LOGGING;
extern int HELP;
extern int PORT;
extern int TIME;
extern int THREADNUM;
extern int SCHED;
extern int client_schedule[MAXCLIENT];
extern int iput_req,iget_req;
extern int clientId[MAXCLIENT];
extern int itail,ihead;
pthread_mutex_t clientId_mutex;
pthread_cond_t clientId_cond;
pthread_mutex_t client_pro_cond;
pthread_mutex_t client_enter_cond;
pthread_mutex_t clientId_req_mutex;
pthread_cond_t clientId_req_cond;
pthread_cond_t clientId_sche;
typedef enum __bool { false = 0, true = 1, } bool;
typedef void* (*FUNC)(void* arg);
typedef struct thpool_job_t{
int socket_client_ID;
long filesize;
char* request;
struct thpool_job_t* prev; // aim to the previous node
struct thpool_job_t* next; // aim to the next node
} thpool_job_t;
/**
Define a working queue
**/
typedef struct thpool_job_queue{
thpool_job_t* head; // head of the queue
thpool_job_t* tail; // tail of the queue
int jobN; // number of jobs
}thpool_job_queue;
typedef struct thpool_t{
pthread_t* thread_id; //< pointer to threads' ID
int thread_count; //< amount of threads
thpool_job_queue* jobqueue; //< pointer to the job queue
}thpool_t;
typedef struct Thread{
pthread_t thread_id; // thread ID
long thread_count; // # connections handled
} Thread;
void process_request(char *rq, int fd);
char* special_folder(char *f);
int request_arg_judge(char *f);
int request_file_type(char *f);
void provide_header(int file_type,char *f,FILE *socket);
char *show_date();
int find_crnl(FILE *fp);
int show_404(char *arg, int fd);
int show_dir(char *dir, int fd);
int thpool_jobqueue_clean(thpool_t* thread_p);
int show_job_queue(thpool_t* thread_p);
int get_cmd_ret(char *cmd,char *buf,int len);
void get_file(int fd,char *f,FILE* socket);
void logging(char *, char *,char *,char *, char *);
//int sjf(int client_socket_id);
//int fcfs(int client_socket_id);
void thread_create(int i);
thpool_t* thpool_init(int threadNum);
int thpool_jobqueue_init(thpool_t* thread_p);
void *thread_listen();
void *thread_schedule();
void thread_exec(thpool_t* thread_p);
#endif