Skip to content

Commit 1fe2390

Browse files
committed
Refactor
1 parent 524e609 commit 1fe2390

26 files changed

+54
-21
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ CC = gcc
55
CFLAGS = -g -Werror
66
LDFLAGS = -lpthread
77

8-
proxy: proxy.c cache.c ./proxy_helpers/error_handling.c service.c robust_io.c ./thread_helpers/sbuf.c ./thread_helpers/semaphore.c socket.c thread.c ./proxy_helpers/url_parser.c ./proxy_helpers/wrappers.c cache.h constants.h ./proxy_helpers/error_handling.h service.h robust_io.h ./thread_helpers/sbuf.h ./thread_helpers/semaphore.h socket.h thread.h ./proxy_helpers/url_parser.h ./proxy_helpers/wrappers.h
9-
$(CC) $(CFLAGS) -o proxy service.c cache.c ./proxy_helpers/error_handling.c robust_io.c ./thread_helpers/sbuf.c ./thread_helpers/semaphore.c socket.c thread.c ./proxy_helpers/url_parser.c ./proxy_helpers/wrappers.c proxy.c $(LDFLAGS)
8+
proxy: proxy.c cache/cache.c proxy-helpers service.c robust-input-output/robust_io.c thread-helpers semaphore/semaphore.c socket-interface/socket.c thread-helpers proxy-helpers proxy-helpers cache/cache.h constants.h proxy-helpers service.h robust-input-output/robust_io.h thread-helpers semaphore/semaphore.h socket-interface/socket.h thread-helpers proxy-helpers proxy-helpers
9+
$(CC) $(CFLAGS) -o proxy service.c ./cache/cache.c ./proxy-helpers/error_handling.c ./robust-input-output/robust_io.c ./thread-helpers/sbuf.c ./semaphore/semaphore.c ./socket-interface/socket.c ./thread-helpers/thread.c ./proxy-helpers/url_parser.c ./proxy-helpers/wrappers.c proxy.c $(LDFLAGS)
1010

1111

1212
# Creates a tarball in ../proxylab-handin.tar that you can then

cache.c renamed to cache/cache.c

File renamed without changes.

cache.h renamed to cache/cache.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define CACHE_H
33
#include <stdio.h>
44
#include <stdlib.h>
5-
#include "constants.h"
6-
#include "proxy_helpers/wrappers.h"
7-
#include "thread_helpers/semaphore.h"
5+
#include "../constants.h"
6+
#include "../proxy-helpers/wrappers.h"
7+
#include "../semaphore/semaphore.h"
88

99
/* Global variables */
1010
extern unsigned long cur_time; /* Used to update timestamp */

proxy

184 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

proxy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
2020
Signal(SIGPIPE, SIG_IGN);
2121

2222
listenfd = Open_listenfd(argv[1]);
23-
printf("Proxy listening on port: %d\n", listenfd);
23+
printf("Proxy listening on port: %s\n", argv[1]);
2424

2525
/* Initialize cache */
2626
cache_init(&cache);
File renamed without changes.

robust_io.h renamed to robust-input-output/robust_io.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <unistd.h>
55
#include <errno.h>
6-
#include "proxy_helpers/error_handling.h"
6+
#include "../proxy-helpers/error_handling.h"
77

88

99
/* Persistent state for the robust I/O (Rio) package */
File renamed without changes.

thread_helpers/semaphore.h renamed to semaphore/semaphore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SEMAPHORE_H
22
#define SEMAPHORE_
33
#include <semaphore.h>
4-
#include "../proxy_helpers/error_handling.h"
4+
#include "../proxy-helpers/error_handling.h"
55
#include "../constants.h"
66

77
extern int cache_line_readcnt[CACHE_LINE_NUM]; /* number of readers per cache line */

service.c

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static void serve_client(int connfd, cache_line_t *cache)
5050
/* Read object from cache */
5151
printf("<-- service from cache -->\n");
5252
service_from_cache(connfd, cache, matched_line_idx);
53+
printf("This is a cached version of the request!\n");
5354
}
5455
else {
5556
printf("Cache miss!\n");

service.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#define PROXY_H
33

44
#include "constants.h"
5-
#include "proxy_helpers/url_parser.h"
6-
#include "proxy_helpers/wrappers.h"
7-
#include "socket.h"
8-
#include "robust_io.h"
9-
#include "thread.h"
10-
#include "thread_helpers/sbuf.h"
11-
#include "thread_helpers/semaphore.h"
12-
#include "cache.h"
5+
#include "proxy-helpers/url_parser.h"
6+
#include "proxy-helpers/wrappers.h"
7+
#include "socket-interface/socket.h"
8+
#include "robust-input-output/robust_io.h"
9+
#include "thread-helpers/thread.h"
10+
#include "thread-helpers/sbuf.h"
11+
#include "semaphore/semaphore.h"
12+
#include "cache/cache.h"
1313

1414
/* Worker thread routine prototype */
1515
void *thread(void *vargp);
File renamed without changes.

socket.h renamed to socket-interface/socket.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <unistd.h>
44
#include <sys/socket.h>
55
#include <arpa/inet.h>
6-
#include "constants.h"
7-
#include "proxy_helpers/error_handling.h"
6+
#include "../constants.h"
7+
#include "../proxy-helpers/error_handling.h"
88

99
/* Simplifies calls to bind(), connect(), and accept() */
1010
typedef struct sockaddr SA;
File renamed without changes.

thread_helpers/sbuf.h renamed to thread-helpers/sbuf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SBUF_H
22
#define SBUF_H
3-
#include "semaphore.h"
4-
#include "../proxy_helpers/wrappers.h"
3+
#include "../semaphore/semaphore.h"
4+
#include "../proxy-helpers/wrappers.h"
55

66
#define NTHREADS 4
77
#define SBUFSIZE 16
File renamed without changes.

thread.h renamed to thread-helpers/thread.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef THREADING_H
22
#define THREADING_H
33
#include <pthread.h>
4-
#include "proxy_helpers/error_handling.h"
4+
#include "../proxy-helpers/error_handling.h"
55

66
/* Pthreads thread control wrappers prototypes */
77
void Pthread_create(pthread_t *tidp, pthread_attr_t *attrp,

0 commit comments

Comments
 (0)