diff -r 26a682609ac2 vt/pack.go
--- a/vt/pack.go Tue Apr 24 12:03:56 2012 -0600
+++ b/vt/pack.go Wed Jun 19 21:24:46 2013 +0300
@@ -6,8 +6,10 @@
//import "log"
+const VtCorruptType = 0xFF
+
const (
- Overrtype = 0
+ Overrtype = iota
Ovroottype
Ovdirtype
Ovptype0
@@ -44,8 +46,8 @@
Ovroottype,
}
-var fromdisk = [...]int{
- -1,
+var fromdisk = [...]uint8{
+ VtCorruptType,
RBlock,
DirBlock,
DirBlock + 1,
@@ -55,33 +57,33 @@
DirBlock + 5,
DirBlock + 6,
DirBlock + 7,
- -1,
- -1,
- -1,
+ VtCorruptType,
+ VtCorruptType,
+ VtCorruptType,
DataBlock,
}
var Epacket *Error = &Error{"invalid packet"}
var Eblktype *Error = &Error{"invalid block type"}
-func fromDiskType(val uint8) int {
+func fromDiskType(val uint8) uint8 {
if int(val) > len(fromdisk) {
- return -1
+ return VtCorruptType
}
return fromdisk[val]
}
-func toDiskType(val uint8) int {
+func toDiskType(val uint8) uint8 {
if int(val) > len(todisk) {
- return -1
+ return VtCorruptType
}
- return int(todisk[val])
+ return todisk[val]
}
func PackCall(buf []byte, id uint8, tag uint8, size int) (int, []byte) {
- size += 2 + 1 + 1 // size[2] id[1] tag[1]
+ size += 2 + 1 + 1 // size[2] id[1] tag[1]
if len(buf) < size {
return -1, nil
}
@@ -108,7 +110,7 @@
func PackThello(buf []byte, tag uint8, version, uid string, strength
uint8, crypto, codec []byte) int {
sz, buf := PackCall(buf, Thello, tag,
- 7+len(version)+len(uid)+len(crypto)+len(codec)) //
vesion[s] uid[s] strength[1] crypto[n] codec[n]
+ 7+len(version)+len(uid)+len(crypto)+len(codec)) // vesion[s]
uid[s] strength[1] crypto[n] codec[n]
if buf == nil {
return -1
}
@@ -127,13 +129,13 @@
}
func PackTread(buf []byte, tag uint8, score Score, btype uint8, count
uint16) int {
- sz, buf := PackCall(buf, Tread, tag, Scoresize+1+1+2) //
score[20] type[1] pad[1] count[2]
+ sz, buf := PackCall(buf, Tread, tag, Scoresize+1+1+2) //
score[20] type[1] pad[1] count[2]
if buf == nil {
return -1
}
buf = Pscore(score, buf)
- buf = Pint8(uint8(toDiskType(btype)), buf)
+ buf = Pint8(toDiskType(btype), buf)
buf = Pint8(0, buf)
Pint16(count, buf)
@@ -141,12 +143,12 @@
}
func PackTwrite(buf []byte, tag uint8, btype uint8, data []byte) int {
- sz, buf := PackCall(buf, Twrite, tag, 1+3+len(data)) //
type[1] pad[3] data
+ sz, buf := PackCall(buf, Twrite, tag, 1+3+len(data)) // type[1] pad[3] data
if buf == nil {
return -1
}
- buf = Pint8(uint8(toDiskType(btype)), buf)
+ buf = Pint8(toDiskType(btype), buf)
buf = Pint8(0, buf)
buf = Pint16(0, buf)
copy(buf, data)
diff -r 26a682609ac2 vt/vtclnt/clnt.go
--- a/vt/vtclnt/clnt.go Tue Apr 24 12:03:56 2012 -0600
+++ b/vt/vtclnt/clnt.go Wed Jun 19 21:24:46 2013 +0300
@@ -279,7 +279,8 @@
pos += n
nreqs++
- clnt.ReqFree(req)
+ // req is freed in recv() if no Done channel was
registered, or by the code calling <-Done.
+ //clnt.ReqFree(req)
select {
default:
req = nil
@@ -355,7 +356,7 @@
clnt = NewClnt(c)
req := clnt.ReqAlloc()
req.Done = make(chan *Req)
- tc := req.Tc
+ tc := &req.Tc
tc.Id = vt.Thello
tc.Version = "02"
tc.Uid = "anonymous"
@@ -411,7 +412,7 @@
func (clnt *Clnt) Getnb(score vt.Score, btype uint8, count uint16,
done chan *Req) (err *vt.Error) {
req := clnt.ReqAlloc()
req.Done = done
- tc := req.Tc
+ tc := &req.Tc
tc.Id = vt.Tread
tc.Score = score
tc.Btype = btype
@@ -447,7 +448,7 @@
// Put is always async, Sync will make sure all Puts finished before returning
func (clnt *Clnt) Put(btype uint8, data []byte) (score vt.Score, err
*vt.Error) {
req := clnt.ReqAlloc()
- tc := req.Tc
+ tc := &req.Tc
tc.Id = vt.Twrite
tc.Btype = btype
tc.Data = data
@@ -466,7 +467,7 @@
done := make(chan *Req)
req := clnt.ReqAlloc()
req.Done = done
- tc := req.Tc
+ tc := &req.Tc
tc.Id = vt.Tsync
err = clnt.Rpcnb(req)
if err != nil {
Post by Pavel ZholkoverHi all,
Does anyone use the http://http://code.google.com/p/govt package for
client side venti ?
I had to apply the attached patch to be able to read a vac score.
Thanks,
- Pavel