2010-06-29 21:23:39 -06:00
|
|
|
// Copyright 2010 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.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2016-04-14 18:47:25 -06:00
|
|
|
"context"
|
2017-02-10 15:59:38 -07:00
|
|
|
"internal/poll"
|
2010-06-29 21:23:39 -06:00
|
|
|
"os"
|
2011-01-19 12:49:25 -07:00
|
|
|
"runtime"
|
2010-06-29 21:23:39 -06:00
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
// canUseConnectEx reports whether we can use the ConnectEx Windows API call
|
|
|
|
// for the given network type.
|
2013-01-10 18:42:09 -07:00
|
|
|
func canUseConnectEx(net string) bool {
|
2013-08-23 04:31:24 -06:00
|
|
|
switch net {
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
case "tcp", "tcp4", "tcp6":
|
|
|
|
return true
|
2013-01-10 18:42:09 -07:00
|
|
|
}
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
// ConnectEx windows API does not support connectionless sockets.
|
|
|
|
return false
|
2013-01-10 18:42:09 -07:00
|
|
|
}
|
|
|
|
|
2011-02-22 20:40:24 -07:00
|
|
|
// Network file descriptor.
|
|
|
|
type netFD struct {
|
2017-02-10 15:59:38 -07:00
|
|
|
pfd poll.FD
|
2010-06-29 21:23:39 -06:00
|
|
|
|
2011-02-22 20:40:24 -07:00
|
|
|
// immutable until Close
|
2017-02-10 15:59:38 -07:00
|
|
|
family int
|
|
|
|
sotype int
|
|
|
|
isConnected bool
|
|
|
|
net string
|
|
|
|
laddr Addr
|
|
|
|
raddr Addr
|
2011-02-22 20:40:24 -07:00
|
|
|
}
|
|
|
|
|
2013-08-06 04:40:10 -06:00
|
|
|
func newFD(sysfd syscall.Handle, family, sotype int, net string) (*netFD, error) {
|
2017-02-10 15:59:38 -07:00
|
|
|
ret := &netFD{
|
|
|
|
pfd: poll.FD{
|
|
|
|
Sysfd: sysfd,
|
|
|
|
IsStream: sotype == syscall.SOCK_STREAM,
|
|
|
|
ZeroReadIsEOF: sotype != syscall.SOCK_DGRAM && sotype != syscall.SOCK_RAW,
|
|
|
|
},
|
|
|
|
family: family,
|
|
|
|
sotype: sotype,
|
|
|
|
net: net,
|
2013-07-21 20:49:57 -06:00
|
|
|
}
|
2017-02-10 15:59:38 -07:00
|
|
|
return ret, nil
|
2013-08-06 08:42:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fd *netFD) init() error {
|
2017-02-10 15:59:38 -07:00
|
|
|
errcall, err := fd.pfd.Init(fd.net)
|
|
|
|
if errcall != "" {
|
|
|
|
err = wrapSyscallError(errcall, err)
|
2013-08-06 04:40:10 -06:00
|
|
|
}
|
2017-02-10 15:59:38 -07:00
|
|
|
return err
|
2011-03-28 21:40:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fd *netFD) setAddr(laddr, raddr Addr) {
|
|
|
|
fd.laddr = laddr
|
|
|
|
fd.raddr = raddr
|
2013-07-29 10:01:13 -06:00
|
|
|
runtime.SetFinalizer(fd, (*netFD).Close)
|
2011-03-28 21:40:01 -06:00
|
|
|
}
|
|
|
|
|
2017-06-14 20:55:40 -06:00
|
|
|
// Always returns nil for connected peer address result.
|
|
|
|
func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (syscall.Sockaddr, error) {
|
net: add special netFD mutex
The mutex, fdMutex, handles locking and lifetime of sysfd,
and serializes Read and Write methods.
This allows to strip 2 sync.Mutex.Lock calls,
2 sync.Mutex.Unlock calls, 1 defer and some amount
of misc overhead from every network operation.
On linux/amd64, Intel E5-2690:
benchmark old ns/op new ns/op delta
BenchmarkTCP4Persistent 9595 9454 -1.47%
BenchmarkTCP4Persistent-2 8978 8772 -2.29%
BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61%
BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96%
In general it strips 70-500 ns from every network operation depending
on processor model. On my relatively new E5-2690 it accounts to ~5%
of network op cost.
Fixes #6074.
R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/12418043
2013-08-09 11:43:00 -06:00
|
|
|
// Do not need to call fd.writeLock here,
|
|
|
|
// because fd is not yet accessible to user,
|
|
|
|
// so no concurrent operations are possible.
|
2014-07-29 01:48:11 -06:00
|
|
|
if err := fd.init(); err != nil {
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, err
|
2014-07-29 01:48:11 -06:00
|
|
|
}
|
net: fix plan9 after context change, propagate contexts more
My previous https://golang.org/cl/22101 to add context throughout the
net package broke Plan 9, which isn't currently tested (#15251).
It also broke some old unsupported version of Windows (Windows 2000?)
which doesn't have the ConnectEx function, but that was only found
visually, since our minimum supported Windows version has ConnectEx.
This change simplifies the Windows and deletes the non-ConnectEx code
path. Windows 2000 will work even less now, if it even worked
before. Windows XP remains our minimum supported version.
Specifically, the previous CL stopped using the "dial" function, which
0intro noted:
https://github.com/golang/go/issues/15333#issuecomment-210842761
This CL removes the dial function instead and makes plan9's net
implementation respect contexts, which likely fixes a number of
t.Skipped tests. I'm leaving that to 0intro to investigate.
In the process of propagating and respecting contexts for plan9, I had
to change some signatures to add contexts to more places and ended up
pushing contexts down into the Go-based DNS resolution as well,
replacing the pure-Go DNS implementation's use of "timeout
time.Duration" with a context instead.
Updates #11932
Updates #15328
Fixes #15333
Change-Id: I6ad1e62f38271cdd86b3f40921f2d0f23374936a
Reviewed-on: https://go-review.googlesource.com/22144
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-16 15:17:40 -06:00
|
|
|
if deadline, ok := ctx.Deadline(); ok && !deadline.IsZero() {
|
2017-02-10 15:59:38 -07:00
|
|
|
fd.pfd.SetWriteDeadline(deadline)
|
|
|
|
defer fd.pfd.SetWriteDeadline(noDeadline)
|
2014-07-29 01:48:11 -06:00
|
|
|
}
|
2013-01-10 18:42:09 -07:00
|
|
|
if !canUseConnectEx(fd.net) {
|
2017-02-10 15:59:38 -07:00
|
|
|
err := connectFunc(fd.pfd.Sysfd, ra)
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, os.NewSyscallError("connect", err)
|
2013-01-10 18:42:09 -07:00
|
|
|
}
|
|
|
|
// ConnectEx windows API requires an unconnected, previously bound socket.
|
2013-04-30 18:47:39 -06:00
|
|
|
if la == nil {
|
|
|
|
switch ra.(type) {
|
|
|
|
case *syscall.SockaddrInet4:
|
|
|
|
la = &syscall.SockaddrInet4{}
|
|
|
|
case *syscall.SockaddrInet6:
|
|
|
|
la = &syscall.SockaddrInet6{}
|
|
|
|
default:
|
|
|
|
panic("unexpected type in connect")
|
|
|
|
}
|
2017-02-10 15:59:38 -07:00
|
|
|
if err := syscall.Bind(fd.pfd.Sysfd, la); err != nil {
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, os.NewSyscallError("bind", err)
|
2013-04-30 18:47:39 -06:00
|
|
|
}
|
2013-01-10 18:42:09 -07:00
|
|
|
}
|
2016-04-14 18:47:25 -06:00
|
|
|
|
|
|
|
// Wait for the goroutine converting context.Done into a write timeout
|
|
|
|
// to exist, otherwise our caller might cancel the context and
|
|
|
|
// cause fd.setWriteDeadline(aLongTimeAgo) to cancel a successful dial.
|
|
|
|
done := make(chan bool) // must be unbuffered
|
|
|
|
defer func() { done <- true }()
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
// Force the runtime's poller to immediately give
|
|
|
|
// up waiting for writability.
|
2017-02-10 15:59:38 -07:00
|
|
|
fd.pfd.SetWriteDeadline(aLongTimeAgo)
|
2016-04-14 18:47:25 -06:00
|
|
|
<-done
|
|
|
|
case <-done:
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-02-10 15:59:38 -07:00
|
|
|
// Call ConnectEx API.
|
|
|
|
if err := fd.pfd.ConnectEx(ra); err != nil {
|
2015-12-14 15:21:48 -07:00
|
|
|
select {
|
2016-04-14 18:47:25 -06:00
|
|
|
case <-ctx.Done():
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, mapErr(ctx.Err())
|
2015-12-14 15:21:48 -07:00
|
|
|
default:
|
|
|
|
if _, ok := err.(syscall.Errno); ok {
|
|
|
|
err = os.NewSyscallError("connectex", err)
|
|
|
|
}
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, err
|
net: fix inconsistent errors
These a series of changes fix inconsistent errors on the package net
APIs. Now almost all the APIs return OpError as a common error type
except Lookup, Resolve and Parse APIs. The Lookup, Resolve and Parse
APIs return more specific errors such as DNSError, AddrError or
ParseError.
An OpError may contain nested error information. For example, Dial may
return an OpError containing a DNSError, AddrError, unexposed type/value
or other package's type/value like the following:
OpError{/* dial info */, Err: &DNSError{}}
OpError{/* dial info */, Err: &AddrError{}}
OpError{/* dial info */, Err: <unexposed type or value>}
OpError{/* dial info */, Err: <other package's type or value>}
and Read and Write may return an OpError containing other OpError when
an application uses io.Copy or similar:
OpError{/* for io.Reader */, Err: &OpError{/* for io.Writer */}}
When an endpoint is created for connection-oriented byte-stream
protocols, Read may return an io.EOF when the connection is closed by
remote endpoint.
Fixes #4856.
A series of changes:
- net: fix inconsistent error values on Dial, Listen partially
https://go.googlesource.com/go/+/89b7c66d0d14462fd7893be4290bdfe5f9063ae1
- net: fix inconsistent error values on Read
https://go.googlesource.com/go/+/ec1144423f45e010c72363fe59291d43214b6e31
- net: fix inconsistent error values on Write
https://go.googlesource.com/go/+/11b5f98bf0d5eb8854f735cc332c912725070214
- net: fix inconsistent error values on Close
https://go.googlesource.com/go/+/310db63c5bc121e7bfccb494c01a6b91a257e7fc
- net: fix inconsistent error values on Accept
https://go.googlesource.com/go/+/4540e162b1aefda8157372764ad3d290a414ef1d
- net: fix inconsistent error values on File
https://go.googlesource.com/go/+/885111365ba0a74421059bfbd18f4c57c1e70332
- net: fix inconsistent error values on setters
https://go.googlesource.com/go/+/2173a27903897c481b0a0daf3ca3e0a0685701db
- net: fix inconsistent error values on Interface
https://go.googlesource.com/go/+/456cf0f22c93e1a6654980f4a48a564555f6c8a2
- net: fix inconsistent error values on Lookup
https://go.googlesource.com/go/+/0fc582e87942b2e52bed751b6c56660ba99e9a7d
- net: add Source field to OpError
https://go.googlesource.com/go/+/afd2d2b6df3ebfe99faf347030f15adfdf422fa0
Change-Id: Id678e369088dc9fbe9073cfe7ff8a8754a57d61f
Reviewed-on: https://go-review.googlesource.com/9236
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-21 06:20:15 -06:00
|
|
|
}
|
2013-01-10 18:42:09 -07:00
|
|
|
}
|
|
|
|
// Refresh socket properties.
|
2017-06-14 20:55:40 -06:00
|
|
|
return nil, os.NewSyscallError("setsockopt", syscall.Setsockopt(fd.pfd.Sysfd, syscall.SOL_SOCKET, syscall.SO_UPDATE_CONNECT_CONTEXT, (*byte)(unsafe.Pointer(&fd.pfd.Sysfd)), int32(unsafe.Sizeof(fd.pfd.Sysfd))))
|
net: add special netFD mutex
The mutex, fdMutex, handles locking and lifetime of sysfd,
and serializes Read and Write methods.
This allows to strip 2 sync.Mutex.Lock calls,
2 sync.Mutex.Unlock calls, 1 defer and some amount
of misc overhead from every network operation.
On linux/amd64, Intel E5-2690:
benchmark old ns/op new ns/op delta
BenchmarkTCP4Persistent 9595 9454 -1.47%
BenchmarkTCP4Persistent-2 8978 8772 -2.29%
BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61%
BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96%
In general it strips 70-500 ns from every network operation depending
on processor model. On my relatively new E5-2690 it accounts to ~5%
of network op cost.
Fixes #6074.
R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/12418043
2013-08-09 11:43:00 -06:00
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func (fd *netFD) Close() error {
|
2017-02-10 15:59:38 -07:00
|
|
|
runtime.SetFinalizer(fd, nil)
|
|
|
|
return fd.pfd.Close()
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2011-11-01 20:05:34 -06:00
|
|
|
func (fd *netFD) shutdown(how int) error {
|
2017-02-10 15:59:38 -07:00
|
|
|
err := fd.pfd.Shutdown(how)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return err
|
2011-09-28 09:12:38 -06:00
|
|
|
}
|
|
|
|
|
2014-04-03 18:07:44 -06:00
|
|
|
func (fd *netFD) closeRead() error {
|
2011-10-12 11:45:25 -06:00
|
|
|
return fd.shutdown(syscall.SHUT_RD)
|
|
|
|
}
|
|
|
|
|
2014-04-03 18:07:44 -06:00
|
|
|
func (fd *netFD) closeWrite() error {
|
2011-10-12 11:45:25 -06:00
|
|
|
return fd.shutdown(syscall.SHUT_WR)
|
2011-09-28 09:12:38 -06:00
|
|
|
}
|
|
|
|
|
2012-01-31 08:36:45 -07:00
|
|
|
func (fd *netFD) Read(buf []byte) (int, error) {
|
2017-02-10 15:59:38 -07:00
|
|
|
n, err := fd.pfd.Read(buf)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return n, wrapSyscallError("wsarecv", err)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2015-04-13 08:45:00 -06:00
|
|
|
func (fd *netFD) readFrom(buf []byte) (int, syscall.Sockaddr, error) {
|
2017-04-11 21:40:07 -06:00
|
|
|
n, sa, err := fd.pfd.ReadFrom(buf)
|
2017-02-10 15:59:38 -07:00
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return n, sa, wrapSyscallError("wsarecvfrom", err)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2012-01-31 08:36:45 -07:00
|
|
|
func (fd *netFD) Write(buf []byte) (int, error) {
|
2017-02-10 15:59:38 -07:00
|
|
|
n, err := fd.pfd.Write(buf)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return n, wrapSyscallError("wsasend", err)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2016-10-29 01:37:49 -06:00
|
|
|
func (c *conn) writeBuffers(v *Buffers) (int64, error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, syscall.EINVAL
|
|
|
|
}
|
|
|
|
n, err := c.fd.writeBuffers(v)
|
|
|
|
if err != nil {
|
2017-05-18 23:12:49 -06:00
|
|
|
return n, &OpError{Op: "wsasend", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
|
2016-10-29 01:37:49 -06:00
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fd *netFD) writeBuffers(buf *Buffers) (int64, error) {
|
2017-02-10 15:59:38 -07:00
|
|
|
n, err := fd.pfd.Writev((*[][]byte)(buf))
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return n, wrapSyscallError("wsasend", err)
|
2016-10-29 01:37:49 -06:00
|
|
|
}
|
|
|
|
|
2014-04-02 18:06:51 -06:00
|
|
|
func (fd *netFD) writeTo(buf []byte, sa syscall.Sockaddr) (int, error) {
|
2017-02-10 15:59:38 -07:00
|
|
|
n, err := fd.pfd.WriteTo(buf, sa)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return n, wrapSyscallError("wsasendto", err)
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
2017-02-10 15:59:38 -07:00
|
|
|
func (fd *netFD) accept() (*netFD, error) {
|
|
|
|
s, rawsa, rsan, errcall, err := fd.pfd.Accept(func() (syscall.Handle, error) {
|
|
|
|
return sysSocket(fd.family, fd.sotype, 0)
|
|
|
|
})
|
|
|
|
|
2012-01-31 08:36:45 -07:00
|
|
|
if err != nil {
|
2017-02-10 15:59:38 -07:00
|
|
|
if errcall != "" {
|
|
|
|
err = wrapSyscallError(errcall, err)
|
|
|
|
}
|
2015-04-16 23:35:54 -06:00
|
|
|
return nil, err
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Associate our new socket with IOCP.
|
2013-07-21 20:49:57 -06:00
|
|
|
netfd, err := newFD(s, fd.family, fd.sotype, fd.net)
|
|
|
|
if err != nil {
|
2017-02-10 15:59:38 -07:00
|
|
|
poll.CloseFunc(s)
|
2015-04-16 23:35:54 -06:00
|
|
|
return nil, err
|
2010-06-29 21:23:39 -06:00
|
|
|
}
|
2013-08-06 08:42:33 -06:00
|
|
|
if err := netfd.init(); err != nil {
|
|
|
|
fd.Close()
|
|
|
|
return nil, err
|
|
|
|
}
|
2010-06-29 21:23:39 -06:00
|
|
|
|
|
|
|
// Get local and peer addr out of AcceptEx buffer.
|
2011-02-22 20:40:24 -07:00
|
|
|
var lrsa, rrsa *syscall.RawSockaddrAny
|
|
|
|
var llen, rlen int32
|
2013-08-06 04:40:10 -06:00
|
|
|
syscall.GetAcceptExSockaddrs((*byte)(unsafe.Pointer(&rawsa[0])),
|
2017-02-10 15:59:38 -07:00
|
|
|
0, rsan, rsan, &lrsa, &llen, &rrsa, &rlen)
|
2011-02-22 20:40:24 -07:00
|
|
|
lsa, _ := lrsa.Sockaddr()
|
|
|
|
rsa, _ := rrsa.Sockaddr()
|
|
|
|
|
2014-08-04 15:10:46 -06:00
|
|
|
netfd.setAddr(netfd.addrFunc()(lsa), netfd.addrFunc()(rsa))
|
2012-01-31 08:36:45 -07:00
|
|
|
return netfd, nil
|
2011-01-11 21:55:17 -07:00
|
|
|
}
|
|
|
|
|
2011-05-30 02:02:59 -06:00
|
|
|
// Unimplemented functions.
|
2010-11-05 12:02:03 -06:00
|
|
|
|
2012-01-31 08:36:45 -07:00
|
|
|
func (fd *netFD) dup() (*os.File, error) {
|
2010-11-05 12:02:03 -06:00
|
|
|
// TODO: Implement this
|
2015-04-18 01:53:55 -06:00
|
|
|
return nil, syscall.EWINDOWS
|
2010-11-05 12:02:03 -06:00
|
|
|
}
|
2010-12-07 11:40:14 -07:00
|
|
|
|
2014-04-02 18:06:51 -06:00
|
|
|
func (fd *netFD) readMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.Sockaddr, err error) {
|
2015-04-16 08:10:56 -06:00
|
|
|
return 0, 0, 0, nil, syscall.EWINDOWS
|
2010-12-07 11:40:14 -07:00
|
|
|
}
|
|
|
|
|
2014-04-02 18:06:51 -06:00
|
|
|
func (fd *netFD) writeMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oobn int, err error) {
|
2015-04-15 20:26:44 -06:00
|
|
|
return 0, 0, syscall.EWINDOWS
|
2010-12-07 11:40:14 -07:00
|
|
|
}
|