summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.c2
-rw-r--r--src/loop.c2
-rw-r--r--src/multiplex.c1
-rw-r--r--src/packet_cache.c14
-rw-r--r--src/packet_cache.h4
-rw-r--r--src/socket/socket.h4
-rw-r--r--src/socket/socket_linux.c11
-rw-r--r--src/socket/socket_windows.c5
8 files changed, 32 insertions, 11 deletions
diff --git a/src/common.c b/src/common.c
index 7034971..01483f0 100644
--- a/src/common.c
+++ b/src/common.c
@@ -13,6 +13,7 @@
#include "common.h"
+#ifndef NAUNET_ON_WINDOWS
#define RESET "\033[0m"
static inline const char *get_color_for_level(u8 level)
{
@@ -30,6 +31,7 @@ static inline const char *get_color_for_level(u8 level)
default: return "";
}
}
+#endif
s32 al_print_default(void *userdata, u8 level, char *message)
{
diff --git a/src/loop.c b/src/loop.c
index 774feaf..e4c2271 100644
--- a/src/loop.c
+++ b/src/loop.c
@@ -9,7 +9,7 @@ bool nn_event_loop_init(struct nn_event_loop *loop)
// @TODO:
// https://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod @ EVBACKEND_SELECT
//ev_set_timeout_collect_interval(loop->ev, 0.1);
- //ev_set_io_collect_interval(loop->ev, 0.05);
+ //ev_set_io_collect_interval(loop->ev, 0.003);
return true;
}
diff --git a/src/multiplex.c b/src/multiplex.c
index 40d7e75..9744957 100644
--- a/src/multiplex.c
+++ b/src/multiplex.c
@@ -89,6 +89,7 @@ void nn_multiplex_socket_close(struct nn_multiplex_socket *multi)
ev_io_stop(multi->loop->ev, &multi->event);
nn_socket_shutdown(&multi->sock);
nn_socket_close(&multi->sock);
+ nn_socket_cleanup(&multi->sock);
}
static struct nn_multiplex_direct multiplex_direct_global = { 0 };
diff --git a/src/packet_cache.c b/src/packet_cache.c
index bc230ed..2e907b3 100644
--- a/src/packet_cache.c
+++ b/src/packet_cache.c
@@ -10,20 +10,20 @@ void nn_packet_cache_init(struct nn_packet_cache *cache, u32 size)
nn_mutex_init(&cache->mutex);
}
-bool nn_packet_cache_send_packet(struct nn_packet_cache *cache, struct nn_packet *packet)
+bool nn_packet_cache_available(struct nn_packet_cache *cache)
{
nn_mutex_lock(&cache->mutex);
- if (cache->disabled) {
- nn_mutex_unlock(&cache->mutex);
- return false;
- }
+ return !cache->disabled;
+}
+
+void nn_packet_cache_send_packet(struct nn_packet_cache *cache, struct nn_packet *packet)
+{
+ al_assert(!cache->disabled);
al_array_push(cache->cache, packet);
bool flush = !packet || cache->cache.count >= cache->flush;
if (flush && nn_cond_is_waiting(&cache->cond)) {
nn_cond_signal(&cache->cond);
}
- nn_mutex_unlock(&cache->mutex);
- return true;
}
void nn_packet_cache_flush(struct nn_packet_cache *cache)
diff --git a/src/packet_cache.h b/src/packet_cache.h
index c31347d..5d2535c 100644
--- a/src/packet_cache.h
+++ b/src/packet_cache.h
@@ -14,11 +14,11 @@ struct nn_packet_cache {
};
void nn_packet_cache_init(struct nn_packet_cache *cache, u32 size);
-bool nn_packet_cache_send_packet(struct nn_packet_cache *cache, struct nn_packet *packet);
+bool nn_packet_cache_available(struct nn_packet_cache *cache);
+void nn_packet_cache_send_packet(struct nn_packet_cache *cache, struct nn_packet *packet);
void nn_packet_cache_flush(struct nn_packet_cache *cache);
bool nn_packet_cache_wait(struct nn_packet_cache *cache, u32 *count);
struct nn_packet *nn_packet_cache_at(struct nn_packet_cache *cache, u32 index);
-void nn_packet_cache_lock(struct nn_packet_cache *cache);
void nn_packet_cache_unlock(struct nn_packet_cache *cache);
void nn_packet_cache_disable(struct nn_packet_cache *cache);
void nn_packet_cache_enable(struct nn_packet_cache *cache);
diff --git a/src/socket/socket.h b/src/socket/socket.h
index 3872bd4..fde26f4 100644
--- a/src/socket/socket.h
+++ b/src/socket/socket.h
@@ -25,7 +25,7 @@ enum {
};
// @TODO: Guard against EINTR?
-// https://github.com/kovidgoyal/kitty/blob/master/kitty/safe-wrappers.h
+// https://github.com/kovidgoyal/kitty/blob/master/kitty/safe-wrappers.h
struct nn_socket {
u8 type;
@@ -37,6 +37,7 @@ struct nn_socket {
s32 fd;
struct addrinfo *addrinfo;
struct sockaddr_un addr_un;
+ u32 acceptconn;
#endif
};
@@ -84,3 +85,4 @@ bool nn_socket_check_error(ssize_t ret);
void nn_socket_shutdown(struct nn_socket *sock);
void nn_socket_close(struct nn_socket *sock);
+void nn_socket_cleanup(struct nn_socket *sock);
diff --git a/src/socket/socket_linux.c b/src/socket/socket_linux.c
index 6a97556..e6947c3 100644
--- a/src/socket/socket_linux.c
+++ b/src/socket/socket_linux.c
@@ -185,6 +185,10 @@ bool nn_socket_listen(struct nn_socket *sock)
return false;
}
+ socklen_t optlen = sizeof(sock->acceptconn);
+ getsockopt(sock->fd, SOL_SOCKET, SO_ACCEPTCONN, &sock->acceptconn, &optlen);
+ al_assert(sock->acceptconn);
+
log_debug("Listening.");
return true;
@@ -305,3 +309,10 @@ void nn_socket_close(struct nn_socket *sock)
sock->addrinfo = NULL;
}
}
+
+void nn_socket_cleanup(struct nn_socket *sock)
+{
+ if (sock->type == NNWT_SOCKET_UNIX && sock->acceptconn) {
+ unlink(sock->addr_un.sun_path);
+ }
+}
diff --git a/src/socket/socket_windows.c b/src/socket/socket_windows.c
index 3cf316f..9baa312 100644
--- a/src/socket/socket_windows.c
+++ b/src/socket/socket_windows.c
@@ -174,3 +174,8 @@ void nn_socket_close(struct nn_socket *sock)
// Based on these docs, I assume calling closesocket() is not necessary.
//closesocket(sock->fd);
}
+
+void nn_socket_cleanup(struct nn_socket *sock)
+{
+ (void)sock;
+}