Skip to content

Commit 8382db0

Browse files
don't use type aliases since we are not mirroring the net package
Signed-off-by: Achille Roussel <[email protected]>
1 parent 87af203 commit 8382db0

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

wasip1/dial_wasip1.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ func init() {
1616
}
1717
}
1818

19-
// Conn is a generic stream-oriented network connection.
20-
type Conn = net.Conn
21-
2219
// Dial connects to the address on the named network.
23-
func Dial(network, address string) (Conn, error) {
20+
func Dial(network, address string) (net.Conn, error) {
2421
addr, err := lookupAddr("dial", network, address)
2522
if err != nil {
2623
return nil, err
@@ -29,12 +26,32 @@ func Dial(network, address string) (Conn, error) {
2926
}
3027

3128
// DialContext is a variant of Dial that accepts a context.
32-
func DialContext(ctx context.Context, network, address string) (Conn, error) {
33-
_ = ctx // TODO
34-
return Dial(network, address)
29+
func DialContext(ctx context.Context, network, address string) (net.Conn, error) {
30+
select {
31+
case <-ctx.Done():
32+
return nil, &net.OpError{
33+
Op: "dial",
34+
Net: network,
35+
Addr: &networkAddress{
36+
network: network,
37+
address: address,
38+
},
39+
Err: context.Cause(ctx),
40+
}
41+
default:
42+
return Dial(network, address)
43+
}
3544
}
3645

37-
func dialAddr(addr net.Addr) (Conn, error) {
46+
type networkAddress struct {
47+
network string
48+
address string
49+
}
50+
51+
func (na *networkAddress) Network() string { return na.address }
52+
func (na *networkAddress) String() string { return na.address }
53+
54+
func dialAddr(addr net.Addr) (net.Conn, error) {
3855
proto := family(addr)
3956
sotype := socketType(addr)
4057

wasip1/listen_wasip1.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ import (
88
"github.com/stealthrocket/net/syscall"
99
)
1010

11-
// A Listener is a generic network listener for stream-oriented protocols.
12-
type Listener = net.Listener
13-
1411
// Listen announces on the local network address.
15-
func Listen(network, address string) (Listener, error) {
12+
func Listen(network, address string) (net.Listener, error) {
1613
addr, err := lookupAddr("listen", network, address)
1714
if err != nil {
1815
return nil, err
1916
}
2017
return listenAddr(addr)
2118
}
2219

23-
func listenAddr(addr net.Addr) (Listener, error) {
20+
func listenAddr(addr net.Addr) (net.Listener, error) {
2421
fd, err := syscall.Socket(family(addr), socketType(addr), 0)
2522
if err != nil {
2623
return nil, fmt.Errorf("Socket: %w", err)
@@ -57,7 +54,7 @@ func listenAddr(addr net.Addr) (Listener, error) {
5754
}
5855

5956
type listener struct {
60-
Listener
57+
net.Listener
6158
addr net.Addr
6259
}
6360

0 commit comments

Comments
 (0)