1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 func runtime_pollServerInit()
16 func runtime_pollOpen(fd
int) (uintptr, int)
17 func runtime_pollClose(ctx
uintptr)
18 func runtime_pollWait(ctx
uintptr, mode
int) int
19 func runtime_pollReset(ctx
uintptr, mode
int) int
20 func runtime_pollSetDeadline(ctx
uintptr, d
int64, mode
int)
21 func runtime_pollUnblock(ctx
uintptr)
23 var canCancelIO
= true // used for testing current package
25 type pollDesc
struct {
29 var serverInit sync
.Once
34 func (pd
*pollDesc
) Init(fd
*netFD
) error
{
35 serverInit
.Do(runtime_pollServerInit
)
36 ctx
, errno
:= runtime_pollOpen(fd
.sysfd
)
38 return syscall
.Errno(errno
)
44 func (pd
*pollDesc
) Close() {
45 runtime_pollClose(pd
.runtimeCtx
)
48 func (pd
*pollDesc
) Lock() {
51 func (pd
*pollDesc
) Unlock() {
54 func (pd
*pollDesc
) Wakeup() {
57 // Evict evicts fd from the pending list, unblocking any I/O running on fd.
58 // Return value is whether the pollServer should be woken up.
59 func (pd
*pollDesc
) Evict() bool {
60 runtime_pollUnblock(pd
.runtimeCtx
)
64 func (pd
*pollDesc
) PrepareRead() error
{
65 res
:= runtime_pollReset(pd
.runtimeCtx
, 'r')
66 return convertErr(res
)
69 func (pd
*pollDesc
) PrepareWrite() error
{
70 res
:= runtime_pollReset(pd
.runtimeCtx
, 'w')
71 return convertErr(res
)
74 func (pd
*pollDesc
) WaitRead() error
{
75 res
:= runtime_pollWait(pd
.runtimeCtx
, 'r')
76 return convertErr(res
)
79 func (pd
*pollDesc
) WaitWrite() error
{
80 res
:= runtime_pollWait(pd
.runtimeCtx
, 'w')
81 return convertErr(res
)
84 func convertErr(res
int) error
{
96 func setReadDeadline(fd
*netFD
, t time
.Time
) error
{
97 return setDeadlineImpl(fd
, t
, 'r')
100 func setWriteDeadline(fd
*netFD
, t time
.Time
) error
{
101 return setDeadlineImpl(fd
, t
, 'w')
104 func setDeadline(fd
*netFD
, t time
.Time
) error
{
105 return setDeadlineImpl(fd
, t
, 'r'+'w')
108 func setDeadlineImpl(fd
*netFD
, t time
.Time
, mode
int) error
{
113 if err
:= fd
.incref(false); err
!= nil {
116 runtime_pollSetDeadline(fd
.pd
.runtimeCtx
, d
, mode
)