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
f6fab255
Commit
f6fab255
authored
Aug 08, 2011
by
Joel Sing
Committed by
Russ Cox
Aug 08, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: add support for openbsd
R=rsc CC=golang-dev
https://golang.org/cl/4816060
parent
21ac258e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
0 deletions
+128
-0
src/pkg/net/Makefile
src/pkg/net/Makefile
+12
-0
src/pkg/net/fd_openbsd.go
src/pkg/net/fd_openbsd.go
+116
-0
No files found.
src/pkg/net/Makefile
View file @
f6fab255
...
...
@@ -69,6 +69,18 @@ GOFILES_linux=\
sendfile_linux.go
\
sock_linux.go
\
GOFILES_openbsd
=
\
dnsclient.go
\
dnsconfig.go
\
fd.go
\
file.go
\
interface_bsd.go
\
newpollserver.go
\
port.go
\
sendfile_stub.go
\
sock_bsd.go
\
cgo_stub.go
\
GOFILES_plan9
=
\
interface_stub.go
\
lookup_unix.go
\
...
...
src/pkg/net/fd_openbsd.go
0 → 100644
View file @
f6fab255
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Waiting for FDs via kqueue/kevent.
package
net
import
(
"os"
"syscall"
)
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
)
{
p
=
new
(
pollster
)
var
e
int
if
p
.
kq
,
e
=
syscall
.
Kqueue
();
e
!=
0
{
return
nil
,
os
.
NewSyscallError
(
"kqueue"
,
e
)
}
p
.
events
=
p
.
eventbuf
[
0
:
0
]
return
p
,
nil
}
func
(
p
*
pollster
)
AddFD
(
fd
int
,
mode
int
,
repeat
bool
)
(
bool
,
os
.
Error
)
{
// pollServer is locked.
var
kmode
int
if
mode
==
'r'
{
kmode
=
syscall
.
EVFILT_READ
}
else
{
kmode
=
syscall
.
EVFILT_WRITE
}
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
if
!
repeat
{
flags
|=
syscall
.
EV_ONESHOT
}
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
flags
)
n
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
:
],
nil
,
nil
)
if
e
!=
0
{
return
false
,
os
.
NewSyscallError
(
"kevent"
,
e
)
}
if
n
!=
1
||
(
ev
.
Flags
&
syscall
.
EV_ERROR
)
==
0
||
int
(
ev
.
Ident
)
!=
fd
||
int
(
ev
.
Filter
)
!=
kmode
{
return
false
,
os
.
NewSyscallError
(
"kqueue phase error"
,
e
)
}
if
ev
.
Data
!=
0
{
return
false
,
os
.
Errno
(
int
(
ev
.
Data
))
}
return
false
,
nil
}
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
}
ev
:=
&
p
.
kbuf
[
0
]
// EV_DELETE - delete event from kqueue list
syscall
.
SetKevent
(
ev
,
fd
,
kmode
,
syscall
.
EV_DELETE
)
syscall
.
Kevent
(
p
.
kq
,
p
.
kbuf
[
:
],
nil
,
nil
)
}
func
(
p
*
pollster
)
WaitFD
(
s
*
pollServer
,
nsec
int64
)
(
fd
int
,
mode
int
,
err
os
.
Error
)
{
var
t
*
syscall
.
Timespec
for
len
(
p
.
events
)
==
0
{
if
nsec
>
0
{
if
t
==
nil
{
t
=
new
(
syscall
.
Timespec
)
}
*
t
=
syscall
.
NsecToTimespec
(
nsec
)
}
s
.
Unlock
()
nn
,
e
:=
syscall
.
Kevent
(
p
.
kq
,
nil
,
p
.
eventbuf
[
:
],
t
)
s
.
Lock
()
if
e
!=
0
{
if
e
==
syscall
.
EINTR
{
continue
}
return
-
1
,
0
,
os
.
NewSyscallError
(
"kevent"
,
e
)
}
if
nn
==
0
{
return
-
1
,
0
,
nil
}
p
.
events
=
p
.
eventbuf
[
0
:
nn
]
}
ev
:=
&
p
.
events
[
0
]
p
.
events
=
p
.
events
[
1
:
]
fd
=
int
(
ev
.
Ident
)
if
ev
.
Filter
==
syscall
.
EVFILT_READ
{
mode
=
'r'
}
else
{
mode
=
'w'
}
return
fd
,
mode
,
nil
}
func
(
p
*
pollster
)
Close
()
os
.
Error
{
return
os
.
NewSyscallError
(
"close"
,
syscall
.
Close
(
p
.
kq
))
}
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