2013-02-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
[official-gcc.git] / libgo / go / net / fd_plan9.go
blob3462792816e5f4d2e9952b4ae69075051825658e
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package net
7 import (
8 "io"
9 "os"
10 "syscall"
11 "time"
14 // Network file descritor.
15 type netFD struct {
16 proto, name, dir string
17 ctl, data *os.File
18 laddr, raddr Addr
21 var canCancelIO = true // used for testing current package
23 func sysInit() {
26 func dialTimeout(net, addr string, timeout time.Duration) (Conn, error) {
27 // On plan9, use the relatively inefficient
28 // goroutine-racing implementation.
29 return dialTimeoutRace(net, addr, timeout)
32 func newFD(proto, name string, ctl *os.File, laddr, raddr Addr) *netFD {
33 return &netFD{proto, name, "/net/" + proto + "/" + name, ctl, nil, laddr, raddr}
36 func (fd *netFD) ok() bool { return fd != nil && fd.ctl != nil }
38 func (fd *netFD) Read(b []byte) (n int, err error) {
39 if !fd.ok() {
40 return 0, syscall.EINVAL
42 if fd.data == nil {
43 fd.data, err = os.OpenFile(fd.dir+"/data", os.O_RDWR, 0)
44 if err != nil {
45 return 0, err
48 n, err = fd.data.Read(b)
49 if fd.proto == "udp" && err == io.EOF {
50 n = 0
51 err = nil
53 return
56 func (fd *netFD) Write(b []byte) (n int, err error) {
57 if !fd.ok() {
58 return 0, syscall.EINVAL
60 if fd.data == nil {
61 fd.data, err = os.OpenFile(fd.dir+"/data", os.O_RDWR, 0)
62 if err != nil {
63 return 0, err
66 return fd.data.Write(b)
69 func (fd *netFD) CloseRead() error {
70 if !fd.ok() {
71 return syscall.EINVAL
73 return syscall.EPLAN9
76 func (fd *netFD) CloseWrite() error {
77 if !fd.ok() {
78 return syscall.EINVAL
80 return syscall.EPLAN9
83 func (fd *netFD) Close() error {
84 if !fd.ok() {
85 return syscall.EINVAL
87 err := fd.ctl.Close()
88 if err != nil {
89 return err
91 if fd.data != nil {
92 err = fd.data.Close()
94 fd.ctl = nil
95 fd.data = nil
96 return err
99 func (fd *netFD) dup() (*os.File, error) {
100 return nil, syscall.EPLAN9
103 func setDeadline(fd *netFD, t time.Time) error {
104 return syscall.EPLAN9
107 func setReadDeadline(fd *netFD, t time.Time) error {
108 return syscall.EPLAN9
111 func setWriteDeadline(fd *netFD, t time.Time) error {
112 return syscall.EPLAN9
115 func setReadBuffer(fd *netFD, bytes int) error {
116 return syscall.EPLAN9
119 func setWriteBuffer(fd *netFD, bytes int) error {
120 return syscall.EPLAN9