1234567891011121314151617181920212223242526272829303132 |
- 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)
-
- 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)
- }
- }
|