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
3a2059c9
Commit
3a2059c9
authored
Oct 25, 2020
by
Roshan Rabinarayan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aaa
parent
2608a56a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
21 deletions
+21
-21
KVClient.c
KVClient.c
+1
-12
KVServer.c
KVServer.c
+20
-9
a.out
a.out
+0
-0
client
client
+0
-0
server
server
+0
-0
No files found.
KVClient.c
View file @
3a2059c9
...
@@ -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
8080
#define PORT
6969
#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,17 +51,6 @@ struct message *request(char status,char* key,char* value)
...
@@ -51,17 +51,6 @@ struct message *request(char status,char* key,char* value)
return
requestMessage
;
return
requestMessage
;
}
}
struct
message
*
requestMessage
;
struct
message
*
requestMessage
;
void
func
(
int
sockfd
)
{
char
buff
[
MAX
];
int
n
;
bzero
(
buff
,
sizeof
(
buff
));
n
=
0
;
char
message
[
256
]
=
"helloworld"
;
requestMessage
=
request
(
'g'
,
message
,
NULL
);
send
(
sockfd
,
requestMessage
,
sizeof
(
struct
message
),
0
);
}
int
main
(
int
argc
,
char
const
*
argv
[])
int
main
(
int
argc
,
char
const
*
argv
[])
{
{
...
...
KVServer.c
View file @
3a2059c9
...
@@ -59,7 +59,7 @@ error. (Assume each character to be 1 byte in size)
...
@@ -59,7 +59,7 @@ error. (Assume each character to be 1 byte in size)
*/
*/
/*
#include <stdio.h>
#include <stdio.h>
#include <pthread.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -69,6 +69,7 @@ error. (Assume each character to be 1 byte in size)
...
@@ -69,6 +69,7 @@ error. (Assume each character to be 1 byte in size)
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/epoll.h>
#include <string.h>
#include <string.h>
#include "KVMessageFormat.h"
#define MAX_EVENTS 10
#define MAX_EVENTS 10
void
*
worker
(
void
*
args
)
{
void
*
worker
(
void
*
args
)
{
...
@@ -76,7 +77,7 @@ void *worker(void *args) {
...
@@ -76,7 +77,7 @@ void *worker(void *args) {
struct
epoll_event
ev
,
events
[
MAX_EVENTS
];
struct
epoll_event
ev
,
events
[
MAX_EVENTS
];
int
read_pipe
,
conn_sock
,
nfds
,
i
;
int
read_pipe
,
conn_sock
,
nfds
,
i
;
int
epollfd
;
int
epollfd
;
int *newfd;
int
*
newfd
=
malloc
(
sizeof
(
int
))
;
read_pipe
=
((
int
*
)
args
)[
0
];
read_pipe
=
((
int
*
)
args
)[
0
];
...
@@ -102,14 +103,19 @@ void *worker(void *args) {
...
@@ -102,14 +103,19 @@ 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
)
{
printf("Hola1!");
fflush
(
stdout
);
fflush
(
stdout
);
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
read
(
read_pipe
,
newfd
,
sizeof
(
newfd
));
printf("read %d", *newfd);
printf
(
"
\n
read %d"
,
*
newfd
);
printf("Hola2!");
if
(
epoll_ctl
(
epollfd
,
EPOLL_CTL_ADD
,
newfd
,
)
==
-
1
)
{
perror
(
"epoll_ctl: read_pipe"
);
exit
(
EXIT_FAILURE
);
}
fflush
(
stdout
);
fflush
(
stdout
);
}
else
{
}
else
{
printf("im doing some work");
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
read
(
events
[
i
].
data
.
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
);
}
}
}
}
}
}
...
@@ -117,6 +123,7 @@ void *worker(void *args) {
...
@@ -117,6 +123,7 @@ void *worker(void *args) {
}
}
int
main
(
int
argc
,
int
argv
)
{
int
main
(
int
argc
,
int
argv
)
{
int
i
;
int
i
;
...
@@ -156,19 +163,22 @@ int main (int argc, int argv) {
...
@@ -156,19 +163,22 @@ int main (int argc, int argv) {
clilen
=
sizeof
(
cli_addr
);
clilen
=
sizeof
(
cli_addr
);
while
(
1
)
{
while
(
1
)
{
printf("Hola!");
fflush
(
stdout
);
fflush
(
stdout
);
newsockfd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
cli_addr
,
&
clilen
);
newsockfd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
cli_addr
,
&
clilen
);
if
(
newsockfd
<
0
)
if
(
newsockfd
<
0
)
perror
(
"ERROR on accept"
);
perror
(
"ERROR on accept"
);
write
(
pipes
[
next
][
1
],
&
newsockfd
,
sizeof
(
newsockfd
));
write
(
pipes
[
next
][
1
],
&
newsockfd
,
sizeof
(
newsockfd
));
printf
(
"main thread ka fd ka value: %d
\n
"
,
newsockfd
);
fflush
(
stdout
);
next
=
(
next
+
1
)
%
pool_thread_size
;
next
=
(
next
+
1
)
%
pool_thread_size
;
}
}
return
0
;
return
0
;
}*/
}
/*
#include <stdio.h>
#include <stdio.h>
#include <netdb.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/in.h>
...
@@ -179,7 +189,7 @@ int main (int argc, int argv) {
...
@@ -179,7 +189,7 @@ int main (int argc, int argv) {
#include <sys/types.h>
#include <sys/types.h>
#include "KVMessageFormat.h"
#include "KVMessageFormat.h"
#define MAX 80
#define MAX 80
#define PORT
8080
#define PORT
6969
#define SA struct sockaddr
#define SA struct sockaddr
// Function designed for chat between client and server.
// Function designed for chat between client and server.
...
@@ -256,3 +266,4 @@ int main(int argc, char const *argv[])
...
@@ -256,3 +266,4 @@ int main(int argc, char const *argv[])
return 0;
return 0;
}
}
*/
\ No newline at end of file
a.out
View file @
3a2059c9
No preview for this file type
client
View file @
3a2059c9
No preview for this file type
server
View file @
3a2059c9
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