Skip to content

Commit

Permalink
Better unsafe type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Mar 27, 2018
1 parent e8588a8 commit 96ff530
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,16 @@ func newTCPConn(fd *netFD) *net.TCPConn {
fd.decref()
}

conn := &net.TCPConn{}
buf1 := (*[8]byte)(unsafe.Pointer(conn))
buf2 := (*[8]byte)(unsafe.Pointer(dummyConn))
conn := (*net.TCPConn)(unsafe.Pointer(dummyConn))

copy(buf1[:], buf2[:])
return conn
}

func newTCPListener(fd *netFD, returnWrapper bool) net.Listener {
dummyListener := &TCPListener{}
dummyListener.fd = fd

listener := &net.TCPListener{}
buf1 := (*[8]byte)(unsafe.Pointer(listener))
buf2 := (*[8]byte)(unsafe.Pointer(dummyListener))

copy(buf1[:], buf2[:])
listener := (*net.TCPListener)(unsafe.Pointer(dummyListener))

if returnWrapper {
return &TFOListener{listener, fd}
Expand Down

0 comments on commit 96ff530

Please sign in to comment.