1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:04:44 -07:00

Move the function Run() back into fd.go.

R=iant
CC=golang-dev, rsc
https://golang.org/cl/1748041
This commit is contained in:
Vinu Rajashekhar 2010-06-29 12:04:04 -07:00 committed by Ian Lance Taylor
parent da69685ee5
commit 00ad47f906
2 changed files with 44 additions and 46 deletions

View File

@ -194,6 +194,50 @@ func (s *pollServer) CheckDeadlines() {
s.deadline = next_deadline
}
func (s *pollServer) Run() {
var scratch [100]byte
for {
var t = s.deadline
if t > 0 {
t = t - s.Now()
if t <= 0 {
s.CheckDeadlines()
continue
}
}
fd, mode, err := s.poll.WaitFD(t)
if err != nil {
print("pollServer WaitFD: ", err.String(), "\n")
return
}
if fd < 0 {
// Timeout happened.
s.CheckDeadlines()
continue
}
if fd == s.pr.Fd() {
// Drain our wakeup pipe.
for nn, _ := s.pr.Read(scratch[0:]); nn > 0; {
nn, _ = s.pr.Read(scratch[0:])
}
// Read from channels
for fd, ok := <-s.cr; ok; fd, ok = <-s.cr {
s.AddFD(fd, 'r')
}
for fd, ok := <-s.cw; ok; fd, ok = <-s.cw {
s.AddFD(fd, 'w')
}
} else {
netfd := s.LookupFD(fd, mode)
if netfd == nil {
print("pollServer: unexpected wakeup for fd=", netfd, " mode=", string(mode), "\n")
continue
}
s.WakeFD(netfd, mode)
}
}
}
var wakeupbuf [1]byte
func (s *pollServer) Wakeup() { s.pw.Write(wakeupbuf[0:]) }

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TODO(rsc): All the prints in this file should go to standard error.
package net
import (
@ -41,47 +39,3 @@ func newPollServer() (s *pollServer, err os.Error) {
go s.Run()
return s, nil
}
func (s *pollServer) Run() {
var scratch [100]byte
for {
var t = s.deadline
if t > 0 {
t = t - s.Now()
if t <= 0 {
s.CheckDeadlines()
continue
}
}
fd, mode, err := s.poll.WaitFD(t)
if err != nil {
print("pollServer WaitFD: ", err.String(), "\n")
return
}
if fd < 0 {
// Timeout happened.
s.CheckDeadlines()
continue
}
if fd == s.pr.Fd() {
// Drain our wakeup pipe.
for nn, _ := s.pr.Read(scratch[0:]); nn > 0; {
nn, _ = s.pr.Read(scratch[0:])
}
// Read from channels
for fd, ok := <-s.cr; ok; fd, ok = <-s.cr {
s.AddFD(fd, 'r')
}
for fd, ok := <-s.cw; ok; fd, ok = <-s.cw {
s.AddFD(fd, 'w')
}
} else {
netfd := s.LookupFD(fd, mode)
if netfd == nil {
print("pollServer: unexpected wakeup for fd=", netfd, " mode=", string(mode), "\n")
continue
}
s.WakeFD(netfd, mode)
}
}
}