Commit 00ad47f9 authored by Vinu Rajashekhar's avatar Vinu Rajashekhar Committed by Ian Lance Taylor

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

R=iant
CC=golang-dev, rsc
https://golang.org/cl/1748041
parent da69685e
......@@ -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:]) }
......
......@@ -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)
}
}
}
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