Skip to content
Snippets Groups Projects
Commit a0271ac7 authored by Mengqi Chen's avatar Mengqi Chen
Browse files

can compile

parent d94f151c
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,6 @@ int main(int argc, char **argv) {
// events[0].fd will always be the listening_socket fd
// then for each i > 0, events[i].fd = client_fd, and events[i + 1].fd = corresponding worker_fd
struct pollfd events[1 + num_threads];
int client_fds[num_threads];
int num_fds = 1;
int poll_timeout = -1; // -1 is same as infinite timeout
bool resize_events_arr = false;
......
......@@ -5,14 +5,23 @@ PROGS = 550server
all: $(PROGS)
550server: 550server.o server_util.o
550server: 550server.o server_util.o server_socket.o threadpool.o verify550.o
$(CC) $(CFLAGS) -o $@ $^
550server.o: 550server.cpp server_util.h
550server.o: 550server.cpp server_util.h server_socket.h threadpool.h
$(CC) $(CFLAGS) -c $<
server_util.o: server_util.cpp server_util.h
$(CC) $(FLAGS) -c $<
server_socket.o: server_socket.cpp server_socket.h
$(CC) $(FLAGS) -c $<
threadpool.o: threadpool.cpp threadpool.h verify550.h
$(CC) $(FLAGS) -c $<
verify550.o: verify550.cpp verify550.h
$(CC) $(FLAGS) -c $<
clean:
rm -f $(PROGS) *.o *~
\ No newline at end of file
......@@ -9,8 +9,8 @@
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <cstring>
using namespace std;
int Listen(char *portnum) {
// Populate the "hints" addrinfo structure for getaddrinfo().
......
......@@ -2,6 +2,7 @@
#define SERVER_UTIL_H_
#include <cstring>
#include <string>
using namespace std;
......
#include <unistd.h>
#include <iostream>
#include <string>
#include "./threadpool.h"
using namespace std;
// This is the thread start routine, i.e., the function that threads
// are born into.
void *ThreadLoop(void *t_pool);
......
......@@ -7,9 +7,12 @@ extern "C" {
#include <stdint.h> // for uint32_t, etc.
#include <list> // for std::list
#include <string>
#include "./verify550.h" // For asserts
using namespace std;
static const int FILE_BUFFER_SIZE = 2000000;
class ThreadPool {
......@@ -69,6 +72,14 @@ class ThreadPool {
pthread_t *thread_array_;
};
typedef struct Work {
string filepath;
char buffer[FILE_BUFFER_SIZE]; // Buffer for main thread to read file contents from worker thread
int written; // Number of bytes (char) that the worker thread has written to the buffer
int pipe_fd; // Write end for the pipe. Used to notify main thread that the worker is done writing the file contents.
int client_fd; // Client that this work is for
} Work;
class HttpServerTask : public ThreadPool::Task {
public:
explicit HttpServerTask(ThreadPool::thread_task_fn f)
......@@ -76,12 +87,6 @@ class HttpServerTask : public ThreadPool::Task {
Work* work;
};
struct Work {
string filepath;
char buffer[FILE_BUFFER_SIZE]; // Buffer for main thread to read file contents from worker thread
int written; // Number of bytes (char) that the worker thread has written to the buffer
int pipe_fd; // Write end for the pipe. Used to notify main thread that the worker is done writing the file contents.
int client_fd; // Client that this work is for
};
#endif // THREADPOOL_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment