summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--meson.build16
-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
-rw-r--r--subprojects/libalabaster.wrap4
-rw-r--r--subprojects/libcurl.wrap4
-rw-r--r--subprojects/zlib.wrap6
-rw-r--r--tests/loop_sleep.c2
-rw-r--r--tests/timer_loop.c6
15 files changed, 60 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore
index ff9bd9a..796babe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,8 @@ subprojects/c89atomic.wrap
subprojects/jansson-*/
subprojects/jsmn-*/
subprojects/libalabaster
-subprojects/libalabaster/
+subprojects/libalabaster-*/
subprojects/libcurl-*/
subprojects/libev-*/
subprojects/packagecache/
+subprojects/zlib-*/
diff --git a/meson.build b/meson.build
index 067fb57..14d2245 100644
--- a/meson.build
+++ b/meson.build
@@ -50,8 +50,12 @@ if get_option('event-loop').enabled()
naunet_has_curl = false
if get_option('curl').enabled()
- libcurl = dependency('libcurl', required: false, allow_fallback: false)
- if not libcurl.found()
+ libcurl_found = false
+ if 'curl' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback'
+ libcurl = dependency('libcurl', required: false, allow_fallback: false)
+ libcurl_found = libcurl.found()
+ endif
+ if not libcurl_found
curl_opts = cmake.subproject_options()
reltype = is_minsize ? 'MinSizeRel' : 'Release'
curl_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype })
@@ -97,8 +101,12 @@ if get_option('json').enabled()
#jsmn = subproject('jsmn').get_variable('jsmn')
#naunet_deps += [jsmn]
#naunet_args += ['-DNAUNET_HAS_JSON']
- jansson = dependency('jansson', required: false, allow_fallback: false)
- if not jansson.found()
+ jansson_found = false
+ if 'jansson' not in get_option('force_fallback_for') and get_option('wrap_mode') != 'forcefallback'
+ jansson = dependency('jansson', required: false, allow_fallback: false)
+ jansson_found = jansson.found()
+ endif
+ if not jansson_found
jansson_opts = cmake.subproject_options()
reltype = is_minsize ? 'MinSizeRel' : 'Release'
jansson_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype })
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;
+}
diff --git a/subprojects/libalabaster.wrap b/subprojects/libalabaster.wrap
index c992439..3f7a977 100644
--- a/subprojects/libalabaster.wrap
+++ b/subprojects/libalabaster.wrap
@@ -1,5 +1,5 @@
[wrap-git]
-directory = libalabaster-492f4a3
+directory = libalabaster-dd7a1d1
url = https://git.akon.city/libalabaster.git
-revision = 492f4a38f7b7f32727ab678f333eff840d968d74
+revision = dd7a1d1afb8b3e93ab1005abdc21edb6efca840a
depth = 1
diff --git a/subprojects/libcurl.wrap b/subprojects/libcurl.wrap
index 211ecd7..d1bf82a 100644
--- a/subprojects/libcurl.wrap
+++ b/subprojects/libcurl.wrap
@@ -1,6 +1,6 @@
[wrap-git]
-directory = libcurl-8.15.0
+directory = libcurl-8.17.0
url = https://github.com/curl/curl.git
-revision = curl-8_15_0
+revision = curl-8_17_0
depth = 1
method = cmake
diff --git a/subprojects/zlib.wrap b/subprojects/zlib.wrap
new file mode 100644
index 0000000..4e3b24b
--- /dev/null
+++ b/subprojects/zlib.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+directory = zlib-1.3.1
+url = https://github.com/madler/zlib.git
+revision = v1.3.1
+depth = 1
+method = cmake
diff --git a/tests/loop_sleep.c b/tests/loop_sleep.c
index 03deb53..3576988 100644
--- a/tests/loop_sleep.c
+++ b/tests/loop_sleep.c
@@ -3,7 +3,6 @@
#include <nnwt/timer.h>
static struct nn_event_loop loop;
-static struct nn_timer timer;
static void timer_callback2(void *userdata, struct nn_timer *timer)
{
@@ -34,6 +33,7 @@ s32 main(void)
nn_event_loop_init(&loop);
+ struct nn_timer timer;
nn_timer_init(&timer, &loop, timer_callback, NULL);
nn_timer_set_repeat(&timer, NNWT_TS_FROM_USEC(1000000));
nn_timer_again(&timer);
diff --git a/tests/timer_loop.c b/tests/timer_loop.c
index a90f7c0..1df6863 100644
--- a/tests/timer_loop.c
+++ b/tests/timer_loop.c
@@ -5,9 +5,6 @@
#define DELAY 100000
#define REPEAT 21
-static struct nn_event_loop loop;
-static struct nn_timer timer;
-
static f64 start;
static u32 iter = 0u;
@@ -27,6 +24,9 @@ s32 main(void)
{
if (!nn_common_init(NULL)) return EXIT_FAILURE;
+ struct nn_event_loop loop;
+ struct nn_timer timer;
+
nn_event_loop_init(&loop);
start = nn_get_tick();