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
70aaa378
Commit
70aaa378
authored
Oct 26, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding code to remove fd from epoll instance after socket closed by client
parent
409ba370
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
12 deletions
+18
-12
KVClient
KVClient
+0
-0
KVClient.c
KVClient.c
+1
-0
KVServer
KVServer
+0
-0
KVServer.c
KVServer.c
+17
-12
No files found.
KVClient
0 → 100644
View file @
70aaa378
File added
KVClient.c
View file @
70aaa378
...
@@ -63,6 +63,7 @@ void func(int sockfd,struct message* requestMessage)
...
@@ -63,6 +63,7 @@ void func(int sockfd,struct message* requestMessage)
n
++
;
n
++
;
printf
(
"[Message sent to server]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]
\n
"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
printf
(
"[Message sent to server]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]
\n
"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
write
(
sockfd
,
requestMessage
,
sizeof
(
struct
message
));
write
(
sockfd
,
requestMessage
,
sizeof
(
struct
message
));
sleep
(
2
);
}
}
//printf("[Message sent to server]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
//printf("[Message sent to server]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
...
...
KVServer
0 → 100644
View file @
70aaa378
File added
KVServer.c
View file @
70aaa378
...
@@ -108,7 +108,7 @@ void *worker(void *args) {
...
@@ -108,7 +108,7 @@ void *worker(void *args) {
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
printf
(
"
\n
read %d
\n
"
,
*
newfd
);
printf
(
"
\n
read %d
\n
"
,
*
newfd
);
ev
.
data
.
fd
=*
newfd
;
ev
.
data
.
fd
=*
newfd
;
ev
.
events
=
EPOLLIN
;
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
);
...
@@ -117,21 +117,26 @@ void *worker(void *args) {
...
@@ -117,21 +117,26 @@ void *worker(void *args) {
fflush
(
stdout
);
fflush
(
stdout
);
}
}
else
{
else
{
int
flag
=
events
[
i
].
events
;
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
if
(
flag
&
EPOLLRDHUP
)
{
int
readlength
=
read
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
/* Connection was closed.
if
(
requestMessage
->
status
==
EOF
)
Remove socket from epoll instance
{
Close the socket and dont process more info from this socket
epoll_ctl
(
epollfd
,
EPOLL_CTL_DEL
,
events
[
i
].
data
.
fd
,
NULL
);
*/
close
(
events
[
i
].
data
.
fd
);
char
eof
;
read
(
events
[
i
].
data
.
fd
,
&
eof
,
sizeof
(
char
));
epoll_ctl
(
epollfd
,
EPOLL_CTL_DEL
,
events
[
i
].
data
.
fd
,
NULL
);
close
(
events
[
i
].
data
.
fd
);
continue
;
}
}
else
{
if
(
flag
&
EPOLLIN
)
{
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:%c][Key:%s][Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
printf
(
"
\n
[Message Received from client]
\n
[[Status:%c][Key:%s][Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
}
}
}
}
...
...
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