/* The above call will print a PERROR on error. */
DBG("Error when sending data to consumer on sock %d", fd);
/*
- * At this point, the socket is not usable anymore thus flagging it
- * invalid and closing it.
+ * At this point, the socket is not usable anymore thus closing it and
+ * setting the file descriptor to -1 so it is not reused.
*/
/* This call will PERROR on error. */
/* The above call will print a PERROR on error. */
DBG("Error when receiving data from the consumer socket %d", fd);
/*
- * At this point, the socket is not usable anymore thus flagging it
- * invalid and closing it.
+ * At this point, the socket is not usable anymore thus closing it and
+ * setting the file descriptor to -1 so it is not reused.
*/
/* This call will PERROR on error. */
char err_unix_sock_path[PATH_MAX];
char cmd_unix_sock_path[PATH_MAX];
- /* communication lock */
+ /*
+ * This lock has two purposes. It protects any change to the consumer
+ * socket and make sure only one thread uses this object for read/write
+ * operations.
+ */
pthread_mutex_t lock;
};
lttcomm_connect_unix_sock(consumer_data->cmd_unix_sock_path);
consumer_data->metadata_fd =
lttcomm_connect_unix_sock(consumer_data->cmd_unix_sock_path);
- if (consumer_data->cmd_sock < 0 || consumer_data->metadata_fd < 0) {
+ if (consumer_data->cmd_sock < 0
+ || consumer_data->metadata_fd < 0) {
PERROR("consumer connect cmd socket");
/* On error, signal condition and quit. */
signal_consumer_condition(consumer_data, -1);
error:
/*
* We lock here because we are about to close the sockets and some other
- * thread might be using them so wait before we are exclusive which will
- * abort all other consumer command by other threads.
+ * thread might be using them so get exclusive access which will abort all
+ * other consumer command by other threads.
*/
pthread_mutex_lock(&consumer_data->lock);
unlink(consumer_data->cmd_unix_sock_path);
consumer_data->pid = 0;
pthread_mutex_unlock(&consumer_data->lock);
+
/* Cleanup metadata socket mutex. */
pthread_mutex_destroy(consumer_data->metadata_sock.lock);
free(consumer_data->metadata_sock.lock);