}
/**
- * Closes a socket. Should not be used on non-socket
- * file descriptors or handles.
+ * Closes a socket and invalidates it. Should not be used on non-socket file
+ * descriptors or handles.
+ *
+ * If an error is detected, this function returns #FALSE and sets the error, but
+ * the socket is still closed and invalidated. Callers can use the error in a
+ * diagnostic message, but should not retry closing the socket.
*
* @param fd the socket
* @param error return location for an error
_dbus_close_socket (DBusSocket *fd,
DBusError *error)
{
+ dbus_bool_t rv;
+
_dbus_assert (fd != NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- return _dbus_close (fd->fd, error);
+ rv = _dbus_close (fd->fd, error);
+ _dbus_socket_invalidate (fd);
+
+ return rv;
}
/**
/**
- * Closes a file descriptor.
+ * Closes a socket and invalidates it.
*
* @param fd the file descriptor
* @param error error object
dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not close socket: socket=%Iu, , %s",
fd->sock, _dbus_strerror_from_errno ());
+ _dbus_socket_invalidate (fd);
return FALSE;
}
_dbus_verbose ("socket=%Iu, \n", fd->sock);
+ _dbus_socket_invalidate (fd);
return TRUE;
}