@@ -5,32 +5,42 @@ import (
55 "sync"
66)
77
8- // InmemSocket implements net.Listener using in-memory only connections.
8+ // dummyAddr is used to satisfy net.Addr for the in-mem socket
9+ // it is just stored as a string and returns the string for all calls
10+ type dummyAddr string
11+
12+ // Network returns the addr string, satisfies net.Addr
13+ func (a dummyAddr ) Network () string {
14+ return string (a )
15+ }
16+
17+ // String returns the string form
18+ func (a dummyAddr ) String () string {
19+ return string (a )
20+ }
21+
22+ // InmemSocket implements [net.Listener] using in-memory only connections.
923type InmemSocket struct {
1024 chConn chan net.Conn
1125 chClose chan struct {}
12- addr string
26+ addr dummyAddr
1327 mu sync.Mutex
1428}
1529
16- // dummyAddr is used to satisfy net.Addr for the in-mem socket
17- // it is just stored as a string and returns the string for all calls
18- type dummyAddr string
19-
20- // NewInmemSocket creates an in-memory only net.Listener
21- // The addr argument can be any string, but is used to satisfy the `Addr()` part
22- // of the net.Listener interface
30+ // NewInmemSocket creates an in-memory only [net.Listener]. The addr argument
31+ // can be any string, but is used to satisfy the [net.Listener.Addr] part
32+ // of the [net.Listener] interface
2333func NewInmemSocket (addr string , bufSize int ) * InmemSocket {
2434 return & InmemSocket {
2535 chConn : make (chan net.Conn , bufSize ),
2636 chClose : make (chan struct {}),
27- addr : addr ,
37+ addr : dummyAddr ( addr ) ,
2838 }
2939}
3040
3141// Addr returns the socket's addr string to satisfy net.Listener
3242func (s * InmemSocket ) Addr () net.Addr {
33- return dummyAddr ( s .addr )
43+ return s .addr
3444}
3545
3646// Accept implements the Accept method in the Listener interface; it waits
@@ -69,13 +79,3 @@ func (s *InmemSocket) Dial(network, addr string) (net.Conn, error) {
6979
7080 return clientConn , nil
7181}
72-
73- // Network returns the addr string, satisfies net.Addr
74- func (a dummyAddr ) Network () string {
75- return string (a )
76- }
77-
78- // String returns the string form
79- func (a dummyAddr ) String () string {
80- return string (a )
81- }
0 commit comments