本文整理匯總了Golang中github.com/lionkov/ninep/srv.Req.Respond方法的典型用法代碼示例。如果您正苦於以下問題:Golang Req.Respond方法的具體用法?Golang Req.Respond怎麽用?Golang Req.Respond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lionkov/ninep/srv.Req
的用法示例。
在下文中一共展示了Req.Respond方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Read
func (f *NullFS) Read(r *srv.Req) {
var count int
ninep.InitRread(r.Rc, r.Tc.Count)
fid := r.Fid.Aux.(*Fid)
if fid.Qid.Path == Qroot {
var dirents []byte
for path, v := range dirQids {
d := &ninep.Dir{
Qid: *v,
Type: uint16(v.Type),
Mode: uint32(v.Type) | v.Version,
Name: path,
Uid: "root",
Gid: "root",
}
b := ninep.PackDir(d, true)
dirents = append(dirents, b...)
count += len(b)
}
// TODO: put this boilerplate into a helper function.
switch {
case r.Tc.Offset > uint64(len(dirents)):
count = 0
case len(dirents[r.Tc.Offset:]) > int(r.Tc.Count):
count = int(r.Tc.Count)
default:
count = len(dirents[r.Tc.Offset:])
}
if count == 0 && int(r.Tc.Offset) < len(dirents) && len(dirents) > 0 {
r.RespondError(&ninep.Error{Err: "too small read size for dir entry", Errornum: ninep.EINVAL})
return
}
copy(r.Rc.Data, dirents[r.Tc.Offset:int(r.Tc.Offset)+count])
} else {
if fid.Qid.Path == Qzero {
count = int(r.Tc.Count)
}
}
ninep.SetRreadCount(r.Rc, uint32(count))
r.Respond()
}
示例2: Write
// Write handles writes for writeable files and always succeeds.
// Only the null files has w so we don't bother checking Path.
func (f *NullFS) Write(r *srv.Req) {
var count uint32
ninep.SetRreadCount(r.Rc, uint32(count))
r.Respond()
}
示例3: Read
func (u *Ufs) Read(req *srv.Req) {
dbg := u.Debuglevel&srv.DbgLogFcalls != 0
fid := req.Fid.Aux.(*Fid)
tc := req.Tc
rc := req.Rc
err := fid.stat()
if err != nil {
req.RespondError(err)
return
}
ninep.InitRread(rc, tc.Count)
var count int
var e error
if fid.st.IsDir() {
if tc.Offset == 0 {
var e error
// If we got here, it was open. Can't really seek
// in most cases, just close and reopen it.
fid.file.Close()
if fid.file, e = os.OpenFile(fid.path, omode2uflags(req.Fid.Omode), 0); e != nil {
req.RespondError(toError(e))
return
}
if fid.dirs, e = fid.file.Readdir(-1); e != nil {
req.RespondError(toError(e))
return
}
if dbg {
log.Printf("Read: read %d entries", len(fid.dirs))
}
fid.dirents = nil
fid.direntends = nil
for i := 0; i < len(fid.dirs); i++ {
path := fid.path + "/" + fid.dirs[i].Name()
st, err := dir2Dir(path, fid.dirs[i], req.Conn.Dotu, req.Conn.Srv.Upool)
if err != nil {
if dbg {
log.Printf("dbg: stat of %v: %v", path, err)
}
continue
}
if dbg {
log.Printf("Stat: %v is %v", path, st)
}
b := ninep.PackDir(st, req.Conn.Dotu)
fid.dirents = append(fid.dirents, b...)
count += len(b)
fid.direntends = append(fid.direntends, count)
if dbg {
log.Printf("fid.direntends is %v\n", fid.direntends)
}
}
}
switch {
case tc.Offset > uint64(len(fid.dirents)):
count = 0
case len(fid.dirents[tc.Offset:]) > int(tc.Count):
count = int(tc.Count)
default:
count = len(fid.dirents[tc.Offset:])
}
if dbg {
log.Printf("readdir: count %v @ offset %v", count, tc.Offset)
}
nextend := sort.SearchInts(fid.direntends, int(tc.Offset)+count)
if nextend < len(fid.direntends) {
if fid.direntends[nextend] > int(tc.Offset)+count {
if nextend > 0 {
count = fid.direntends[nextend-1] - int(tc.Offset)
} else {
count = 0
}
}
}
if dbg {
log.Printf("readdir: count adjusted %v @ offset %v", count, tc.Offset)
}
if count == 0 && int(tc.Offset) < len(fid.dirents) && len(fid.dirents) > 0 {
req.RespondError(&ninep.Error{"too small read size for dir entry", ninep.EINVAL})
return
}
copy(rc.Data, fid.dirents[tc.Offset:int(tc.Offset)+count])
} else {
count, e = fid.file.ReadAt(rc.Data, int64(tc.Offset))
if e != nil && e != io.EOF {
req.RespondError(toError(e))
return
}
}
ninep.SetRreadCount(rc, uint32(count))
req.Respond()
}