Commit 490d393c authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Uniformize request receiver names to me.

parent aa771945
...@@ -73,69 +73,69 @@ func (me *request) OutputDebug() string { ...@@ -73,69 +73,69 @@ func (me *request) OutputDebug() string {
me.inHeader.opcode, me.status, dataStr, flatStr) me.inHeader.opcode, me.status, dataStr, flatStr)
} }
func (req *request) parse() { func (me *request) parse() {
inHSize := unsafe.Sizeof(InHeader{}) inHSize := unsafe.Sizeof(InHeader{})
if len(req.inputBuf) < inHSize { if len(me.inputBuf) < inHSize {
log.Printf("Short read for input header: %v", req.inputBuf) log.Printf("Short read for input header: %v", me.inputBuf)
return return
} }
req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0])) me.inHeader = (*InHeader)(unsafe.Pointer(&me.inputBuf[0]))
req.arg = req.inputBuf[inHSize:] me.arg = me.inputBuf[inHSize:]
req.handler = getHandler(req.inHeader.opcode) me.handler = getHandler(me.inHeader.opcode)
if req.handler == nil || req.handler.Func == nil { if me.handler == nil || me.handler.Func == nil {
msg := "Unimplemented" msg := "Unimplemented"
if req.handler == nil { if me.handler == nil {
msg = "Unknown" msg = "Unknown"
} }
log.Printf("%s opcode %v", msg, req.inHeader.opcode) log.Printf("%s opcode %v", msg, me.inHeader.opcode)
req.status = ENOSYS me.status = ENOSYS
return return
} }
if len(req.arg) < req.handler.InputSize { if len(me.arg) < me.handler.InputSize {
log.Printf("Short read for %v: %v", req.inHeader.opcode, req.arg) log.Printf("Short read for %v: %v", me.inHeader.opcode, me.arg)
req.status = EIO me.status = EIO
return return
} }
if req.handler.InputSize > 0 { if me.handler.InputSize > 0 {
req.inData = unsafe.Pointer(&req.arg[0]) me.inData = unsafe.Pointer(&me.arg[0])
req.arg = req.arg[req.handler.InputSize:] me.arg = me.arg[me.handler.InputSize:]
} }
count := req.handler.FileNames count := me.handler.FileNames
if count > 0 { if count > 0 {
if count == 1 { if count == 1 {
req.filenames = []string{string(req.arg[:len(req.arg)-1])} me.filenames = []string{string(me.arg[:len(me.arg)-1])}
} else { } else {
names := bytes.Split(req.arg[:len(req.arg)-1], []byte{0}, count) names := bytes.Split(me.arg[:len(me.arg)-1], []byte{0}, count)
req.filenames = make([]string, len(names)) me.filenames = make([]string, len(names))
for i, n := range names { for i, n := range names {
req.filenames[i] = string(n) me.filenames[i] = string(n)
} }
if len(names) != count { if len(names) != count {
log.Println("filename argument mismatch", names, count) log.Println("filename argument mismatch", names, count)
req.status = EIO me.status = EIO
} }
} }
} }
} }
func (req *request) serialize() { func (me *request) serialize() {
dataLength := req.handler.OutputSize dataLength := me.handler.OutputSize
if req.outData == nil || req.status != OK { if me.outData == nil || me.status != OK {
dataLength = 0 dataLength = 0
} }
sizeOfOutHeader := unsafe.Sizeof(OutHeader{}) sizeOfOutHeader := unsafe.Sizeof(OutHeader{})
req.outHeaderBytes = make([]byte, sizeOfOutHeader+dataLength) me.outHeaderBytes = make([]byte, sizeOfOutHeader+dataLength)
outHeader := (*OutHeader)(unsafe.Pointer(&req.outHeaderBytes[0])) outHeader := (*OutHeader)(unsafe.Pointer(&me.outHeaderBytes[0]))
outHeader.Unique = req.inHeader.Unique outHeader.Unique = me.inHeader.Unique
outHeader.Status = -req.status outHeader.Status = -me.status
outHeader.Length = uint32(sizeOfOutHeader + dataLength + len(req.flatData)) outHeader.Length = uint32(sizeOfOutHeader + dataLength + len(me.flatData))
copy(req.outHeaderBytes[sizeOfOutHeader:], asSlice(req.outData, dataLength)) copy(me.outHeaderBytes[sizeOfOutHeader:], asSlice(me.outData, dataLength))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment