Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cse550
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Winston Jodjana
cse550
Commits
47a35182
Commit
47a35182
authored
2 years ago
by
Winston Jodjana
Browse files
Options
Downloads
Patches
Plain Diff
Struct and Initial Planning
parent
b26e878e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assignment1/partb/550server.cpp
+17
-1
17 additions, 1 deletion
assignment1/partb/550server.cpp
assignment1/partb/threadpool.h
+14
-0
14 additions, 0 deletions
assignment1/partb/threadpool.h
with
31 additions
and
1 deletion
assignment1/partb/550server.cpp
+
17
−
1
View file @
47a35182
...
...
@@ -13,6 +13,10 @@
static
const
int
num_threads
=
16
;
// This is the function that threads are dispatched into
// in order to process new client connections.
static
void
HttpServer_ThrFn
(
ThreadPool
::
Task
*
t
);
// given a program name, it prints
// information about its usage.
void
Usage
(
char
*
progname
);
...
...
@@ -70,7 +74,9 @@ int main(int argc, char **argv) {
unsigned
char
buf
[
BUFFER_SIZE
];
while
(
1
)
{
// TODO: Spawn workers when you see a client connect
// Read file path, clean it up, pass it to worker thread
//
HttpServerTask
*
hst
=
new
HttpServerTask
(
HttpServer_ThrFn
);
// TODO: change to new fields
hst
->
base_dir
=
static_file_dir_path_
;
...
...
@@ -118,6 +124,16 @@ int main(int argc, char **argv) {
return
EXIT_SUCCESS
;
}
static
void
HttpServer_ThrFn
(
ThreadPool
::
Task
*
t
)
{
// TODO: Worker thread logic
// Input: Shared struct with cond. var., buffer, etc
// 1. A worker function that receives the name of a file (absolute file path),
// 2. reads the file content into the address space of the process,
// 3. and arranges to return (a pointer to) the file content to whoever dispatched the thread to the worker function.
// TODO: Tell main thread that task is done, main thread needs to close the connection
}
void
Usage
(
char
*
progname
)
{
std
::
cerr
<<
"usage: "
<<
progname
<<
" port"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
...
...
This diff is collapsed.
Click to expand it.
assignment1/partb/threadpool.h
+
14
−
0
View file @
47a35182
...
...
@@ -67,4 +67,18 @@ class ThreadPool {
pthread_t
*
thread_array_
;
};
class
HttpServerTask
:
public
ThreadPool
::
Task
{
public:
explicit
HttpServerTask
(
ThreadPool
::
thread_task_fn
f
)
:
ThreadPool
::
Task
(
f
)
{
}
Work
*
work
;
};
struct
Work
{
char
*
buffer
;
// 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
pthread_cond_t
buffer_filled
;
// Cond. var. for when the main thread should read from the buffer and write back the file contents to the client
pthread_cond_t
task_finished
;
// Cond. var. for when the worker thread has finished reading all the file contents
};
#endif // THREADPOOL_H_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment