Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(994)

Side by Side Diff: src/pkg/net/fd_openbsd.go

Issue 5294074: code review 5294074: src/pkg/[n-z]*: gofix -r error (Closed)
Patch Set: diff -r b78bb4f2d2a3 https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/fd_linux.go ('k') | src/pkg/net/fd_windows.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Waiting for FDs via kqueue/kevent. 5 // Waiting for FDs via kqueue/kevent.
6 6
7 package net 7 package net
8 8
9 import ( 9 import (
10 "os" 10 "os"
11 "syscall" 11 "syscall"
12 ) 12 )
13 13
14 type pollster struct { 14 type pollster struct {
15 kq int 15 kq int
16 eventbuf [10]syscall.Kevent_t 16 eventbuf [10]syscall.Kevent_t
17 events []syscall.Kevent_t 17 events []syscall.Kevent_t
18 18
19 // An event buffer for AddFD/DelFD. 19 // An event buffer for AddFD/DelFD.
20 // Must hold pollServer lock. 20 // Must hold pollServer lock.
21 kbuf [1]syscall.Kevent_t 21 kbuf [1]syscall.Kevent_t
22 } 22 }
23 23
24 func newpollster() (p *pollster, err os.Error) { 24 func newpollster() (p *pollster, err error) {
25 p = new(pollster) 25 p = new(pollster)
26 var e int 26 var e int
27 if p.kq, e = syscall.Kqueue(); e != 0 { 27 if p.kq, e = syscall.Kqueue(); e != 0 {
28 return nil, os.NewSyscallError("kqueue", e) 28 return nil, os.NewSyscallError("kqueue", e)
29 } 29 }
30 p.events = p.eventbuf[0:0] 30 p.events = p.eventbuf[0:0]
31 return p, nil 31 return p, nil
32 } 32 }
33 33
34 func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, os.Error) { 34 func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
35 // pollServer is locked. 35 // pollServer is locked.
36 36
37 var kmode int 37 var kmode int
38 if mode == 'r' { 38 if mode == 'r' {
39 kmode = syscall.EVFILT_READ 39 kmode = syscall.EVFILT_READ
40 } else { 40 } else {
41 kmode = syscall.EVFILT_WRITE 41 kmode = syscall.EVFILT_WRITE
42 } 42 }
43 ev := &p.kbuf[0] 43 ev := &p.kbuf[0]
44 // EV_ADD - add event to kqueue list 44 // EV_ADD - add event to kqueue list
(...skipping 25 matching lines...) Expand all
70 kmode = syscall.EVFILT_READ 70 kmode = syscall.EVFILT_READ
71 } else { 71 } else {
72 kmode = syscall.EVFILT_WRITE 72 kmode = syscall.EVFILT_WRITE
73 } 73 }
74 ev := &p.kbuf[0] 74 ev := &p.kbuf[0]
75 // EV_DELETE - delete event from kqueue list 75 // EV_DELETE - delete event from kqueue list
76 syscall.SetKevent(ev, fd, kmode, syscall.EV_DELETE) 76 syscall.SetKevent(ev, fd, kmode, syscall.EV_DELETE)
77 syscall.Kevent(p.kq, p.kbuf[:], nil, nil) 77 syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
78 } 78 }
79 79
80 func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E rror) { 80 func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err erro r) {
81 var t *syscall.Timespec 81 var t *syscall.Timespec
82 for len(p.events) == 0 { 82 for len(p.events) == 0 {
83 if nsec > 0 { 83 if nsec > 0 {
84 if t == nil { 84 if t == nil {
85 t = new(syscall.Timespec) 85 t = new(syscall.Timespec)
86 } 86 }
87 *t = syscall.NsecToTimespec(nsec) 87 *t = syscall.NsecToTimespec(nsec)
88 } 88 }
89 89
90 s.Unlock() 90 s.Unlock()
(...skipping 15 matching lines...) Expand all
106 p.events = p.events[1:] 106 p.events = p.events[1:]
107 fd = int(ev.Ident) 107 fd = int(ev.Ident)
108 if ev.Filter == syscall.EVFILT_READ { 108 if ev.Filter == syscall.EVFILT_READ {
109 mode = 'r' 109 mode = 'r'
110 } else { 110 } else {
111 mode = 'w' 111 mode = 'w'
112 } 112 }
113 return fd, mode, nil 113 return fd, mode, nil
114 } 114 }
115 115
116 func (p *pollster) Close() os.Error { return os.NewSyscallError("close", syscall .Close(p.kq)) } 116 func (p *pollster) Close() error { return os.NewSyscallError("close", syscall.Cl ose(p.kq)) }
OLDNEW
« no previous file with comments | « src/pkg/net/fd_linux.go ('k') | src/pkg/net/fd_windows.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b