1 // Copyright 2010 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.
14 func selfConnectedTCPSocket() (pr
, pw
*os
.File
, err error
) {
15 // See ../syscall/exec.go for description of ForkLock.
16 syscall
.ForkLock
.RLock()
17 sockfd
, e
:= syscall
.Socket(syscall
.AF_INET
, syscall
.SOCK_STREAM
, 0)
19 syscall
.ForkLock
.RUnlock()
20 return nil, nil, os
.Errno(e
)
22 syscall
.CloseOnExec(sockfd
)
23 syscall
.ForkLock
.RUnlock()
25 // Allow reuse of recently-used addresses.
26 syscall
.SetsockoptInt(sockfd
, syscall
.SOL_SOCKET
, syscall
.SO_REUSEADDR
, 1)
29 var la syscall
.Sockaddr
30 if laTCP
, err
= ResolveTCPAddr("127.0.0.1:0"); err
!= nil {
34 if la
, err
= laTCP
.sockaddr(syscall
.AF_INET
); err
!= nil {
37 e
= syscall
.Bind(sockfd
, la
)
41 return nil, nil, os
.Errno(e
)
44 laddr
, _
:= syscall
.Getsockname(sockfd
)
45 e
= syscall
.Connect(sockfd
, laddr
)
50 fd
:= os
.NewFile(sockfd
, "wakeupSocket")
54 func newPollServer() (s
*pollServer
, err error
) {
56 s
.cr
= make(chan *netFD
, 1)
57 s
.cw
= make(chan *netFD
, 1)
58 // s.pr and s.pw are indistinguishable.
59 if s
.pr
, s
.pw
, err
= selfConnectedTCPSocket(); err
!= nil {
63 if e
= syscall
.SetNonblock(s
.pr
.Fd(), true); e
!= 0 {
65 err
= &os
.PathError
{"setnonblock", s
.pr
.Name(), os
.Errno(e
)}
70 if s
.poll
, err
= newpollster(); err
!= nil {
73 if _
, err
= s
.poll
.AddFD(s
.pr
.Fd(), 'r', true); err
!= nil {
77 s
.pending
= make(map[int]*netFD
)