Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
key-value-store
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Samarth Joshi
key-value-store
Commits
a8ac017f
Commit
a8ac017f
authored
Oct 27, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Plain Diff
Merging changes
parents
402105da
4b88969f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
KVServer.c
KVServer.c
+6
-5
server
server
+0
-0
No files found.
KVServer.c
View file @
a8ac017f
...
...
@@ -9,9 +9,9 @@
#include <string.h>
#include "KVMessageFormat.h"
#define MAX_EVENTS 10
static
int
thread
=
0
;
void
*
worker
(
void
*
args
)
{
thread
++
;
struct
epoll_event
ev
,
events
[
MAX_EVENTS
];
struct
epoll_event
socketEvent
;
socketEvent
.
events
=
EPOLLIN
;
...
...
@@ -47,7 +47,8 @@ void *worker(void *args) {
if
(
events
[
i
].
data
.
fd
==
read_pipe
)
{
/* if we get a request from main thread to add new client */
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
printf
(
"[%s] read %d
\n
"
,
name
,
*
newfd
);
printf
(
"
\n
read %d
\n
"
,
read_pipe
);
ev
.
data
.
fd
=*
newfd
;
ev
.
events
=
EPOLLIN
|
EPOLLRDHUP
;
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
*
newfd
,
&
ev
)
==
-
1
)
{
...
...
@@ -72,7 +73,7 @@ void *worker(void *args) {
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
int
readlength
=
read
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
printf
(
"
\n
[Message Received from client]
\n
[[Status:%d][Key:%s][Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
/*Process the message and send appropriate response to client*/
requestMessage
->
status
=
200
;
write
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
fflush
(
stdout
);
...
...
@@ -139,4 +140,4 @@ int main (int argc, int argv) {
}
return
0
;
}
\ No newline at end of file
}
server
View file @
a8ac017f
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment