Close closes the socket.
()
| 113 | |
| 114 | // Close closes the socket. |
| 115 | func (s *Socket) Close() error { |
| 116 | // Set the FD in the socket to -1, to ensure that all future calls to |
| 117 | // FD/Release get nothing and Close calls return immediately. |
| 118 | fd := int(s.fd.Swap(-1)) |
| 119 | if fd < 0 { |
| 120 | // Already closed or closing. |
| 121 | return unix.EBADF |
| 122 | } |
| 123 | |
| 124 | // Shutdown the socket to cancel any pending accepts. |
| 125 | s.shutdown(fd) |
| 126 | |
| 127 | if err := s.finish(); err != nil { |
| 128 | return err |
| 129 | } |
| 130 | |
| 131 | return unix.Close(fd) |
| 132 | } |
| 133 | |
| 134 | // Release releases ownership of the socket FD. |
| 135 | // |