Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp2023-2018-project-1
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
Model registry
Operate
Environments
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
Saleh Ahmed Khan
comp2023-2018-project-1
Commits
d6a1002d
Commit
d6a1002d
authored
Apr 18, 2018
by
Saleh Ahmed Khan
Browse files
Options
Downloads
Patches
Plain Diff
Multithreaded server is a go :)
parent
d6e59d18
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.vscode/settings.json
+2
-1
2 additions, 1 deletion
.vscode/settings.json
makefile
+3
-2
3 additions, 2 deletions
makefile
server.c
+24
-26
24 additions, 26 deletions
server.c
with
29 additions
and
29 deletions
.vscode/settings.json
+
2
−
1
View file @
d6a1002d
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
"type_traits"
:
"c"
,
"type_traits"
:
"c"
,
"xstring"
:
"c"
,
"xstring"
:
"c"
,
"xutility"
:
"c"
,
"xutility"
:
"c"
,
"stdio.h"
:
"c"
"stdio.h"
:
"c"
,
"stat.h"
:
"c"
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
makefile
+
3
−
2
View file @
d6a1002d
server
:
server.c get.c
server
:
server.c get.c
gcc
-o
server server.c get.c
gcc
-o
server server.c get.c
-lpthread
debug
:
server.c get.c
gcc
-o
server server.c get.c
-lpthread
-g
client
:
client.c
client
:
client.c
gcc
-o
client client.c
gcc
-o
client client.c
...
...
This diff is collapsed.
Click to expand it.
server.c
+
24
−
26
View file @
d6a1002d
...
@@ -61,39 +61,37 @@ int main(int argc, char *argv[])
...
@@ -61,39 +61,37 @@ int main(int argc, char *argv[])
incoming connection requests will be queued */
incoming connection requests will be queued */
listen
(
sockfd
,
5
);
listen
(
sockfd
,
5
);
clilen
=
sizeof
(
cli_addr
);
clilen
=
sizeof
(
cli_addr
);
char
*
root
=
argv
[
2
];
while
(
1
)
{
/* Accept a connection - block until a connection is ready to
/* Accept a connection - block until a connection is ready to
be accepted. Get back a new file descriptor to communicate on. */
be accepted. Get back a new file descriptor to communicate on. */
newsockfd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
cli_addr
,
newsockfd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
cli_addr
,
&
clilen
);
&
clilen
);
if
(
newsockfd
<
0
)
{
if
(
newsockfd
<
0
)
{
perror
(
"ERROR on accept"
);
perror
(
"ERROR on accept"
);
exit
(
1
);
// exit(1);
continue
;
}
}
if
(
!
fork
())
{
bzero
(
buffer
,
BUF
);
close
(
sockfd
);
/* Read characters from the connection,
printf
(
"closed sockfd
\n
"
);
then process */
// bzero(buffer,BUF);
/* Read characters from the connection, then process */
n
=
read
(
newsockfd
,
buffer
,
BUF
-
1
);
n
=
read
(
newsockfd
,
buffer
,
BUF
-
1
);
/* ******************************************************************************** */
/* ******************************************************************************** */
/* ******************************************************************************** */
char
*
root
=
argv
[
2
];
// Extract just the file path from the request message into the char array 'path'.
parse_request_and_send_response
(
root
,
buffer
,
newsockfd
);
parse_request_and_send_response
(
root
,
buffer
,
newsockfd
);
close
(
newsockfd
);
printf
(
"closed newsockfd
\n
"
);
// printf("Here is the message: %s\n",buffer);
}
// printf("Here is the path calculated: %s + %s = %s\n", root, path, full_path);
close
(
newsockfd
);
printf
(
"closed sockfd in parent
\n
"
);
}
if
(
n
<
0
)
{
if
(
n
<
0
)
{
perror
(
"ERROR writing to socket"
);
perror
(
"ERROR writing to socket"
);
exit
(
1
);
exit
(
1
);
}
}
/* close socket */
/* close socket */
close
(
sockfd
);
//
close(sockfd);
return
0
;
return
0
;
}
}
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