本文整理汇总了Golang中github.com/rminnich/go9p.SrvReq.RespondError方法的典型用法代码示例。如果您正苦于以下问题:Golang SrvReq.RespondError方法的具体用法?Golang SrvReq.RespondError怎么用?Golang SrvReq.RespondError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rminnich/go9p.SrvReq
的用法示例。
在下文中一共展示了SrvReq.RespondError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Walk
func (sfs *NopSrv) Walk(req *go9p.SrvReq) {
fid := req.Fid.Aux.(Dispatcher)
tc := req.Tc
if sfs.Debuglevel > 0 {
log.Printf("walk %s %s", fid, tc.Wname)
}
if req.Newfid.Aux == nil {
req.Newfid.Aux = fid.Clone()
}
if len(tc.Wname) == 0 {
w := make([]go9p.Qid, 0)
req.RespondRwalk(w)
} else {
nfid, err := fid.Walk(req, tc.Wname[0])
if err != nil {
req.RespondError(toError(err))
return
}
req.Newfid.Aux = nfid
w := []go9p.Qid{*Qid(nfid)}
req.RespondRwalk(w)
}
}
示例2: Open
// Open opens a local file.
func (fs *fileSystem) Open(req *go9p.SrvReq) {
// Stat file handle.
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
// Open local file handle.
file, err := os.OpenFile(aux.path, omode2uflags(req.Tc.Mode), 0)
if err != nil {
req.RespondError(toError(err))
return
}
aux.file = file
// Add to appropriate set.
if req.Tc.Mode&go9p.OREAD != 0 {
fs.addToReadset(aux.rootID, aux.path)
} else if req.Tc.Mode&go9p.OWRITE != 0 {
fs.addToWriteset(aux.rootID, aux.path)
} else if req.Tc.Mode&go9p.ORDWR != 0 {
fs.addToReadset(aux.rootID, aux.path)
fs.addToWriteset(aux.rootID, aux.path)
}
req.RespondRopen(aux.qid(), 0)
}
示例3: 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()
}
示例4: 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()
}
示例5: 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()
}
示例6: Attach
func (sfs *NopSrv) Attach(req *go9p.SrvReq) {
if req.Afid != nil {
req.RespondError(go9p.Enoauth)
return
}
req.Fid.Aux = sfs.Root
if sfs.Debuglevel > 0 {
log.Printf("attach")
}
req.RespondRattach(Qid(sfs.Root))
}
示例7: Attach
// Attach creates a file handle on the file system.
func (fs *fileSystem) Attach(req *go9p.SrvReq) {
rootID, filename := split(req.Tc.Aname)
aux := &Aux{
rootID: rootID,
path: path.Join(fs.path, filename),
}
req.Fid.Aux = aux
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
req.RespondRattach(aux.qid())
}
示例8: Stat
func (fs *fileSystem) Stat(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
st, err := new9pDir(aux.path, aux.st, req.Conn.Dotu, req.Conn.Srv.Upool)
if st == nil {
req.RespondError(err)
return
}
req.RespondRstat(st)
}
示例9: Write
func (sfs *NopSrv) Write(req *go9p.SrvReq) {
fid := req.Fid.Aux.(Dispatcher)
tc := req.Tc
if sfs.Debuglevel > 0 {
log.Printf("write: %f", fid)
}
e := fid.Write(req, tc.Data)
if e != nil {
req.RespondError(toError(e))
return
}
req.RespondRwrite(uint32(len(tc.Data)))
}
示例10: Remove
func (fs *fileSystem) Remove(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
// Add to writeset.
fs.addToWriteset(aux.rootID, aux.path)
if err := os.Remove(aux.path); err != nil {
req.RespondError(toError(err))
return
}
req.RespondRremove()
}
示例11: Read
// Read reads data from a file handle.
func (fs *fileSystem) Read(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
// Add to readset.
fs.addToReadset(aux.rootID, aux.path)
go9p.InitRread(req.Rc, req.Tc.Count)
if aux.st.IsDir() {
fs.readDir(req)
return
}
fs.readFile(req)
}
示例12: Write
// Write writes data to a file.
func (fs *fileSystem) Write(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
// Add to writeset.
fs.addToWriteset(aux.rootID, aux.path)
n, err := aux.file.WriteAt(req.Tc.Data, int64(req.Tc.Offset))
if err != nil {
req.RespondError(toError(err))
return
}
req.RespondRwrite(uint32(n))
}
示例13: Walk
func (fs *fileSystem) Walk(req *go9p.SrvReq) {
// Stat the file.
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
// Create a new file handle, if necessary.
if req.Newfid.Aux == nil {
req.Newfid.Aux = &Aux{rootID: aux.rootID}
}
nfid := req.Newfid.Aux.(*Aux)
wqids := make([]go9p.Qid, 0, len(req.Tc.Wname))
newPath := aux.path
// Append actual files after the root.
for i, name := range req.Tc.Wname {
// If we have no root then the first segment is the root ID.
if nfid.rootID == "" {
nfid.rootID = name
if root := (*FileSystem)(fs).Root(nfid.rootID); root == nil {
req.RespondError(go9p.Enoent)
return
}
wqids = append(wqids, *newRootQid(nfid.rootID))
continue
}
// Otherwise we're already walking a root so continue to traverse the files.
p := newPath + "/" + name
st, err := os.Lstat(p)
if err != nil {
if i == 0 {
req.RespondError(go9p.Enoent)
return
}
break
}
wqids = append(wqids, *newQid(st))
newPath = p
}
nfid.path = newPath
req.RespondRwalk(wqids)
}
示例14: Create
// Create creates a new file.
func (fs *fileSystem) Create(req *go9p.SrvReq) {
aux := req.Fid.Aux.(*Aux)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
path := aux.path + "/" + req.Tc.Name
var file *os.File
var err error
switch {
case req.Tc.Perm&go9p.DMDIR != 0:
err = os.Mkdir(path, os.FileMode(req.Tc.Perm&0777))
case req.Tc.Perm&go9p.DMSYMLINK != 0:
err = os.Symlink(req.Tc.Ext, path)
case req.Tc.Perm&go9p.DMLINK != 0:
n, err := strconv.ParseUint(req.Tc.Ext, 10, 0)
if err != nil {
break
}
ofid := req.Conn.FidGet(uint32(n))
if ofid == nil {
req.RespondError(go9p.Eunknownfid)
return
}
err = os.Link(ofid.Aux.(*Aux).path, path)
ofid.DecRef()
case req.Tc.Perm&go9p.DMNAMEDPIPE != 0:
case req.Tc.Perm&go9p.DMDEVICE != 0:
req.RespondError(&go9p.Error{"not implemented", go9p.EIO})
return
default:
var mode uint32 = req.Tc.Perm & 0777
if req.Conn.Dotu {
if req.Tc.Perm&go9p.DMSETUID > 0 {
mode |= syscall.S_ISUID
}
if req.Tc.Perm&go9p.DMSETGID > 0 {
mode |= syscall.S_ISGID
}
}
file, err = os.OpenFile(path, omode2uflags(req.Tc.Mode)|os.O_CREATE, os.FileMode(mode))
}
if file == nil && err == nil {
file, err = os.OpenFile(path, omode2uflags(req.Tc.Mode), 0)
}
if err != nil {
req.RespondError(toError(err))
return
}
aux.path = path
aux.file = file
// Save file to writeset.
fs.addToWriteset(aux.rootID, path)
if err := aux.stat(); err != nil {
req.RespondError(err)
return
}
req.RespondRcreate(aux.qid(), 0)
}
示例15: Remove
func (*NopSrv) Remove(req *go9p.SrvReq) {
log.Printf("remove: %p", req)
req.RespondError(errors.New("remove: ..."))
}