go/src/internal/syscall/unix/socket.go
Mikio Hara 6f7961da28 net, internal/syscall/unix: add SocketConn, SocketPacketConn
FileConn and FilePacketConn APIs accept user-configured socket
descriptors to make them work together with runtime-integrated network
poller, but there's a limitation. The APIs reject protocol sockets that
are not supported by standard library. It's very hard for the net,
syscall packages to look after all platform, feature-specific sockets.

This change allows various platform, feature-specific socket descriptors
to use runtime-integrated network poller by using SocketConn,
SocketPacketConn APIs that bridge between the net, syscall packages and
platforms.

New exposed APIs:
pkg net, func SocketConn(*os.File, SocketAddr) (Conn, error)
pkg net, func SocketPacketConn(*os.File, SocketAddr) (PacketConn, error)
pkg net, type SocketAddr interface { Addr, Raw }
pkg net, type SocketAddr interface, Addr([]uint8) Addr
pkg net, type SocketAddr interface, Raw(Addr) []uint8

Fixes #10565.

Change-Id: Iec57499b3d84bb5cb0bcf3f664330c535eec11e3
Reviewed-on: https://go-review.googlesource.com/9275
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-13 01:04:23 +00:00

39 lines
1.3 KiB
Go

// Copyright 2015 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.
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package unix
// Getsockname copies the binary encoding of the current address for s
// into addr.
func Getsockname(s int, addr []byte) error {
return getsockname(s, addr)
}
// Getpeername copies the binary encoding of the peer address for s
// into addr.
func Getpeername(s int, addr []byte) error {
return getpeername(s, addr)
}
var emptyPayload uintptr
// Recvfrom receives a message from s, copying the message into b.
// The socket address addr must be large enough for storing the source
// address of the message.
// Flags must be operation control flags or 0.
// It retunrs the number of bytes copied into b.
func Recvfrom(s int, b []byte, flags int, addr []byte) (int, error) {
return recvfrom(s, b, flags, addr)
}
// Sendto sends a message to the socket address addr, copying the
// message from b.
// The socket address addr must be suitable for s.
// Flags must be operation control flags or 0.
// It retunrs the number of bytes copied from b.
func Sendto(s int, b []byte, flags int, addr []byte) (int, error) {
return sendto(s, b, flags, addr)
}