Commit a01bdb4a authored by Ian Lance Taylor's avatar Ian Lance Taylor

Add an accessor function os.FD.Fd() to get the file

descriptor.  Use it in the PollServer code.

6g currently accepts this code without this change, but it
should not.  Test case for the bug is bug133.go.

R=rsc
DELTA=10  (0 added, 0 deleted, 10 changed)
OCL=23451
CL=23486
parent 2a4f4dd8
......@@ -84,19 +84,19 @@ func _NewPollServer() (s *_PollServer, err *os.Error) {
if s.pr, s.pw, err = os.Pipe(); err != nil {
return nil, err
}
if err = _SetNonblock(s.pr.fd); err != nil {
if err = _SetNonblock(s.pr.Fd); err != nil {
Error:
s.pr.Close();
s.pw.Close();
return nil, err
}
if err = _SetNonblock(s.pw.fd); err != nil {
if err = _SetNonblock(s.pw.Fd); err != nil {
goto Error
}
if s.poll, err = NewPollster(); err != nil {
goto Error
}
if err = s.poll.AddFD(s.pr.fd, 'r', true); err != nil {
if err = s.poll.AddFD(s.pr.Fd, 'r', true); err != nil {
s.poll.Close();
goto Error
}
......@@ -142,7 +142,7 @@ func (s *_PollServer) Run() {
print("_PollServer WaitFD: ", err.String(), "\n");
return
}
if fd == s.pr.fd {
if fd == s.pr.Fd {
// Drain our wakeup pipe.
for nn, e := s.pr.Read(scratch); nn > 0; {
nn, e = s.pr.Read(scratch)
......
......@@ -9,7 +9,7 @@ import os "os"
// FDs are wrappers for file descriptors
type FD struct {
fd int64
Fd int64
}
func NewFD(fd int64) *FD {
......@@ -48,8 +48,8 @@ func (fd *FD) Close() *Error {
if fd == nil {
return EINVAL
}
r, e := syscall.Close(fd.fd);
fd.fd = -1; // so it can't be closed again
r, e := syscall.Close(fd.Fd);
fd.Fd = -1; // so it can't be closed again
return ErrnoToError(e)
}
......@@ -59,7 +59,7 @@ func (fd *FD) Read(b []byte) (ret int, err *Error) {
}
var r, e int64;
if len(b) > 0 { // because we access b[0]
r, e = syscall.Read(fd.fd, &b[0], int64(len(b)));
r, e = syscall.Read(fd.Fd, &b[0], int64(len(b)));
if r < 0 {
r = 0
}
......@@ -73,7 +73,7 @@ func (fd *FD) Write(b []byte) (ret int, err *Error) {
}
var r, e int64;
if len(b) > 0 { // because we access b[0]
r, e = syscall.Write(fd.fd, &b[0], int64(len(b)));
r, e = syscall.Write(fd.Fd, &b[0], int64(len(b)));
if r < 0 {
r = 0
}
......@@ -89,7 +89,7 @@ func (fd *FD) WriteString(s string) (ret int, err *Error) {
if !syscall.StringToBytes(b, s) {
return 0, EINVAL
}
r, e := syscall.Write(fd.fd, &b[0], int64(len(s)));
r, e := syscall.Write(fd.Fd, &b[0], int64(len(s)));
if r < 0 {
r = 0
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment