Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pa4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nilesh Jagdish
pa4
Commits
db68af3a
Commit
db68af3a
authored
Nov 06, 2020
by
Saikumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified respondToClient function
parent
a9e2787b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
13 deletions
+31
-13
server.c
server.c
+31
-13
No files found.
server.c
View file @
db68af3a
...
@@ -17,42 +17,60 @@ void *respondToClient(void *args) {
...
@@ -17,42 +17,60 @@ void *respondToClient(void *args) {
int
clientFd
=
*
((
int
*
)
args
);
int
clientFd
=
*
((
int
*
)
args
);
while
(
1
)
{
while
(
1
)
{
// printf("reading for client %d\n", clientFd);
// printf("reading for client %d\n", clientFd);
char
buffer
[
513
];
// char buffer[513];
char
*
buffer
=
(
char
*
)
malloc
(
513
*
sizeof
(
char
));
int
len
=
read
(
clientFd
,
buffer
,
513
);
int
len
=
read
(
clientFd
,
buffer
,
513
);
// buffer[len] = '\0';
buffer
[
len
]
=
'\0'
;
char
key
[
100
],
value
[
100
];
char
key
[
100
],
value
[
100
];
memset
(
key
,
'\0'
,
100
);
memset
(
value
,
'\0'
,
100
);
char
todo
=
buffer
[
0
];
char
todo
=
buffer
[
0
];
// key: first non-zero till byte 257
// key: first non-zero till byte 257
int
i
;
int
i
;
for
(
i
=
1
;
buffer
[
i
]
==
'0'
;
i
++
);
if
(
todo
!=
'4'
){
// printf("I: %d %c\n", i, buffer[i]);
for
(
i
=
1
;
buffer
[
i
]
==
'0'
;
i
++
);
// printf("I: %d %c\n", i, buffer[i]);
printf
(
"key length: %d
\n
"
,
257
-
i
);
printf
(
"key length: %d
\n
"
,
257
-
i
);
memcpy
(
key
,
buffer
+
i
,
257
-
i
);
memcpy
(
key
,
buffer
+
i
,
257
-
i
);
// value: first non-zero till byte 513
// value: first non-zero till byte 513
for
(
i
=
257
;
buffer
[
i
]
==
'0'
;
i
++
);
for
(
i
=
257
;
buffer
[
i
]
==
'0'
;
i
++
);
printf
(
"value length: %d
\n
"
,
513
-
i
);
printf
(
"value length: %d
\n
"
,
513
-
i
);
memcpy
(
value
,
buffer
+
i
,
513
-
i
);
memcpy
(
value
,
buffer
+
i
,
513
-
i
);
}
switch
(
todo
)
{
switch
(
todo
)
{
case
'1'
:
case
'1'
:
printf
(
"GET recvd
\n
"
);
printf
(
"GET recvd
\n
"
);
printf
(
"Key: %s
\n
"
,
key
);
printf
(
"Key: %s
\n
"
,
key
);
write
(
clientFd
,
"Get returns
\0
"
,
12
);
break
;
break
;
case
'2'
:
case
'2'
:
printf
(
"PUT recvd
\n
"
);
printf
(
"PUT recvd
\n
"
);
printf
(
"Key: %s
\n
"
,
key
);
printf
(
"Key: %s
\n
"
,
key
);
printf
(
"Value: %s
\n
"
,
value
);
printf
(
"Value: %s
\n
"
,
value
);
write
(
clientFd
,
"Put returns
\0
"
,
12
);
break
;
break
;
case
'3'
:
case
'3'
:
printf
(
"DELETE recvd
\n
"
);
printf
(
"DELETE recvd
\n
"
);
printf
(
"Key: %s
\n
"
,
key
);
printf
(
"Key: %s
\n
"
,
key
);
write
(
clientFd
,
"Delete returns
\0
"
,
15
);
break
;
break
;
case
'4'
:
printf
(
"Connection terminated
\n
"
);
write
(
clientFd
,
"Connection terminated
\0
"
,
22
);
return
NULL
;
// break;
}
}
// printf("%s\n", buffer);
// printf("%s\n", buffer);
write
(
clientFd
,
"Client response
\0
"
,
16
);
// write(clientFd, "Client response\0", 16);
// if (todo=='4')
// {
// return NULL;
// }
}
}
}
}
...
...
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