--- /dev/null
+/* FLL - Level 0
+ * Project: Socket
+ * Version: 0.4.2
+ * Licenses: lgplv2.1
+ * Programmers: Kevin Day
+ * Documentation:
+ *
+ * Provide means to connect to and use sockets.
+ */
+#ifndef _F_socket_h
+#define _F_socket_h
+
+// libc includes
+#include <stdlib.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/socket.h>
+
+// fll includes
+#include <level_0/types.h>
+#include <level_0/errors.h>
+#include <level_0/strings.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#ifndef _di_f_socket_types_
+ #define f_socket_address struct sockaddr_un
+ #define f_socket_id f_s_int
+ #define f_socket_close_id f_u_short
+
+ enum {
+ f_socket_close_fast, // As in close();
+ f_socket_close_read, // As in shutdown(, SHUT_RD);
+ f_socket_close_write, // As in shutdown(, SHUT_WR);
+ f_socket_close_read_write, // As in shutdown(, SHUT_RDWR);
+ };
+#endif // _di_f_socket_types_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _F_socket_h
--- /dev/null
+/* FLL - Level 1
+ * Project: Socket
+ * Version: 0.4.2
+ * Licenses: lgplv2.1
+ * Programmers: Kevin Day
+ * Documentation:
+ *
+ * Provide means to connect to and use sockets.
+ */
+#include <level_0/socket.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#ifndef _di_fl_socket_file_bind_
+ f_return_status fl_socket_file_bind(const f_string socket_path, f_socket_id *socket_id, f_socket_address *socket_address) {
+ memset(&socket_address, 0, structure_socket_length);
+ socket_address.sun_family = SOCKET_FAMILY;
+ strncpy(socket_address.sun_path, socket_path, sizeof(socket_address.sun_path) - 1);
+
+ if (bind(*socket_id, (f_socket_address *) socket_address, structure_socket_length) < 0) {
+ if (errno == EACCES) {
+ return f_access_denied;
+ }
+ else if (errno == EADDRINUSE) {
+ return f_busy_address;
+ }
+ else if (errno == EADDRNOTAVAIL) {
+ return f_unavailable_address;
+ }
+ else if (errno == EINVAL) {
+ return f_busy_socket;
+ }
+ else if (errno == ENOTSOCK) {
+ return f_invalid_socket;
+ }
+ else if (errno == ENAMETOOLONG) {
+ return f_string_too_large;
+ }
+ else if (errno == ENOENT) {
+ return f_file_not_found;
+ }
+ else if (errno == EFAULT) {
+ return f_invalid_address;
+ }
+ else if (errno == ENOTDIR) {
+ return f_directory_not_found;
+ }
+ else if (errno == ENOMEM) {
+ return f_out_of_memory;
+ }
+ else if (errno == ELOOP) {
+ return f_loop;
+ }
+
+ return f_failure;
+ }
+
+ return f_none;
+ }
+#endif // _di_fl_socket_file_bind_
+
+#ifndef _di_fl_socket_listen_
+ f_return_status fl_socket_listen(const f_socket_id socket_id, const f_u_int socket_backlog) {
+ if (listen(socket_id, socket_backlog) < 0) {
+ if (errno == EADDRINUSE) {
+ return f_busy;
+ }
+ else if (errno == EBADF) {
+ return f_file_descriptor_error;
+ }
+ else if (errno == ENOTSOCK) {
+ return f_invalid_socket;
+ }
+ else if (errno == EOPNOTSUPP) {
+ return f_unsupported;
+ }
+
+ return f_failure;
+ }
+
+ return f_none;
+ }
+#endif // _di_fl_socket_listen_
+
+#ifndef _di_fl_socket_close_client_
+ // terminate a socket connection.
+ f_return_status fl_socket_close_client(const f_socket_id socket_id_client, const f_socket_close_id close_action = f_socket_close_fast) {
+ f_u_int error_code = 0;
+
+ if (close_action == f_socket_close_fast) {
+ if (close(socket_id_client) < 0) {
+ error_code = errno;
+ }
+ }
+ else {
+ if (close_action == f_socket_close_read || close_action == f_socket_close_write || close_action == f_socket_close_read_write) {
+ if (shutdown(socket_id_client, close_action) < 0) {
+ error_code = errno;
+ }
+ }
+ else {
+ // socket close id is unsupported.
+ return f_unsupported;
+ }
+ }
+
+ if (error_code > 0) {
+ if (result == EBADF) {
+ return f_file_descriptor_error;
+ }
+ else if (result == EINVAL) {
+ return f_invalid_value;
+ }
+ else if (result == ENOTCONN) {
+ return f_not_connected;
+ }
+ else if (result == ENOTSOCK) {
+ return f_invalid_socket;
+ }
+ else if (result == EINTR) {
+ return f_interrupted;
+ }
+ else if (result == EBADF) {
+ return f_input_output_error;
+ }
+
+ return f_failure;
+ }
+
+ return f_none;
+ }
+#endif // _di_fl_socket_close_client_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
--- /dev/null
+/* FLL - Level 1
+ * Project: Socket
+ * Version: 0.4.2
+ * Licenses: lgplv2.1
+ * Programmers: Kevin Day
+ * Documentation:
+ *
+ * Provide means to connect to and use sockets.
+ */
+#ifndef _F_socket_h
+#define _F_socket_h
+
+// libc includes
+#include <stdlib.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/socket.h>
+
+// fll includes
+#include <level_0/types.h>
+#include <level_0/errors.h>
+#include <level_0/strings.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#ifndef _di_fl_socket_file_bind_
+ // bind a socket.
+ f_extern f_return_status fl_socket_file_bind(const f_string socket_path, f_socket_id *socket_id, f_socket_address *socket_address);
+#endif // _di_fl_socket_file_bind_
+
+#ifndef _di_fl_socket_listen_
+ // terminate a socket connection
+ // suggested socket_backlog default setting = 8.
+ f_extern f_return_status fl_socket_listen(const f_socket_id socket_id, const f_u_int socket_backlog);
+#endif // _di_fl_socket_listen_
+
+#ifndef _di_fl_socket_close_client_
+ // terminate a socket connection
+ // suggested default close_action = f_socket_close_fast.
+ f_extern f_return_status fl_socket_close_client(const f_socket_id socket_id_client, const f_socket_close_id close_action);
+#endif // _di_fl_socket_close_client_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _F_socket_h