Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
000d60ac
Commit
000d60ac
authored
Mar 18, 2011
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: Use preallocated buffer for kqueue/kevent.
R=rsc CC=golang-dev
https://golang.org/cl/4293056
parent
3be0921e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
12 deletions
+24
-12
src/pkg/net/fd_darwin.go
src/pkg/net/fd_darwin.go
+12
-6
src/pkg/net/fd_freebsd.go
src/pkg/net/fd_freebsd.go
+12
-6
No files found.
src/pkg/net/fd_darwin.go
View file @
000d60ac
...
...
@@ -15,6 +15,10 @@ type pollster struct {
kq
int
eventbuf
[
10
]
syscall
.
Kevent_t
events
[]
syscall
.
Kevent_t
// An event buffer for AddFD/DelFD.
// Must hold pollServer lock.
kbuf
[
1
]
syscall
.
Kevent_t
}
func
newpollster
()
(
p
*
pollster
,
err
os
.
Error
)
{
...
...
@@ -28,14 +32,15 @@ func newpollster() (p *pollster, err os.Error) {
}
func
(
p
*
pollster
)
AddFD
(
fd
int
,
mode
int
,
repeat
bool
)
os
.
Error
{
// pollServer is locked.
var
kmode
int
if
mode
==
'r'
{
kmode
=
syscall
.
EVFILT_READ
}
else
{
kmode
=
syscall
.
EVFILT_WRITE
}
var
events
[
1
]
syscall
.
Kevent_t
ev
:=
&
events
[
0
]
ev
:=
&
p
.
kbuf
[
0
]
// EV_ADD - add event to kqueue list
// EV_RECEIPT - generate fake EV_ERROR as result of add,
// rather than waiting for real event
...
...
@@ -46,7 +51,7 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
}
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
flags
)
n
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
events
[
0
:
],
events
[
0
:
],
nil
)
n
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
0
:
],
p
.
kbuf
[
0
:
],
nil
)
if
e
!=
0
{
return
os
.
NewSyscallError
(
"kevent"
,
e
)
}
...
...
@@ -60,19 +65,20 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
}
func
(
p
*
pollster
)
DelFD
(
fd
int
,
mode
int
)
{
// pollServer is locked.
var
kmode
int
if
mode
==
'r'
{
kmode
=
syscall
.
EVFILT_READ
}
else
{
kmode
=
syscall
.
EVFILT_WRITE
}
var
events
[
1
]
syscall
.
Kevent_t
ev
:=
&
events
[
0
]
ev
:=
&
p
.
kbuf
[
0
]
// EV_DELETE - delete event from kqueue list
// EV_RECEIPT - generate fake EV_ERROR as result of add,
// rather than waiting for real event
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
syscall
.
EV_DELETE
|
syscall
.
EV_RECEIPT
)
syscall
.
Kevent
(
p
.
kq
,
events
[
0
:
],
events
[
0
:
],
nil
)
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
0
:
],
p
.
kbuf
[
0
:
],
nil
)
}
func
(
p
*
pollster
)
WaitFD
(
s
*
pollServer
,
nsec
int64
)
(
fd
int
,
mode
int
,
err
os
.
Error
)
{
...
...
src/pkg/net/fd_freebsd.go
View file @
000d60ac
...
...
@@ -15,6 +15,10 @@ type pollster struct {
kq
int
eventbuf
[
10
]
syscall
.
Kevent_t
events
[]
syscall
.
Kevent_t
// An event buffer for AddFD/DelFD.
// Must hold pollServer lock.
kbuf
[
1
]
syscall
.
Kevent_t
}
func
newpollster
()
(
p
*
pollster
,
err
os
.
Error
)
{
...
...
@@ -28,14 +32,15 @@ func newpollster() (p *pollster, err os.Error) {
}
func
(
p
*
pollster
)
AddFD
(
fd
int
,
mode
int
,
repeat
bool
)
os
.
Error
{
// pollServer is locked.
var
kmode
int
if
mode
==
'r'
{
kmode
=
syscall
.
EVFILT_READ
}
else
{
kmode
=
syscall
.
EVFILT_WRITE
}
var
events
[
1
]
syscall
.
Kevent_t
ev
:=
&
events
[
0
]
ev
:=
&
p
.
kbuf
[
0
]
// EV_ADD - add event to kqueue list
// EV_ONESHOT - delete the event the first time it triggers
flags
:=
syscall
.
EV_ADD
...
...
@@ -44,7 +49,7 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
}
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
flags
)
n
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
events
[
:
],
nil
,
nil
)
n
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
:
],
nil
,
nil
)
if
e
!=
0
{
return
os
.
NewSyscallError
(
"kevent"
,
e
)
}
...
...
@@ -58,17 +63,18 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
}
func
(
p
*
pollster
)
DelFD
(
fd
int
,
mode
int
)
{
// pollServer is locked.
var
kmode
int
if
mode
==
'r'
{
kmode
=
syscall
.
EVFILT_READ
}
else
{
kmode
=
syscall
.
EVFILT_WRITE
}
var
events
[
1
]
syscall
.
Kevent_t
ev
:=
&
events
[
0
]
ev
:=
&
p
.
kbuf
[
0
]
// EV_DELETE - delete event from kqueue list
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
syscall
.
EV_DELETE
)
syscall
.
Kevent
(
p
.
kq
,
events
[
:
],
nil
,
nil
)
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
:
],
nil
,
nil
)
}
func
(
p
*
pollster
)
WaitFD
(
s
*
pollServer
,
nsec
int64
)
(
fd
int
,
mode
int
,
err
os
.
Error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment