@@ -59,7 +59,7 @@ var listeners struct {
5959type listener struct {
6060 s * server
6161 ln net.Listener
62- fd int // go side fd of socketpair sent to C
62+ fd C. SOCKET // go side fd of socketpair sent to C
6363}
6464
6565// conns tracks all the pipe(2)s allocated via tsnet_dial.
@@ -172,6 +172,7 @@ func TsnetErrmsg(sd C.int, buf *C.char, buflen C.size_t) C.int {
172172
173173//export TsnetListen
174174func TsnetListen (sd C.int , network , addr * C.char , listenerOut * C.int ) C.int {
175+ fmt .Println ("start listening" )
175176 s , err := getServer (sd )
176177 if err != nil {
177178 return s .recErr (err )
@@ -187,8 +188,7 @@ func TsnetListen(sd C.int, network, addr *C.char, listenerOut *C.int) C.int {
187188 // feed an fd for the connection through the listener. This lets C use
188189 // epoll on the tailscale_listener to know if it should call
189190 // tailscale_accept, which avoids a blocking call on the far side.
190- var fds [2 ]int
191- fds , err = platform .GetSocketPair ()
191+ fds , err := platform .GetSocketPair ()
192192
193193 if err != nil {
194194 return s .recErr (err )
@@ -200,9 +200,9 @@ func TsnetListen(sd C.int, network, addr *C.char, listenerOut *C.int) C.int {
200200 if listeners .m == nil {
201201 listeners .m = map [C.int ]* listener {}
202202 }
203- listeners .m [fdC ] = & listener {s : s , ln : ln , fd : sp }
203+ listeners .m [fdC ] = & listener {s : s , ln : ln , fd : C . SOCKET ( sp ) }
204204 listeners .mu .Unlock ()
205-
205+ fmt . Println ( "listener setup" )
206206 cleanup := func () {
207207 // If fdC is closed on the C side, then we end up calling
208208 // into cleanup twice. Be careful to avoid syscall.Close
@@ -252,7 +252,7 @@ func TsnetListen(sd C.int, network, addr *C.char, listenerOut *C.int) C.int {
252252 netConn .Close ()
253253 // fallthrough to close connFd, then continue Accept()ing
254254 }
255- platform .CloseSocket (int ( connFd ) ) // now owned by recvmsg
255+ // platform.CloseSocket(connFd) // now owned by recvmsg
256256 }
257257 }()
258258
@@ -263,9 +263,8 @@ func TsnetListen(sd C.int, network, addr *C.char, listenerOut *C.int) C.int {
263263func newConn (s * server , netConn net.Conn , connOut * C.int ) error {
264264
265265 // TODO https://github.com/ncm/selectable-socketpair/blob/master/socketpair.c
266- var fds [2 ]int
267266 var err error
268- fds , err = platform .GetSocketPair ()
267+ fds , err : = platform .GetSocketPair ()
269268 if err != nil {
270269 return err
271270 }
@@ -300,7 +299,7 @@ func newConn(s *server, netConn net.Conn, connOut *C.int) error {
300299 defer connCleanup ()
301300 var b [1 << 16 ]byte
302301 io .CopyBuffer (r , netConn , b [:])
303- platform .Shutdown (int (r .Fd ()), syscall .SHUT_WR )
302+ platform .Shutdown (syscall . Handle (r .Fd ()), syscall .SHUT_WR )
304303 if cr , ok := netConn .(interface { CloseRead () error }); ok {
305304 cr .CloseRead ()
306305 }
@@ -309,7 +308,7 @@ func newConn(s *server, netConn net.Conn, connOut *C.int) error {
309308 defer connCleanup ()
310309 var b [1 << 16 ]byte
311310 io .CopyBuffer (netConn , r , b [:])
312- platform .Shutdown (int (r .Fd ()), syscall .SHUT_RD )
311+ platform .Shutdown (syscall . Handle (r .Fd ()), syscall .SHUT_RD )
313312 if cw , ok := netConn .(interface { CloseWrite () error }); ok {
314313 cw .CloseWrite ()
315314 }
0 commit comments