NewSocket returns a socket from an existing FD. NewSocket takes ownership of fd.
(fd int)
| 80 | // |
| 81 | // NewSocket takes ownership of fd. |
| 82 | func NewSocket(fd int) (*Socket, error) { |
| 83 | // fd must be non-blocking for non-blocking unix.Accept in |
| 84 | // ServerSocket.Accept. |
| 85 | if err := unix.SetNonblock(fd, true); err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | |
| 89 | efd, err := eventfd.Create() |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | |
| 94 | return &Socket{ |
| 95 | fd: atomicbitops.FromInt32(int32(fd)), |
| 96 | efd: efd, |
| 97 | }, nil |
| 98 | } |
| 99 | |
| 100 | // finish completes use of s.fd by evicting any waiters, closing the gate, and |
| 101 | // closing the event FD. |
searching dependent graphs…