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
4174ea50
Commit
4174ea50
authored
Oct 27, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changing malloced variable newfd to local variable
parent
6d60454f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
9 deletions
+5
-9
KVServer
KVServer
+0
-0
KVServer.c
KVServer.c
+5
-9
No files found.
KVServer
View file @
4174ea50
No preview for this file type
KVServer.c
View file @
4174ea50
...
@@ -18,10 +18,8 @@ void *worker(void *args) {
...
@@ -18,10 +18,8 @@ void *worker(void *args) {
int
read_pipe
,
conn_sock
,
nfds
,
i
;
int
read_pipe
,
conn_sock
,
nfds
,
i
;
int
epollfd
;
int
epollfd
;
int
*
newfd
=
malloc
(
sizeof
(
int
))
;
int
newfd
;
char
*
name
=
(
char
*
)
malloc
(
5
*
sizeof
(
char
));
epollfd
=
epoll_create1
(
0
);
epollfd
=
epoll_create1
(
0
);
if
(
epollfd
==
-
1
)
{
if
(
epollfd
==
-
1
)
{
perror
(
"epoll_create1"
);
perror
(
"epoll_create1"
);
...
@@ -46,12 +44,12 @@ void *worker(void *args) {
...
@@ -46,12 +44,12 @@ void *worker(void *args) {
for
(
i
=
0
;
i
<
nfds
;
++
i
)
{
for
(
i
=
0
;
i
<
nfds
;
++
i
)
{
if
(
events
[
i
].
data
.
fd
==
read_pipe
)
{
if
(
events
[
i
].
data
.
fd
==
read_pipe
)
{
/* if we get a request from main thread to add new client */
/* if we get a request from main thread to add new client */
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
read
(
read_pipe
,
&
newfd
,
sizeof
(
newfd
));
printf
(
"
\n
read %d
\n
"
,
read_pipe
);
printf
(
"
\n
read %d
\n
"
,
read_pipe
);
ev
.
data
.
fd
=
*
newfd
;
ev
.
data
.
fd
=
newfd
;
ev
.
events
=
EPOLLIN
|
EPOLLRDHUP
;
ev
.
events
=
EPOLLIN
|
EPOLLRDHUP
;
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
*
newfd
,
&
ev
)
==
-
1
)
{
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
newfd
,
&
ev
)
==
-
1
)
{
perror
(
"epoll_ctl: read_pipe"
);
perror
(
"epoll_ctl: read_pipe"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -72,7 +70,7 @@ void *worker(void *args) {
...
@@ -72,7 +70,7 @@ void *worker(void *args) {
/* Parse the actual message from client */
/* Parse the actual message from client */
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
int
readlength
=
read
(
events
[
i
].
data
.
fd
,
requestMessage
,
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
);
printf
(
"
[Message Received from client] (%d, %s, %s)
\n
"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
/*Process the message and send appropriate response to client*/
/*Process the message and send appropriate response to client*/
requestMessage
->
status
=
200
;
requestMessage
->
status
=
200
;
write
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
write
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
...
@@ -133,8 +131,6 @@ int main (int argc, int argv) {
...
@@ -133,8 +131,6 @@ int main (int argc, int argv) {
perror
(
"ERROR on accept"
);
perror
(
"ERROR on accept"
);
write
(
pipes
[
next_thread_to_assign
][
1
],
&
newsockfd
,
sizeof
(
newsockfd
));
write
(
pipes
[
next_thread_to_assign
][
1
],
&
newsockfd
,
sizeof
(
newsockfd
));
printf
(
"main thread value: %d
\n
"
,
newsockfd
);
fflush
(
stdout
);
next_thread_to_assign
=
(
next_thread_to_assign
+
1
)
%
pool_thread_size
;
next_thread_to_assign
=
(
next_thread_to_assign
+
1
)
%
pool_thread_size
;
}
}
...
...
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