本文整理匯總了Golang中code/google/com/p/goplan9/plan9.Fcall.Data方法的典型用法代碼示例。如果您正苦於以下問題:Golang Fcall.Data方法的具體用法?Golang Fcall.Data怎麽用?Golang Fcall.Data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/goplan9/plan9.Fcall
的用法示例。
在下文中一共展示了Fcall.Data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readfile
func (c *ClientConn) readfile(fc *plan9.Fcall, ref *fileRef) *plan9.Fcall {
size, err := c.explorer.Sizeof(ref.Path)
if err != nil {
return c.unexpectedErr(fc, err)
}
if size > 0 && fc.Offset >= size {
// trying to reading past the end of file.
// return count == 0 to signal EOF to client
fc.Count = 0
return fc
}
fc.Data = allocBuffer(min(int(c.iounit), int(fc.Count), int(size)))
defer discardBuffer(fc.Data)
n, err := c.explorer.Read(fc.Data, fc.Offset, ref.Path)
if err == io.EOF {
if n == 0 {
// returned EOF without reading anything, should return fc.Count = 0
discardBuffer(fc.Data)
fc.Data = nil
err = nil
return fc
} else {
// was able to read som data from the file, should return the count
// but not the error. The next call to read will trigger the EOF
err = nil
}
}
if err != nil {
return c.unexpectedErr(fc, err)
}
fc.Count = uint32(n)
fc.Data = fc.Data[:fc.Count]
return fc
}
示例2: readdir
func (c *ClientConn) readdir(fc *plan9.Fcall, ref *fileRef) *plan9.Fcall {
// if the call have an offset, return 0
// since all readdir call's will return the full directory
if fc.Offset > 0 {
fc.Count = 0
return fc
}
childs, err := c.explorer.ListDir(ref.Path)
if err != nil {
return c.unexpectedErr(fc, err)
}
tmpBuf := allocBuffer(int(c.iounit))
out := bytes.NewBuffer(tmpBuf[:0])
defer discardBuffer(tmpBuf)
for _, id := range childs {
stat, err := c.explorer.Stat(id.Path)
if err != nil {
return c.unexpectedErr(fc, err)
}
dir := plan9.Dir{
Qid: plan9.Qid{Type: uint8(stat.Type), Vers: stat.Version, Path: id.Path},
Mode: plan9.Perm(stat.Mode),
Atime: stat.Atime,
Mtime: stat.Mtime,
Length: stat.Size,
Uid: stat.Uname,
Gid: stat.Gname,
Name: stat.Name,
}
buf, err := dir.Bytes()
if err != nil {
return c.unexpectedErr(fc, err)
}
_, err = out.Write(buf)
if err != nil {
return c.unexpectedErr(fc, err)
}
}
fc.Count = uint32(len(fc.Data))
fc.Data = out.Bytes()
return fc
}