diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-11-21 07:03:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-11-21 07:03:38 +0000 |
commit | fabcaa8df3d6eb852b87821ef090d31d222870b7 (patch) | |
tree | 72455aea0286937aa08cc141e5efc800e4626577 /libgo/go/net/fd_plan9.go | |
parent | a51fb17f48428e7cfc96a72a9f9f87901363bb6b (diff) | |
download | gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.zip gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.gz gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.bz2 |
libgo: Update to current version of master library.
From-SVN: r193688
Diffstat (limited to 'libgo/go/net/fd_plan9.go')
-rw-r--r-- | libgo/go/net/fd_plan9.go | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/libgo/go/net/fd_plan9.go b/libgo/go/net/fd_plan9.go new file mode 100644 index 0000000..6d7ab38 --- /dev/null +++ b/libgo/go/net/fd_plan9.go @@ -0,0 +1,115 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +import ( + "io" + "os" + "syscall" + "time" +) + +// Network file descritor. +type netFD struct { + proto, name, dir string + ctl, data *os.File + laddr, raddr Addr +} + +var canCancelIO = true // used for testing current package + +func sysInit() { +} + +func newFD(proto, name string, ctl *os.File, laddr, raddr Addr) *netFD { + return &netFD{proto, name, "/net/" + proto + "/" + name, ctl, nil, laddr, raddr} +} + +func (fd *netFD) ok() bool { return fd != nil && fd.ctl != nil } + +func (fd *netFD) Read(b []byte) (n int, err error) { + if !fd.ok() { + return 0, syscall.EINVAL + } + if fd.data == nil { + fd.data, err = os.OpenFile(fd.dir+"/data", os.O_RDWR, 0) + if err != nil { + return 0, err + } + } + n, err = fd.data.Read(b) + if fd.proto == "udp" && err == io.EOF { + n = 0 + err = nil + } + return +} + +func (fd *netFD) Write(b []byte) (n int, err error) { + if !fd.ok() { + return 0, syscall.EINVAL + } + if fd.data == nil { + fd.data, err = os.OpenFile(fd.dir+"/data", os.O_RDWR, 0) + if err != nil { + return 0, err + } + } + return fd.data.Write(b) +} + +func (fd *netFD) CloseRead() error { + if !fd.ok() { + return syscall.EINVAL + } + return syscall.EPLAN9 +} + +func (fd *netFD) CloseWrite() error { + if !fd.ok() { + return syscall.EINVAL + } + return syscall.EPLAN9 +} + +func (fd *netFD) Close() error { + if !fd.ok() { + return syscall.EINVAL + } + err := fd.ctl.Close() + if err != nil { + return err + } + if fd.data != nil { + err = fd.data.Close() + } + fd.ctl = nil + fd.data = nil + return err +} + +func (fd *netFD) dup() (*os.File, error) { + return nil, syscall.EPLAN9 +} + +func setDeadline(fd *netFD, t time.Time) error { + return syscall.EPLAN9 +} + +func setReadDeadline(fd *netFD, t time.Time) error { + return syscall.EPLAN9 +} + +func setWriteDeadline(fd *netFD, t time.Time) error { + return syscall.EPLAN9 +} + +func setReadBuffer(fd *netFD, bytes int) error { + return syscall.EPLAN9 +} + +func setWriteBuffer(fd *netFD, bytes int) error { + return syscall.EPLAN9 +} |