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
fd69388c
Commit
fd69388c
authored
Oct 25, 2020
by
Roshan Rabinarayan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
infinite looping problem!
parent
aed86122
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
19 deletions
+33
-19
KVClient.c
KVClient.c
+19
-7
KVServer.c
KVServer.c
+14
-12
abc.txt
abc.txt
+0
-0
client
client
+0
-0
server
server
+0
-0
No files found.
KVClient.c
View file @
fd69388c
...
@@ -20,7 +20,7 @@ client library interfaces to do the actual operations.
...
@@ -20,7 +20,7 @@ client library interfaces to do the actual operations.
#include "KVMessageFormat.h"
#include "KVMessageFormat.h"
#include <arpa/inet.h>
#include <arpa/inet.h>
#define MAX 80
#define MAX 80
#define PORT
6969
#define PORT
8000
#define SA struct sockaddr
#define SA struct sockaddr
struct
message
*
request
(
char
status
,
char
*
key
,
char
*
value
)
struct
message
*
request
(
char
status
,
char
*
key
,
char
*
value
)
{
{
...
@@ -51,7 +51,19 @@ struct message *request(char status,char* key,char* value)
...
@@ -51,7 +51,19 @@ struct message *request(char status,char* key,char* value)
return
requestMessage
;
return
requestMessage
;
}
}
struct
message
*
requestMessage
;
struct
message
*
requestMessage
;
void
func
(
int
sockfd
,
struct
message
*
requestMessage
)
{
char
buff
[
MAX
];
int
n
;
for
(;;)
{
bzero
(
buff
,
sizeof
(
buff
));
n
=
0
;
if
((
n
++
)
==
0
)
write
(
sockfd
,
requestMessage
,
sizeof
(
struct
message
));
//printf("[Message sent to server]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",requestMessage->status,requestMessage->key,requestMessage->value);
}
}
int
main
(
int
argc
,
char
const
*
argv
[])
int
main
(
int
argc
,
char
const
*
argv
[])
{
{
int
sock
=
0
,
valread
;
int
sock
=
0
,
valread
;
...
@@ -83,11 +95,11 @@ int main(int argc, char const *argv[])
...
@@ -83,11 +95,11 @@ int main(int argc, char const *argv[])
char
value
[
256
]
=
"cde"
;
char
value
[
256
]
=
"cde"
;
struct
message
*
requestMessage
=
request
(
'g'
,
key
,
value
);
struct
message
*
requestMessage
=
request
(
'g'
,
key
,
value
);
struct
message
*
replyMessage
=
malloc
(
sizeof
(
struct
message
));
struct
message
*
replyMessage
=
malloc
(
sizeof
(
struct
message
));
send
(
sock
,
requestMessage
,
sizeof
(
struct
message
)
,
0
);
///
send(sock , requestMessage ,sizeof(struct message) , 0 );
printf
(
"Hello message sent
\n
"
);
///
printf("Hello message sent\n");
func
(
sock
,
requestMessage
);
valread
=
read
(
sock
,
replyMessage
,
sizeof
(
struct
message
));
//
valread = read( sock , replyMessage, sizeof(struct message));
printf
(
"[Message Received from client]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]"
,
replyMessage
->
status
,
replyMessage
->
key
,
replyMessage
->
value
);
//
printf("[Message Received from client]\n[[Status:%c]\n[Key:%s]\n[Value:%s]]",replyMessage->status,replyMessage->key,replyMessage->value);
return
0
;
return
0
;
}
}
\ No newline at end of file
KVServer.c
View file @
fd69388c
...
@@ -74,14 +74,15 @@ error. (Assume each character to be 1 byte in size)
...
@@ -74,14 +74,15 @@ error. (Assume each character to be 1 byte in size)
void
*
worker
(
void
*
args
)
{
void
*
worker
(
void
*
args
)
{
struct
epoll_event
ev
,
events
[
MAX_EVENTS
];
struct
epoll_event
ev
,
events
[
MAX_EVENTS
];
struct
epoll_event
socketEvent
;
socketEvent
.
events
=
EPOLLIN
;
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
=
malloc
(
sizeof
(
int
));
read_pipe
=
((
int
*
)
args
)[
0
];
read_pipe
=
((
int
*
)
args
)[
0
];
//assigned the read end of the pipe
epollfd
=
epoll_create1
(
0
);
epollfd
=
epoll_create1
(
0
);
if
(
epollfd
==
-
1
)
{
if
(
epollfd
==
-
1
)
{
perror
(
"epoll_create1"
);
perror
(
"epoll_create1"
);
...
@@ -105,18 +106,19 @@ void *worker(void *args) {
...
@@ -105,18 +106,19 @@ void *worker(void *args) {
if
(
events
[
i
].
data
.
fd
==
read_pipe
)
{
if
(
events
[
i
].
data
.
fd
==
read_pipe
)
{
fflush
(
stdout
);
fflush
(
stdout
);
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
printf
(
"
\n
read %d"
,
*
newfd
);
printf
(
"
\n
read %d
\n
"
,
*
newfd
);
ev
.
events
=
EPOLLIN
;
socketEvent
.
data
.
fd
=*
newfd
;
ev
.
data
.
fd
=
*
newfd
;
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
*
newfd
,
&
socketEvent
)
==
-
1
)
{
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
*
newfd
,
&
ev
)
==
-
1
)
{
perror
(
"epoll_ctl: read_pipe"
);
perror
(
"epoll_ctl: read_pipe"
);
printf
(
"haga
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
fflush
(
stdout
);
fflush
(
stdout
);
}
}
else
{
else
if
(
events
[
i
].
data
.
fd
==
*
newfd
)
{
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
read
(
events
[
i
].
data
.
fd
,
requestMessage
,
sizeof
(
struct
message
));
read
(
*
new
fd
,
requestMessage
,
sizeof
(
struct
message
));
printf
(
"[Message Received from client]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
printf
(
"[Message Received from client]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
}
}
...
@@ -132,7 +134,7 @@ int main (int argc, int argv) {
...
@@ -132,7 +134,7 @@ int main (int argc, int argv) {
int
i
;
int
i
;
int
next
=
0
;
// to decide which worker thread to assign client in round robin fashion
int
next
=
0
;
// to decide which worker thread to assign client in round robin fashion
pthread_t
*
threads
;
// set of all worker threads
pthread_t
*
threads
;
// set of all worker threads
int
pool_thread_size
=
5
;
// TODO: get pool thread size from config file
int
pool_thread_size
=
1
;
// TODO: get pool thread size from config file
int
sockfd
,
newsockfd
,
portno
,
clilen
,
n
;
int
sockfd
,
newsockfd
,
portno
,
clilen
,
n
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
...
@@ -153,7 +155,7 @@ int main (int argc, int argv) {
...
@@ -153,7 +155,7 @@ int main (int argc, int argv) {
exit
(
1
);
exit
(
1
);
}
}
memset
(
&
serv_addr
,
0
,
sizeof
(
serv_addr
));
memset
(
&
serv_addr
,
0
,
sizeof
(
serv_addr
));
portno
=
6969
;
portno
=
8000
;
serv_addr
.
sin_family
=
AF_INET
;
serv_addr
.
sin_family
=
AF_INET
;
serv_addr
.
sin_port
=
htons
(
portno
);
serv_addr
.
sin_port
=
htons
(
portno
);
serv_addr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
serv_addr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
...
...
abc.txt
0 → 100644
View file @
fd69388c
client
View file @
fd69388c
No preview for this file type
server
View file @
fd69388c
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