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
82957c3a
Commit
82957c3a
authored
Oct 26, 2020
by
Roshan Rabinarayan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added KVCLientLibrary.c
parent
b6242314
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
56 deletions
+53
-56
KVClient.c
KVClient.c
+4
-49
KVClientLibrary.c
KVClientLibrary.c
+46
-0
KVMessageFormat.h
KVMessageFormat.h
+0
-4
Makefile
Makefile
+3
-3
client
client
+0
-0
server
server
+0
-0
No files found.
KVClient.c
View file @
82957c3a
...
...
@@ -9,65 +9,24 @@ send GET , PUT , and DELETE requests to the server process. It will have a main
client library interfaces to do the actual operations.
*/
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "KVMessageFormat.h"
#include <arpa/inet.h>
#define MAX 80
#define PORT 8000
#define SA struct sockaddr
struct
message
*
request
(
char
status
,
char
*
key
,
char
*
value
)
{
if
(
!
status
||
(
key
==
NULL
&&
value
==
NULL
)
)
{
printf
(
"Invalid parameters in request()"
);
return
NULL
;
}
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
requestMessage
->
status
=
status
;
memcpy
(
requestMessage
->
key
,
key
,
256
);
//copied the complete key
if
(
strlen
(
requestMessage
->
key
)
<
256
)
{
requestMessage
->
key
[
strlen
(
requestMessage
->
key
)]
=
'\0'
;
}
if
(
value
!=
NULL
)
{
memcpy
(
requestMessage
->
value
,
value
,
256
);
//copied the complete value
}
if
(
strlen
(
requestMessage
->
value
)
<
256
)
//to pad with \0
{
requestMessage
->
value
[
strlen
(
requestMessage
->
value
)]
=
'\0'
;
}
printf
(
"
\n
[Message Generated at Client]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
return
requestMessage
;
}
struct
message
*
requestMessage
;
#include "KVClientLibrary.c"
struct
message
*
requestMessage
;
void
func
(
int
sockfd
,
struct
message
*
requestMessage
)
{
char
buff
[
MAX
];
int
n
=
0
;
for
(;;)
{
bzero
(
buff
,
sizeof
(
buff
));
if
(
1
)
{
n
++
;
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
));
sleep
(
2
);
}
//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
[])
...
...
@@ -101,11 +60,7 @@ int main(int argc, char const *argv[])
char
value
[
256
]
=
"cde"
;
struct
message
*
requestMessage
=
request
(
'g'
,
key
,
value
);
struct
message
*
replyMessage
=
malloc
(
sizeof
(
struct
message
));
///send(sock , requestMessage ,sizeof(struct message) , 0 );
///printf("Hello message sent\n");
func
(
sock
,
requestMessage
);
// 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);
return
0
;
}
\ No newline at end of file
KVClientLibrary.c
View file @
82957c3a
...
...
@@ -33,3 +33,49 @@ If the code is 200, then get will fill in the value with malloced memory.
Else, it will malloc some memory into the error pointer and return it. And so on....
*/
#include "KVMessageFormat.h"
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
struct
message
*
request
(
char
status
,
char
*
key
,
char
*
value
)
{
if
(
!
status
||
(
key
==
NULL
&&
value
==
NULL
)
)
{
printf
(
"Invalid parameters in request()"
);
return
NULL
;
}
struct
message
*
requestMessage
=
malloc
(
sizeof
(
struct
message
));
requestMessage
->
status
=
status
;
memcpy
(
requestMessage
->
key
,
key
,
256
);
//copied the complete key
if
(
strlen
(
requestMessage
->
key
)
<
256
)
{
requestMessage
->
key
[
strlen
(
requestMessage
->
key
)]
=
'\0'
;
}
if
(
value
!=
NULL
)
{
memcpy
(
requestMessage
->
value
,
value
,
256
);
//copied the complete value
}
if
(
strlen
(
requestMessage
->
value
)
<
256
)
//to pad with \0
{
requestMessage
->
value
[
strlen
(
requestMessage
->
value
)]
=
'\0'
;
}
return
requestMessage
;
}
void
printMessage
(
struct
message
*
requestMessage
)
{
printf
(
"[Message Generated]
\n
[[Status:%c]
\n
[Key:%s]
\n
[Value:%s]]
\n
"
,
requestMessage
->
status
,
requestMessage
->
key
,
requestMessage
->
value
);
return
;
}
\ No newline at end of file
KVMessageFormat.h
View file @
82957c3a
...
...
@@ -7,10 +7,6 @@ status code, and this status code will uniquely identify different requests and
the message will be value, again you can use padding if value is not 256B. In case of GET and
DEL requests where no value is required you can only consider the first 257B of the request
message.
Status Codes for request message
GET: 1
PUT: 2
DEL: 3
Status Codes for response message
Success: 200
...
...
Makefile
View file @
82957c3a
all
:
KVClient.c KVServer.c KVMessageFormat.h
gcc KVServer.c
-o
server
gcc KVClient.c
-o
client
\ No newline at end of file
all
:
KVClient.c KVServer.c KVMessageFormat.h KVClientLibrary.c
gcc
-pthread
KVServer.c
-o
server
gcc KVClient.c
-o
client
\ No newline at end of file
client
View file @
82957c3a
No preview for this file type
server
View file @
82957c3a
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