Only call strncpy() if socket->name is defined.
Only set socket->id to -1 for f_socket_close_fast_e.
When received EINTR, do set socket->id to -1 for f_socket_close_fast_e.
Be consistent and make length parameter optional for the socket read and write functions.
address->sun_family = f_socket_domain_file_d;
- strncpy(address->sun_path, socket->name, sizeof(address->sun_path) - 1);
+ if (socket->name) {
+ strncpy(address->sun_path, socket->name, sizeof(address->sun_path) - 1);
+ }
+ else {
+ address->sun_path[0] = 0;
+ }
}
if (bind(socket->id, socket->address, sizeof(struct sockaddr_un)) == -1) {
if (result == -1) {
// According to man pages, retrying close() after another close on error is invalid on Linux because Linux releases the descriptor before stages that cause failures.
- if (errno != EBADF && errno != EINTR) {
+ if (action == f_socket_close_fast_e && errno != EBADF) {
socket->id = -1;
}
return F_status_set_error(F_failure);
}
- *length = (size_t) result;
+ if (length) {
+ *length = (size_t) result;
+ }
return F_none;
}
if (errno == EPIPE) return F_status_set_error(F_pipe);
if (errno == ETIMEDOUT) return F_status_set_error(F_time_out);
-
return F_status_set_error(F_failure);
}
return F_status_set_error(F_failure);
}
- *length = (size_t) result;
+ if (length) {
+ *length = (size_t) result;
+ }
return F_none;
}
/**
* Create a new socket.
*
- * @param socket_structure
+ * @param socket
* The socket structure.
* The socket.address may point to any valid structure, like "struct sockaddr", "struct sockaddr_un", or "struct sockaddr_in".
* The socket.domain must be assigned the desired domain.
* The socket.protocol must be assigned the desired protocol.
* The socket.id will be updated with a file descriptor representing the created socket.
*
- * This is named "socket_structure" rather than "socket" due to a conflict with the function "socket()".
- *
* @return
* F_none on success.
*
* @see socket()
*/
#ifndef _di_f_socket_create_
- extern f_status_t f_socket_create(f_socket_t * const socket_structure);
+ extern f_status_t f_socket_create(f_socket_t * const socket);
#endif // _di_f_socket_create_
/**
* @param header
* The message header.
* @param length
+ * (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length read.
* Data may be lost if the amount of data read is larger than given buffer length.
*
* @param header
* The message header.
* @param length
+ * (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length send.
* Data may be lost if the amount of data send is larger than given buffer length.
*
* domain: The socket domain (protocol family).
* flag: Flags used for opening the file.
* id: File descriptor, with a value of -1 represents a closed file.
- * name: The name of the socket, if a name is given (for UNIX sockets this represents the path).
+ * name: The name of the socket, if a name is given (for UNIX sockets this represents the path) (Must be a NULL terminated string).
* protocol: The socket protocol.
* size_read: The default number of 1-byte characters to read at a time and is often used for the read buffer size.
* size_write: The default number of 1-byte characters to read at a time and is often used for the write buffer size.