本文整理汇总了Golang中github.com/rminnich/go9p.SrvReq.Respond方法的典型用法代码示例。如果您正苦于以下问题:Golang SrvReq.Respond方法的具体用法?Golang SrvReq.Respond怎么用?Golang SrvReq.Respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rminnich/go9p.SrvReq
的用法示例。
在下文中一共展示了SrvReq.Respond方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
func (sfs *NopSrv) Read(req *go9p.SrvReq) {
fid := req.Fid.Aux.(Dispatcher)
tc := req.Tc
rc := req.Rc
if sfs.Debuglevel > 0 {
log.Printf("read %T %s %d:%d", fid, fid, tc.Offset, tc.Count)
}
buf, err := fid.Read(req)
if err != nil {
req.RespondError(toError(err))
return
}
go9p.InitRread(rc, tc.Count)
count := 0
switch {
case tc.Offset > uint64(len(buf)):
count = 0
case len(buf[tc.Offset:]) > int(tc.Count):
count = int(tc.Count)
default:
count = len(buf[tc.Offset:])
}
copy(rc.Data, buf[tc.Offset:int(tc.Offset)+count])
go9p.SetRreadCount(rc, uint32(count))
req.Respond()
}
示例2: readFile
func (fs *fileSystem) readFile(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
n, err := aux.file.ReadAt(req.Rc.Data, int64(req.Tc.Offset))
if err != nil && err != io.EOF {
req.RespondError(toError(err))
return
}
go9p.SetRreadCount(req.Rc, uint32(n))
req.Respond()
}
示例3: readDir
func (fs *fileSystem) readDir(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
var n int
if req.Tc.Offset == 0 {
// If we got here, it was open. Can't really seek
// in most cases, just close and reopen it.
aux.file.Close()
file, err := os.OpenFile(aux.path, omode2uflags(req.Fid.Omode), 0)
if err != nil {
req.RespondError(toError(err))
return
}
aux.file = file
dirs, e := aux.file.Readdir(-1)
if e != nil {
req.RespondError(toError(e))
return
}
aux.dirs = dirs
aux.dirents = nil
aux.direntends = nil
for _, dir := range aux.dirs {
path := aux.path + "/" + dir.Name()
st, _ := new9pDir(path, dir, req.Conn.Dotu, req.Conn.Srv.Upool)
if st == nil {
continue
}
b := go9p.PackDir(st, req.Conn.Dotu)
aux.dirents = append(aux.dirents, b...)
n += len(b)
aux.direntends = append(aux.direntends, n)
}
}
switch {
case req.Tc.Offset > uint64(len(aux.dirents)):
n = 0
case len(aux.dirents[req.Tc.Offset:]) > int(req.Tc.Count):
n = int(req.Tc.Count)
default:
n = len(aux.dirents[req.Tc.Offset:])
}
copy(req.Rc.Data, aux.dirents[req.Tc.Offset:int(req.Tc.Offset)+n])
go9p.SetRreadCount(req.Rc, uint32(n))
req.Respond()
}