Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs733
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sushant Mahajan
cs733
Commits
2539813d
Commit
2539813d
authored
Jan 21, 2015
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
additional error handling for set command
parent
57bd661b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
6 deletions
+41
-6
assignment1/client.go
assignment1/client.go
+13
-1
assignment1/server.go
assignment1/server.go
+28
-5
No files found.
assignment1/client.go
View file @
2539813d
...
...
@@ -7,16 +7,25 @@ import (
"os"
)
var
die
bool
func
doRead
(
conn
net
.
Conn
)
{
for
{
buf
:=
make
([]
byte
,
1024
)
conn
.
Read
(
buf
)
_
,
err
:=
conn
.
Read
(
buf
)
if
err
!=
nil
{
fmt
.
Println
(
"Server closed connection"
)
die
=
true
break
}
fmt
.
Println
(
string
(
buf
))
}
}
func
main
()
{
conn
,
err
:=
net
.
Dial
(
"tcp"
,
"localhost:5000"
)
die
=
false
go
doRead
(
conn
)
if
err
!=
nil
{
...
...
@@ -25,6 +34,9 @@ func main() {
reader
:=
bufio
.
NewReader
(
os
.
Stdin
)
for
{
if
die
{
break
}
msg
,
err
:=
reader
.
ReadString
(
'\n'
)
if
err
!=
nil
{
fmt
.
Println
(
"Err: "
,
err
)
...
...
assignment1/server.go
View file @
2539813d
...
...
@@ -94,8 +94,9 @@ func read(conn net.Conn, toRead uint64) ([]byte, bool){
}
func
write
(
conn
net
.
Conn
,
msg
string
)
{
buf
:=
[]
byte
(
msg
)[
0
:
len
(
msg
)
-
1
]
buf
=
append
(
buf
,
[]
byte
(
CRLF
))
buf
:=
[]
byte
(
msg
)
buf
=
append
(
buf
,
[]
byte
(
CRLF
)
...
)
logger
.
Println
(
buf
,
len
(
buf
))
conn
.
Write
(
buf
)
}
...
...
@@ -116,6 +117,23 @@ func isValid(cmd string, tokens []string, conn net.Conn) int{
case
SET
:
if
len
(
tokens
)
>
5
||
len
(
tokens
)
<
4
{
flag
=
1
logger
.
Println
(
cmd
,
":Invalid no. of tokens"
)
}
if
len
([]
byte
(
tokens
[
1
]))
>
250
{
flag
=
1
logger
.
Println
(
cmd
,
":Invalid size of key"
)
}
if
len
(
tokens
)
==
5
&&
tokens
[
4
]
!=
NOREPLY
{
logger
.
Println
(
cmd
,
":optional arg incorrect"
)
flag
=
1
}
if
_
,
err
:=
strconv
.
ParseUint
(
tokens
[
2
],
10
,
64
);
err
!=
nil
{
logger
.
Println
(
cmd
,
":expiry time invalid"
)
flag
=
1
}
if
_
,
err
:=
strconv
.
ParseUint
(
tokens
[
3
],
10
,
64
);
err
!=
nil
{
logger
.
Println
(
cmd
,
":numBytes invalid"
)
flag
=
1
}
//other validations
case
GET
:
...
...
@@ -159,9 +177,14 @@ func parseInput(conn net.Conn, msg string, table *KeyValueStore) {
return
}
if
ver
,
ok
:=
performSet
(
conn
,
tokens
[
1
:
len
(
tokens
)],
table
);
ok
{
logger
.
Println
(
ver
)
buffer
.
WriteString
(
OK
)
buffer
.
WriteString
(
" "
)
buffer
.
WriteString
(
strconv
.
FormatUint
(
ver
,
10
))
logger
.
Println
(
buffer
.
String
())
write
(
conn
,
buffer
.
String
())
}
//
case GET: performGet(tokens[1:len(tokens)])
case
GET
:
performGet
(
tokens
[
1
:
len
(
tokens
)])
//case GETM: performGetm(tokens[1:len(tokens)])
//case CAS: performCas(tokens[1:len(tokens)])
//case DELETE: performDelete(tokens[1:len(tokens)])
...
...
@@ -185,7 +208,7 @@ func performSet(conn net.Conn, tokens []string, table *KeyValueStore) (uint64, b
v
,
ok
:=
read
(
conn
,
n
+
2
)
if
!
ok
{
//error here
return
return
0
,
false
}
table
.
Lock
()
...
...
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