Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs283
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
Container 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joey Le
Cs283
Commits
a7b4c2ec
Commit
a7b4c2ec
authored
3 months ago
by
Joey Le
Browse files
Options
Downloads
Patches
Plain Diff
Ok I forgot to call make the entire time wtf
parent
9ebef86a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment-06/starter/rsh_server.c
+13
-42
13 additions, 42 deletions
Assignment-06/starter/rsh_server.c
with
13 additions
and
42 deletions
Assignment-06/starter/rsh_server.c
+
13
−
42
View file @
a7b4c2ec
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include
<sys/un.h>
#include
<sys/un.h>
#include
<fcntl.h>
#include
<fcntl.h>
#include
<errno.h>
#include
<errno.h>
#include
<pthread.h>
//INCLUDES for extra credit
//INCLUDES for extra credit
//#include <signal.h>
//#include <signal.h>
...
@@ -73,6 +74,8 @@
...
@@ -73,6 +74,8 @@
}
}
/*
/*
* stop_server(svr_socket)
* stop_server(svr_socket)
* svr_socket: The socket that was created in the boot_server()
* svr_socket: The socket that was created in the boot_server()
...
@@ -172,41 +175,6 @@ int stop_server(int svr_socket) {
...
@@ -172,41 +175,6 @@ int stop_server(int svr_socket) {
return
svr_socket
;
return
svr_socket
;
}
}
/*
* process_cli_requests(svr_socket)
*/
int
process_cli_requests
(
int
svr_socket
)
{
int
cli_socket
;
pthread_t
thread_id
;
printf
(
"SERVER: Waiting for client connections...
\n
"
);
while
(
1
)
{
printf
(
"SERVER: Waiting for a client to connect...
\n
"
);
cli_socket
=
accept
(
svr_socket
,
NULL
,
NULL
);
if
(
cli_socket
==
-
1
)
{
perror
(
"SERVER: accept failed"
);
return
ERR_RDSH_COMMUNICATION
;
}
printf
(
"SERVER: Client connected. Socket: %d
\n
"
,
cli_socket
);
if
(
pthread_create
(
&
thread_id
,
NULL
,
exec_client_requests
,
(
void
*
)
&
cli_socket
)
<
0
)
{
perror
(
"SERVER: Failed to create thread"
);
close
(
cli_socket
);
return
ERR_RDSH_COMMUNICATION
;
}
printf
(
"SERVER: Thread created for client. Thread ID: %lu
\n
"
,
(
unsigned
long
)
thread_id
);
pthread_detach
(
thread_id
);
printf
(
"SERVER: Thread detached.
\n
"
);
}
return
OK
;
}
/*
/*
* process_cli_requests(svr_socket)
* process_cli_requests(svr_socket)
* svr_socket: The server socket that was obtained from boot_server()
* svr_socket: The server socket that was obtained from boot_server()
...
@@ -248,6 +216,8 @@ int process_cli_requests(int svr_socket) {
...
@@ -248,6 +216,8 @@ int process_cli_requests(int svr_socket) {
* connections, and negative values terminate the server.
* connections, and negative values terminate the server.
*
*
*/
*/
int
process_cli_requests
(
int
svr_socket
)
{
int
process_cli_requests
(
int
svr_socket
)
{
int
cli_socket
;
int
cli_socket
;
pthread_t
thread_id
;
pthread_t
thread_id
;
...
@@ -255,29 +225,30 @@ int process_cli_requests(int svr_socket) {
...
@@ -255,29 +225,30 @@ int process_cli_requests(int svr_socket) {
printf
(
"SERVER: Waiting for client connections...
\n
"
);
printf
(
"SERVER: Waiting for client connections...
\n
"
);
while
(
1
)
{
while
(
1
)
{
// Accept a client connection
printf
(
"SERVER: Waiting for a client to connect...
\n
"
);
cli_socket
=
accept
(
svr_socket
,
NULL
,
NULL
);
cli_socket
=
accept
(
svr_socket
,
NULL
,
NULL
);
if
(
cli_socket
==
-
1
)
{
if
(
cli_socket
==
-
1
)
{
perror
(
"SERVER: accept failed"
);
perror
(
"SERVER: accept failed"
);
return
ERR_RDSH_COMMUNICATION
;
return
ERR_RDSH_COMMUNICATION
;
}
}
printf
(
"SERVER: Client connected. Socket: %d
\n
"
,
cli_socket
);
printf
(
"SERVER: Client connected. Socket: %d
\n
"
,
cli_socket
);
// Create a new thread to handle the client
if
(
pthread_create
(
&
thread_id
,
NULL
,
exec_client_requests
,
(
void
*
)
&
cli_socket
)
<
0
)
{
if
(
pthread_create
(
&
thread_id
,
NULL
,
exec_client_requests
,
(
void
*
)
&
cli_socket
)
<
0
)
{
perror
(
"SERVER: Failed to create thread"
);
perror
(
"SERVER: Failed to create thread"
);
close
(
cli_socket
);
close
(
cli_socket
);
return
ERR_RDSH_COMMUNICATION
;
return
ERR_RDSH_COMMUNICATION
;
}
}
printf
(
"SERVER: Thread created for client. Thread ID: %lu
\n
"
,
(
unsigned
long
)
thread_id
);
// Detach the thread to allow it to clean up automatically
pthread_detach
(
thread_id
);
pthread_detach
(
thread_id
);
printf
(
"SERVER: Thread detached.
\n
"
);
}
}
return
OK
;
return
OK
;
}
}
/*
/*
* exec_client_requests(cli_socket)
* exec_client_requests(cli_socket)
* cli_socket: The server-side socket that is connected to the client
* cli_socket: The server-side socket that is connected to the client
...
...
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