Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lavabit/magma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadar Levison <ladar@lavabit.com>2017-03-28 22:39:08 +0300
committerLadar Levison <ladar@lavabit.com>2017-03-28 22:39:08 +0300
commitfbba305414755b2d971006ad12f827e68df34803 (patch)
tree0d756bb2f187d8437a2a865c0cd63642c78cace8
parente95a4efc0f5906778fc08ae8952fcbe313d5b019 (diff)
Enabled the poll used to accept incoming connections.
-rw-r--r--src/network/listeners.c228
1 files changed, 114 insertions, 114 deletions
diff --git a/src/network/listeners.c b/src/network/listeners.c
index 8d164707..ac210715 100644
--- a/src/network/listeners.c
+++ b/src/network/listeners.c
@@ -6,120 +6,120 @@
*/
#include "magma.h"
-
-void net_accept(server_t *server) {
-
- int connection = 0;
-
- thread_start();
-
- do {
-
- // Keep calling accept until it fails.
- if ((connection = accept(server->network.sockd, NULL, NULL)) != -1) {
- protocol_process(server, connection);
- }
-
- } while(status());
-
- thread_stop();
-
- return;
-}
-
-void net_listen(void) {
-
- server_t *server = NULL;
- pthread_t *threads[MAGMA_SERVER_INSTANCES];
-
- mm_wipe(threads, sizeof(threads));
-
- // Loop through and launch listener threads for all of the server sockets.
- for (uint64_t i = 0; i < MAGMA_SERVER_INSTANCES; i++) {
- if ((server = magma.servers[i]) && server->enabled && server->network.sockd) {
- threads[i] = thread_alloc(net_accept, server);
- }
- }
-
- // Loop through again and wait for the listener threads to exit.
- for (uint64_t i = 0; i < MAGMA_SERVER_INSTANCES; i++) {
- if ((server = magma.servers[i]) && server->enabled && server->network.sockd && threads[i] != NULL) {
- thread_join(*threads[i]);
- mm_free(threads[i]);
- }
- }
-
- return;
-}
-
-bool_t net_init(server_t *server) {
-
- int sd;
- struct sockaddr_in sin4;
- struct sockaddr_in6 sin6;
-
- // Create the socket.
- if ((sd = socket(server->network.ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0)) == -1) {
- log_critical("Error while calling socket.");
- return false;
- }
-
- // Set non-blocking IO.
-// if (!net_set_non_blocking(sd, false)) {
-// log_critical("Error attempting to setup non-blocking IO.");
+//
+//void net_accept(server_t *server) {
+//
+// int connection = 0;
+//
+// thread_start();
+//
+// do {
+//
+// // Keep calling accept until it fails.
+// if ((connection = accept(server->network.sockd, NULL, NULL)) != -1) {
+// protocol_process(server, connection);
+// }
+//
+// } while(status());
+//
+// thread_stop();
+//
+// return;
+//}
+//
+//void net_listen(void) {
+//
+// server_t *server = NULL;
+// pthread_t *threads[MAGMA_SERVER_INSTANCES];
+//
+// mm_wipe(threads, sizeof(threads));
+//
+// // Loop through and launch listener threads for all of the server sockets.
+// for (uint64_t i = 0; i < MAGMA_SERVER_INSTANCES; i++) {
+// if ((server = magma.servers[i]) && server->enabled && server->network.sockd) {
+// threads[i] = thread_alloc(net_accept, server);
+// }
+// }
+//
+// // Loop through again and wait for the listener threads to exit.
+// for (uint64_t i = 0; i < MAGMA_SERVER_INSTANCES; i++) {
+// if ((server = magma.servers[i]) && server->enabled && server->network.sockd && threads[i] != NULL) {
+// thread_join(*threads[i]);
+// mm_free(threads[i]);
+// }
+// }
+//
+// return;
+//}
+//
+//bool_t net_init(server_t *server) {
+//
+// int sd;
+// struct sockaddr_in sin4;
+// struct sockaddr_in6 sin6;
+//
+// // Create the socket.
+// if ((sd = socket(server->network.ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0)) == -1) {
+// log_critical("Error while calling socket.");
// return false;
// }
-
- // Make this a reusable socket.
- if (!net_set_reuseable_address(sd, true)) {
- log_critical("Could not make the socket reusable.");
- return false;
- }
-
- if (!net_set_buffer_length(sd, magma.system.network_buffer, magma.system.network_buffer)) {
- log_critical("Could not configure the socket buffer size.");
- return false;
- }
-
- // Zero out the server socket structure, and set the values.
- if (server->network.ipv6) {
- mm_wipe(&sin6, sizeof(sin6));
- sin6.sin6_family = AF_INET6;
- sin6.sin6_addr = in6addr_any;
- sin6.sin6_port = htons(server->network.port);
-
- // Bind the socket.
- if (bind(sd, (struct sockaddr *)&sin6, sizeof(sin6)) == -1) {
- log_critical("Error while binding to socket. Attempting to use port %u.", server->network.port);
- return false;
- }
- }
- else {
- mm_wipe(&sin4, sizeof(sin4));
- sin4.sin_family = AF_INET;
- sin4.sin_addr.s_addr = INADDR_ANY;
- sin4.sin_port = htons(server->network.port);
-
- // Bind the socket.
- if (bind(sd, (struct sockaddr *)&sin4, sizeof(sin4)) == -1) {
- log_critical("Error while binding to socket. Attempting to use port %u.", server->network.port);
- return false;
- }
- }
-
- // Start listening for incoming connections. We set the queue to our config file listen queue value.
- if (listen(sd, server->network.listen_queue) == -1) {
- log_critical("Error while listening to socket. Attempting to use port %u.", server->network.port);
- return false;
- }
-
- // Store the socket descriptor elsewhere, so it can be shutdown later.
- server->network.sockd = sd;
-
- return true;
-}
-
-
+//
+// // Set non-blocking IO.
+//// if (!net_set_non_blocking(sd, false)) {
+//// log_critical("Error attempting to setup non-blocking IO.");
+//// return false;
+//// }
+//
+// // Make this a reusable socket.
+// if (!net_set_reuseable_address(sd, true)) {
+// log_critical("Could not make the socket reusable.");
+// return false;
+// }
+//
+// if (!net_set_buffer_length(sd, magma.system.network_buffer, magma.system.network_buffer)) {
+// log_critical("Could not configure the socket buffer size.");
+// return false;
+// }
+//
+// // Zero out the server socket structure, and set the values.
+// if (server->network.ipv6) {
+// mm_wipe(&sin6, sizeof(sin6));
+// sin6.sin6_family = AF_INET6;
+// sin6.sin6_addr = in6addr_any;
+// sin6.sin6_port = htons(server->network.port);
+//
+// // Bind the socket.
+// if (bind(sd, (struct sockaddr *)&sin6, sizeof(sin6)) == -1) {
+// log_critical("Error while binding to socket. Attempting to use port %u.", server->network.port);
+// return false;
+// }
+// }
+// else {
+// mm_wipe(&sin4, sizeof(sin4));
+// sin4.sin_family = AF_INET;
+// sin4.sin_addr.s_addr = INADDR_ANY;
+// sin4.sin_port = htons(server->network.port);
+//
+// // Bind the socket.
+// if (bind(sd, (struct sockaddr *)&sin4, sizeof(sin4)) == -1) {
+// log_critical("Error while binding to socket. Attempting to use port %u.", server->network.port);
+// return false;
+// }
+// }
+//
+// // Start listening for incoming connections. We set the queue to our config file listen queue value.
+// if (listen(sd, server->network.listen_queue) == -1) {
+// log_critical("Error while listening to socket. Attempting to use port %u.", server->network.port);
+// return false;
+// }
+//
+// // Store the socket descriptor elsewhere, so it can be shutdown later.
+// server->network.sockd = sd;
+//
+// return true;
+//}
+//
+//
/**
@@ -128,7 +128,7 @@ bool_t net_init(server_t *server) {
* @see protocol_process()
* @return This function returns no value.
*/
-void old_net_listen(void) {
+void net_listen(void) {
server_t *server = NULL;
int ed, ready, connection;
@@ -224,7 +224,7 @@ void old_net_listen(void) {
* @param server a pointer to the server object to be initialized.
* @return true on successful initialization of the server, or false on failure.
*/
-bool_t old_net_init(server_t *server) {
+bool_t net_init(server_t *server) {
int sd;
struct sockaddr_in sin4;