mirror of
https://github.com/golang/go
synced 2024-11-13 17:30:24 -07:00
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
This commit is contained in:
parent
2a4f4dd842
commit
a01bdb4ae0
@ -84,19 +84,19 @@ func _NewPollServer() (s *_PollServer, err *os.Error) {
|
|||||||
if s.pr, s.pw, err = os.Pipe(); err != nil {
|
if s.pr, s.pw, err = os.Pipe(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = _SetNonblock(s.pr.fd); err != nil {
|
if err = _SetNonblock(s.pr.Fd); err != nil {
|
||||||
Error:
|
Error:
|
||||||
s.pr.Close();
|
s.pr.Close();
|
||||||
s.pw.Close();
|
s.pw.Close();
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = _SetNonblock(s.pw.fd); err != nil {
|
if err = _SetNonblock(s.pw.Fd); err != nil {
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
if s.poll, err = NewPollster(); err != nil {
|
if s.poll, err = NewPollster(); err != nil {
|
||||||
goto Error
|
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();
|
s.poll.Close();
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ func (s *_PollServer) Run() {
|
|||||||
print("_PollServer WaitFD: ", err.String(), "\n");
|
print("_PollServer WaitFD: ", err.String(), "\n");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if fd == s.pr.fd {
|
if fd == s.pr.Fd {
|
||||||
// Drain our wakeup pipe.
|
// Drain our wakeup pipe.
|
||||||
for nn, e := s.pr.Read(scratch); nn > 0; {
|
for nn, e := s.pr.Read(scratch); nn > 0; {
|
||||||
nn, e = s.pr.Read(scratch)
|
nn, e = s.pr.Read(scratch)
|
||||||
|
@ -9,7 +9,7 @@ import os "os"
|
|||||||
|
|
||||||
// FDs are wrappers for file descriptors
|
// FDs are wrappers for file descriptors
|
||||||
type FD struct {
|
type FD struct {
|
||||||
fd int64
|
Fd int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFD(fd int64) *FD {
|
func NewFD(fd int64) *FD {
|
||||||
@ -48,8 +48,8 @@ func (fd *FD) Close() *Error {
|
|||||||
if fd == nil {
|
if fd == nil {
|
||||||
return EINVAL
|
return EINVAL
|
||||||
}
|
}
|
||||||
r, e := syscall.Close(fd.fd);
|
r, e := syscall.Close(fd.Fd);
|
||||||
fd.fd = -1; // so it can't be closed again
|
fd.Fd = -1; // so it can't be closed again
|
||||||
return ErrnoToError(e)
|
return ErrnoToError(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func (fd *FD) Read(b []byte) (ret int, err *Error) {
|
|||||||
}
|
}
|
||||||
var r, e int64;
|
var r, e int64;
|
||||||
if len(b) > 0 { // because we access b[0]
|
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 {
|
if r < 0 {
|
||||||
r = 0
|
r = 0
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func (fd *FD) Write(b []byte) (ret int, err *Error) {
|
|||||||
}
|
}
|
||||||
var r, e int64;
|
var r, e int64;
|
||||||
if len(b) > 0 { // because we access b[0]
|
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 {
|
if r < 0 {
|
||||||
r = 0
|
r = 0
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ func (fd *FD) WriteString(s string) (ret int, err *Error) {
|
|||||||
if !syscall.StringToBytes(b, s) {
|
if !syscall.StringToBytes(b, s) {
|
||||||
return 0, EINVAL
|
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 {
|
if r < 0 {
|
||||||
r = 0
|
r = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user