-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspellChecker.h
More file actions
62 lines (55 loc) · 1.5 KB
/
Copy pathspellChecker.h
File metadata and controls
62 lines (55 loc) · 1.5 KB
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
//libraries used throughout program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <pthread.h>
#include <ctype.h>
//constant for default socket port
#define DEFAULT_SOCKET 4000
//constant for default dictionary
#define DEFAULT_DICTIONARY "dictionary.txt"
//constant for maximum word size
#define WORD_SIZE 100
//constant for maximum buffer size
#define MAX_BUF_SIZE 3
//constant for maximum buffer size
#define NUM_WORKERS 2
// global variable. file pointer to dictionary file
FILE *DICTIONARY;
//global variable. file pointer to log file
FILE *LOG;
//global integer variable for port that users connect to to us spellcheck
int PORT;
//global integer array to hold clients
int jobs[MAX_BUF_SIZE];
//global pointer array to hold client logged data
char *logs[MAX_BUF_SIZE];
//struct for server
typedef struct {
int job_count;
int log_count;
int job_front;
int job_rear;
int log_front;
int log_rear;
pthread_mutex_t job_mutex;
pthread_mutex_t log_mutex;
pthread_cond_t job_not_empty;
pthread_cond_t job_not_full;
pthread_cond_t log_not_empty;
pthread_cond_t log_not_full;
}server;
//function prototypes
void initServer(server *server);
void insertLog(server *server, char *item, int correct);
void insertJob(server *server, int socket);
char *removeLog(server *server);
int removeJob(server *server);
int openListenfd(int port);
int findWord(char *word);
void *workerThread(void *serve);
void *loggerThread(void *serve);