package door import ( "net" "os" ) var fdmap map[uintptr] *os.File func init() { fdmap = make(map[uintptr] *os.File) } func socket_to_fd(socket net.Conn) int { client_conn := socket.(*net.TCPConn) // This creates a duplicate, but once closed -- the fd gets reused! client_file, _ := client_conn.File() fdmap[client_file.Fd()] = client_file return int(client_file.Fd()) } func close_fd(fd int) { var fd_uintptr uintptr = uintptr(fd) file, ok := fdmap[fd_uintptr] if ok { file.Close() delete(fdmap, fd_uintptr) } }