mirror of
https://github.com/tinygo-org/net.git
synced 2026-08-08 05:33:39 +00:00
correct netdever Accept() prototype
According to man page accept(2), accept returns new client sockfd and remote peer ip:port. This patch corrects the Accept() prototype in the netdever interface to not take in an ip:port arg, but rather return an ip:port for remote peer.
This commit is contained in:
@@ -95,7 +95,7 @@ type netdever interface {
|
||||
Bind(sockfd int, ip netip.AddrPort) error
|
||||
Connect(sockfd int, host string, ip netip.AddrPort) error
|
||||
Listen(sockfd int, backlog int) error
|
||||
Accept(sockfd int, ip netip.AddrPort) (int, error)
|
||||
Accept(sockfd int) (int, netip.AddrPort, error)
|
||||
|
||||
// # Flags argument on Send and Recv
|
||||
//
|
||||
|
||||
+14
-3
@@ -119,6 +119,17 @@ func ResolveTCPAddr(network, address string) (*TCPAddr, error) {
|
||||
return &TCPAddr{IP: ip.AsSlice(), Port: port}, nil
|
||||
}
|
||||
|
||||
// TCPAddrFromAddrPort returns addr as a TCPAddr. If addr.IsValid() is false,
|
||||
// then the returned TCPAddr will contain a nil IP field, indicating an
|
||||
// address family-agnostic unspecified address.
|
||||
func TCPAddrFromAddrPort(addr netip.AddrPort) *TCPAddr {
|
||||
return &TCPAddr{
|
||||
IP: addr.Addr().AsSlice(),
|
||||
Zone: addr.Addr().Zone(),
|
||||
Port: int(addr.Port()),
|
||||
}
|
||||
}
|
||||
|
||||
// TCPConn is an implementation of the Conn interface for TCP network
|
||||
// connections.
|
||||
type TCPConn struct {
|
||||
@@ -277,7 +288,7 @@ type listener struct {
|
||||
}
|
||||
|
||||
func (l *listener) Accept() (Conn, error) {
|
||||
fd, err := netdev.Accept(l.fd, netip.AddrPort{})
|
||||
fd, raddr, err := netdev.Accept(l.fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -286,6 +297,7 @@ func (l *listener) Accept() (Conn, error) {
|
||||
fd: fd,
|
||||
net: "tcp",
|
||||
laddr: l.laddr,
|
||||
raddr: TCPAddrFromAddrPort(raddr),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -303,8 +315,7 @@ func listenTCP(laddr *TCPAddr) (Listener, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lip, _ := netip.AddrFromSlice(laddr.IP)
|
||||
laddrport := netip.AddrPortFrom(lip, uint16(laddr.Port))
|
||||
laddrport := laddr.AddrPort()
|
||||
err = netdev.Bind(fd, laddrport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user