doWakeup = true
}
- if err := s.poll.AddFD(intfd, mode, false); err != nil {
+ wake, err := s.poll.AddFD(intfd, mode, false)
+ if err != nil {
panic("pollServer AddFD " + err.String())
}
+ if wake {
+ doWakeup = true
+ }
s.Unlock()
return p, nil
}
-func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
+func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
// pollServer is locked.
var already bool
op = syscall.EPOLL_CTL_ADD
}
if e := syscall.EpollCtl(p.epfd, op, fd, &p.ctlEvent); e != 0 {
- return os.NewSyscallError("epoll_ctl", e)
+ return false, os.NewSyscallError("epoll_ctl", e)
}
p.events[fd] = p.ctlEvent.Events
- return nil
+ return false, nil
}
func (p *pollster) StopWaiting(fd int, bits uint) {
return p, nil
}
-func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
+func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) {
+ // pollServer is locked.
+
if mode == 'r' {
syscall.FDSet(fd, p.readFds)
} else {
p.maxFd = fd
}
- return nil
+ return true, nil
}
func (p *pollster) DelFD(fd int, mode int) {
+ // pollServer is locked.
+
if mode == 'r' {
if !syscall.FDIsSet(fd, p.readFds) {
print("Select unexpected fd=", fd, " for read\n")
// We don't worry about maxFd here.
}
-func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) {
+func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.Error) {
if p.nReady == 0 {
var timeout *syscall.Timeval
var tv syscall.Timeval
tmpReadFds = *p.readFds
tmpWriteFds = *p.writeFds
+ s.Unlock()
n, e = syscall.Select(p.maxFd + 1, &tmpReadFds, &tmpWriteFds, nil, timeout)
+ s.Lock()
+
if e != syscall.EINTR {
break
}
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
}
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
}