mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
parent
5ed37e5438
commit
c7f63737eb
|
@ -33,8 +33,6 @@ addons:
|
||||||
packages:
|
packages:
|
||||||
- check
|
- check
|
||||||
- libcv-dev # For av_test.
|
- libcv-dev # For av_test.
|
||||||
- libev-dev # For tox_loop.
|
|
||||||
- libevent-dev # For tox_loop.
|
|
||||||
- libhighgui-dev # For av_test.
|
- libhighgui-dev # For av_test.
|
||||||
- libopencv-contrib-dev # For av_test.
|
- libopencv-contrib-dev # For av_test.
|
||||||
- libsndfile1-dev # For av_test.
|
- libsndfile1-dev # For av_test.
|
||||||
|
|
|
@ -183,12 +183,6 @@ if (BUILD_TOXAV)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LIBEV_FOUND)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LIBEV")
|
|
||||||
elseif(LIBEVENT_FOUND)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LIBEVENT")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# :: Tox Core Library
|
# :: Tox Core Library
|
||||||
|
@ -240,18 +234,6 @@ if(RT_LIBRARIES)
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt")
|
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LIBEV_FOUND)
|
|
||||||
target_link_modules(toxnetwork ${LIBEV_LIBRARIES})
|
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lev")
|
|
||||||
elseif(LIBEVENT_FOUND)
|
|
||||||
target_link_modules(toxnetwork ${LIBEVENT_LIBRARIES})
|
|
||||||
if(NOT WIN32)
|
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-levent -levent_pthreads")
|
|
||||||
else()
|
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-levent")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_modules(toxnetwork ws2_32 iphlpapi)
|
target_link_modules(toxnetwork ws2_32 iphlpapi)
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
|
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
|
||||||
|
@ -443,7 +425,7 @@ auto_test(resource_leak)
|
||||||
auto_test(save_friend)
|
auto_test(save_friend)
|
||||||
auto_test(skeleton)
|
auto_test(skeleton)
|
||||||
auto_test(tox)
|
auto_test(tox)
|
||||||
auto_test(tox_loop)
|
auto_test(tox_loop_test)
|
||||||
auto_test(tox_many)
|
auto_test(tox_many)
|
||||||
auto_test(tox_many_tcp)
|
auto_test(tox_many_tcp)
|
||||||
auto_test(tox_one)
|
auto_test(tox_one)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
if BUILD_TESTS
|
if BUILD_TESTS
|
||||||
|
|
||||||
TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_loop_test tox_test dht_autotest tox_strncasecmp_test
|
TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest tox_strncasecmp_test
|
||||||
check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_loop_test tox_test dht_autotest tox_strncasecmp_test
|
check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest tox_strncasecmp_test
|
||||||
|
|
||||||
AUTOTEST_CFLAGS = \
|
AUTOTEST_CFLAGS = \
|
||||||
$(LIBSODIUM_CFLAGS) \
|
$(LIBSODIUM_CFLAGS) \
|
||||||
|
@ -61,13 +61,6 @@ TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
||||||
TCP_test_LDADD = $(AUTOTEST_LDADD)
|
TCP_test_LDADD = $(AUTOTEST_LDADD)
|
||||||
|
|
||||||
|
|
||||||
tox_loop_test_SOURCES = ../auto_tests/tox_loop_test.c
|
|
||||||
|
|
||||||
tox_loop_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
|
||||||
|
|
||||||
tox_loop_test_LDADD = $(AUTOTEST_LDADD)
|
|
||||||
|
|
||||||
|
|
||||||
tox_test_SOURCES = ../auto_tests/tox_test.c
|
tox_test_SOURCES = ../auto_tests/tox_test.c
|
||||||
|
|
||||||
tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include <check.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdlib.h>
|
#include "helpers.h"
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
|
|
||||||
#include "helpers.h"
|
#include <check.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define TCP_RELAY_PORT 33448
|
#define TCP_RELAY_PORT 33448
|
||||||
/* The Travis-CI container responds poorly to ::1 as a localhost address
|
/* The Travis-CI container responds poorly to ::1 as a localhost address
|
||||||
|
@ -17,38 +19,38 @@
|
||||||
#define TOX_LOCALHOST "127.0.0.1"
|
#define TOX_LOCALHOST "127.0.0.1"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
struct loop_test {
|
||||||
int start_count, stop_count;
|
int start_count, stop_count;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
Tox *tox;
|
Tox *tox;
|
||||||
} loop_test;
|
};
|
||||||
|
|
||||||
void tox_loop_cb_start(Tox *tox, void *user_data)
|
void tox_loop_cb_start(Tox *tox, void *user_data)
|
||||||
{
|
{
|
||||||
loop_test *userdata = (loop_test *) user_data;
|
struct loop_test *userdata = user_data;
|
||||||
pthread_mutex_lock(&userdata->mutex);
|
pthread_mutex_lock(&userdata->mutex);
|
||||||
userdata->start_count++;
|
userdata->start_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_loop_cb_stop(Tox *tox, void *user_data)
|
void tox_loop_cb_stop(Tox *tox, void *user_data)
|
||||||
{
|
{
|
||||||
loop_test *userdata = (loop_test *) user_data;
|
struct loop_test *userdata = user_data;
|
||||||
userdata->stop_count++;
|
userdata->stop_count++;
|
||||||
pthread_mutex_unlock(&userdata->mutex);
|
pthread_mutex_unlock(&userdata->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tox_loop_worker(void *data)
|
void *tox_loop_worker(void *data)
|
||||||
{
|
{
|
||||||
loop_test *userdata = (loop_test *) data;
|
struct loop_test *userdata = data;
|
||||||
tox_loop(userdata->tox, data, NULL);
|
int retval = tox_loop(userdata->tox, data);
|
||||||
return NULL;
|
return (void *)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(test_tox_loop)
|
START_TEST(test_tox_loop)
|
||||||
{
|
{
|
||||||
pthread_t worker, worker_tcp;
|
pthread_t worker1, worker2;
|
||||||
struct Tox_Options *opts = tox_options_new(NULL);
|
struct Tox_Options opts;
|
||||||
loop_test userdata;
|
struct loop_test userdata;
|
||||||
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
|
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -56,42 +58,43 @@ START_TEST(test_tox_loop)
|
||||||
userdata.stop_count = 0;
|
userdata.stop_count = 0;
|
||||||
pthread_mutex_init(&userdata.mutex, NULL);
|
pthread_mutex_init(&userdata.mutex, NULL);
|
||||||
|
|
||||||
tox_options_set_tcp_port(opts, TCP_RELAY_PORT);
|
tox_options_default(&opts);
|
||||||
userdata.tox = tox_new(opts, NULL);
|
opts.tcp_port = TCP_RELAY_PORT;
|
||||||
|
userdata.tox = tox_new(&opts, 0);
|
||||||
tox_callback_loop_begin(userdata.tox, tox_loop_cb_start);
|
tox_callback_loop_begin(userdata.tox, tox_loop_cb_start);
|
||||||
tox_callback_loop_end(userdata.tox, tox_loop_cb_stop);
|
tox_callback_loop_end(userdata.tox, tox_loop_cb_stop);
|
||||||
pthread_create(&worker, NULL, tox_loop_worker, &userdata);
|
pthread_create(&worker1, NULL, tox_loop_worker, &userdata);
|
||||||
|
|
||||||
tox_self_get_dht_id(userdata.tox, dpk);
|
tox_self_get_dht_id(userdata.tox, dpk);
|
||||||
|
|
||||||
tox_options_default(opts);
|
tox_options_default(&opts);
|
||||||
loop_test userdata_tcp;
|
struct loop_test userdata_tcp;
|
||||||
userdata_tcp.start_count = 0;
|
userdata_tcp.start_count = 0;
|
||||||
userdata_tcp.stop_count = 0;
|
userdata_tcp.stop_count = 0;
|
||||||
pthread_mutex_init(&userdata_tcp.mutex, NULL);
|
pthread_mutex_init(&userdata_tcp.mutex, NULL);
|
||||||
userdata_tcp.tox = tox_new(opts, NULL);
|
userdata_tcp.tox = tox_new(&opts, 0);
|
||||||
tox_callback_loop_begin(userdata_tcp.tox, tox_loop_cb_start);
|
tox_callback_loop_begin(userdata_tcp.tox, tox_loop_cb_start);
|
||||||
tox_callback_loop_end(userdata_tcp.tox, tox_loop_cb_stop);
|
tox_callback_loop_end(userdata_tcp.tox, tox_loop_cb_stop);
|
||||||
pthread_create(&worker_tcp, NULL, tox_loop_worker, &userdata_tcp);
|
pthread_create(&worker2, NULL, tox_loop_worker, &userdata_tcp);
|
||||||
|
|
||||||
pthread_mutex_lock(&userdata_tcp.mutex);
|
pthread_mutex_lock(&userdata_tcp.mutex);
|
||||||
TOX_ERR_BOOTSTRAP error;
|
TOX_ERR_BOOTSTRAP error = 0;
|
||||||
ck_assert_msg(tox_add_tcp_relay(userdata_tcp.tox, TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "Add relay error, %i",
|
ck_assert_msg(tox_add_tcp_relay(userdata_tcp.tox, TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i",
|
||||||
error);
|
error);
|
||||||
ck_assert_msg(tox_bootstrap(userdata_tcp.tox, TOX_LOCALHOST, 33445, dpk, &error), "Bootstrap error, %i", error);
|
ck_assert_msg(tox_bootstrap(userdata_tcp.tox, TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error");
|
||||||
pthread_mutex_unlock(&userdata_tcp.mutex);
|
pthread_mutex_unlock(&userdata_tcp.mutex);
|
||||||
|
|
||||||
sleep(10);
|
sleep(10);
|
||||||
|
|
||||||
tox_loop_stop(userdata.tox);
|
tox_loop_stop(userdata.tox);
|
||||||
pthread_join(worker, (void **)&retval);
|
pthread_join(worker1, (void **)&retval);
|
||||||
ck_assert_msg(retval == 0, "tox_loop didn't return 0");
|
ck_assert_msg(retval == 0, "tox_loop didn't return 0");
|
||||||
|
|
||||||
tox_kill(userdata.tox);
|
tox_kill(userdata.tox);
|
||||||
ck_assert_msg(userdata.start_count == userdata.stop_count, "start and stop must match");
|
ck_assert_msg(userdata.start_count == userdata.stop_count, "start and stop must match");
|
||||||
|
|
||||||
tox_loop_stop(userdata_tcp.tox);
|
tox_loop_stop(userdata_tcp.tox);
|
||||||
pthread_join(worker_tcp, (void **)&retval);
|
pthread_join(worker2, (void **)&retval);
|
||||||
ck_assert_msg(retval == 0, "tox_loop didn't return 0");
|
ck_assert_msg(retval == 0, "tox_loop didn't return 0");
|
||||||
|
|
||||||
tox_kill(userdata_tcp.tox);
|
tox_kill(userdata_tcp.tox);
|
||||||
|
@ -100,9 +103,9 @@ START_TEST(test_tox_loop)
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
#ifdef TRAVIS_ENV
|
#ifdef TRAVIS_ENV
|
||||||
static uint8_t timeout_mux = 20;
|
uint8_t timeout_mux = 20;
|
||||||
#else
|
#else
|
||||||
static uint8_t timeout_mux = 10;
|
uint8_t timeout_mux = 10;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Suite *tox_suite(void)
|
static Suite *tox_suite(void)
|
||||||
|
|
|
@ -15,7 +15,6 @@ dependencies:
|
||||||
- sudo apt-get install clang
|
- sudo apt-get install clang
|
||||||
- sudo apt-get install build-essential libtool autotools-dev automake checkinstall check git yasm
|
- sudo apt-get install build-essential libtool autotools-dev automake checkinstall check git yasm
|
||||||
- sudo apt-get install libopus-dev libvpx-dev pkg-config
|
- sudo apt-get install libopus-dev libvpx-dev pkg-config
|
||||||
- sudo apt-get install libev-dev libevent-dev
|
|
||||||
|
|
||||||
# ------------ network_test requires that "localhost" resolves to ::1 ------------
|
# ------------ network_test requires that "localhost" resolves to ::1 ------------
|
||||||
- sudo bash -c "echo '::1 localhost ipv6-localhost ipv6-loopback' >> /etc/hosts" # ipv6 localhost entry
|
- sudo bash -c "echo '::1 localhost ipv6-localhost ipv6-loopback' >> /etc/hosts" # ipv6 localhost entry
|
||||||
|
|
|
@ -14,14 +14,6 @@ find_library(RT_LIBRARIES rt )
|
||||||
|
|
||||||
# For toxcore.
|
# For toxcore.
|
||||||
pkg_use_module(LIBSODIUM libsodium )
|
pkg_use_module(LIBSODIUM libsodium )
|
||||||
pkg_use_module(LIBEV ev )
|
|
||||||
if(NOT LIBEV_FOUND)
|
|
||||||
if(NOT WIN32)
|
|
||||||
pkg_use_module(LIBEVENT libevent_pthreads )
|
|
||||||
else()
|
|
||||||
pkg_use_module(LIBEVENT libevent )
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# For toxav.
|
# For toxav.
|
||||||
pkg_use_module(OPUS opus )
|
pkg_use_module(OPUS opus )
|
||||||
|
@ -38,7 +30,7 @@ pkg_use_module(MSGPACK msgpack )
|
||||||
|
|
||||||
# For av_test.
|
# For av_test.
|
||||||
pkg_use_module(OPENCV opencv )
|
pkg_use_module(OPENCV opencv )
|
||||||
pkg_use_module(PORTAUDIO portaudio-2.0 )
|
pkg_use_module(PORTAUDIO portaudio-2.0)
|
||||||
pkg_use_module(SNDFILE sndfile )
|
pkg_use_module(SNDFILE sndfile )
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -2,8 +2,6 @@ option(ENABLE_SHARED "Build shared (dynamic) libraries for all modules" ON)
|
||||||
option(ENABLE_STATIC "Build static libraries for all modules" ON)
|
option(ENABLE_STATIC "Build static libraries for all modules" ON)
|
||||||
option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
|
option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
|
|
||||||
if(NOT ENABLE_SHARED AND NOT ENABLE_STATIC)
|
if(NOT ENABLE_SHARED AND NOT ENABLE_STATIC)
|
||||||
message(WARNING
|
message(WARNING
|
||||||
"Both static and shared libraries are disabled; "
|
"Both static and shared libraries are disabled; "
|
||||||
|
@ -50,31 +48,6 @@ function(pkg_use_module mod pkg)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
|
||||||
set(${mod}_DEFINITIONS ${${mod}_CFLAGS_OTHER})
|
|
||||||
find_path(${mod}_INCLUDE_DIR NAMES ${ARGV1}.h
|
|
||||||
HINTS ${${mod}_INCLUDEDIR} ${${mod}_INCLUDE_DIRS}
|
|
||||||
PATH_SUFFIXES ${ARGV1})
|
|
||||||
find_library(${mod}_LIBRARY NAMES ${ARGV1} lib${ARGV1}
|
|
||||||
HINTS ${${mod}_LIBDIR} ${${mod}_LIBRARY_DIRS})
|
|
||||||
find_package_handle_standard_args(${mod} DEFAULT_MSG
|
|
||||||
${mod}_LIBRARY ${mod}_INCLUDE_DIR)
|
|
||||||
|
|
||||||
if(${mod}_FOUND)
|
|
||||||
mark_as_advanced(${mod}_INCLUDE_DIR ${mod}_LIBRARY)
|
|
||||||
set(${mod}_LIBRARIES ${${mod}_LIBRARY} PARENT_SCOPE)
|
|
||||||
set(${mod}_INCLUDE_DIRS ${${mod}_INCLUDE_DIR} PARENT_SCOPE)
|
|
||||||
set(${mod}_FOUND TRUE PARENT_SCOPE)
|
|
||||||
link_directories(${${mod}_LIBRARY_DIRS})
|
|
||||||
include_directories(${${mod}_INCLUDE_DIRS})
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
|
|
||||||
|
|
||||||
foreach(dir ${${mod}_INCLUDE_DIRS})
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
251
configure.ac
251
configure.ac
|
@ -31,8 +31,6 @@ LIBCHECK_FOUND="no"
|
||||||
WANT_NACL="no"
|
WANT_NACL="no"
|
||||||
ADD_NACL_OBJECTS_TO_PKGCONFIG="yes"
|
ADD_NACL_OBJECTS_TO_PKGCONFIG="yes"
|
||||||
SET_SO_VERSION="yes"
|
SET_SO_VERSION="yes"
|
||||||
WANT_LIBEV="no"
|
|
||||||
WANT_LIBEVENT="no"
|
|
||||||
|
|
||||||
AC_ARG_ENABLE([soname-versions],
|
AC_ARG_ENABLE([soname-versions],
|
||||||
[AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for android) (default: enabled)]) ],
|
[AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for android) (default: enabled)]) ],
|
||||||
|
@ -57,32 +55,6 @@ AC_ARG_ENABLE([nacl],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
AC_ARG_ENABLE([libev],
|
|
||||||
[AC_HELP_STRING([--enable-libev], [use libev to watch for events (default: disabled)]) ],
|
|
||||||
[
|
|
||||||
if test "x$enableval" = "xyes"; then
|
|
||||||
WANT_LIBEV="yes"
|
|
||||||
elif test "x$enableval" = "xno"; then
|
|
||||||
WANT_LIBEV="no"
|
|
||||||
fi
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
AC_ARG_ENABLE([libevent],
|
|
||||||
[AC_HELP_STRING([--enable-libevent], [use libevent to watch for events (default: disabled)]) ],
|
|
||||||
[
|
|
||||||
if test "x$enableval" = "xyes"; then
|
|
||||||
WANT_LIBEVENT="yes"
|
|
||||||
elif test "x$enableval" = "xno"; then
|
|
||||||
WANT_LIBEVENT="no"
|
|
||||||
fi
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
if test "x$WANT_LIBEV" = "xyes" && test "x$WANT_LIBEVENT" = "xyes"; then
|
|
||||||
AC_MSG_ERROR([cannot enable both libev and libevent, please choose one])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_ARG_ENABLE([randombytes-stir],
|
AC_ARG_ENABLE([randombytes-stir],
|
||||||
[AC_HELP_STRING([--enable-randombytes-stir], [use randombytes_stir() instead of sodium_init() for faster startup on android (default: disabled)]) ],
|
[AC_HELP_STRING([--enable-randombytes-stir], [use randombytes_stir() instead of sodium_init() for faster startup on android (default: disabled)]) ],
|
||||||
[
|
[
|
||||||
|
@ -239,10 +211,6 @@ LIBSODIUM_SEARCH_HEADERS=
|
||||||
LIBSODIUM_SEARCH_LIBS=
|
LIBSODIUM_SEARCH_LIBS=
|
||||||
NACL_SEARCH_HEADERS=
|
NACL_SEARCH_HEADERS=
|
||||||
NACL_SEARCH_LIBS=
|
NACL_SEARCH_LIBS=
|
||||||
LIBEV_SEARCH_HEADERS=
|
|
||||||
LIBEV_SEARCH_LIBS=
|
|
||||||
LIBEVENT_SEARCH_HEADERS=
|
|
||||||
LIBEVENT_SEARCH_LIBS=
|
|
||||||
|
|
||||||
AC_ARG_WITH(dependency-search,
|
AC_ARG_WITH(dependency-search,
|
||||||
AC_HELP_STRING([--with-dependency-search=DIR],
|
AC_HELP_STRING([--with-dependency-search=DIR],
|
||||||
|
@ -296,42 +264,6 @@ AC_ARG_WITH(libsodium-libs,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
AC_ARG_WITH(libev-headers,
|
|
||||||
AC_HELP_STRING([--with-libev-headers=DIR],
|
|
||||||
[search for libev header files in DIR]),
|
|
||||||
[
|
|
||||||
LIBEV_SEARCH_HEADERS="$withval"
|
|
||||||
AC_MSG_NOTICE([will search for libev header files in $withval])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
AC_ARG_WITH(libev-libs,
|
|
||||||
AC_HELP_STRING([--with-libev-libs=DIR],
|
|
||||||
[search for libev libraries in DIR]),
|
|
||||||
[
|
|
||||||
LIBEV_SEARCH_LIBS="$withval"
|
|
||||||
AC_MSG_NOTICE([will search for libev libraries in $withval])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
AC_ARG_WITH(libevent-headers,
|
|
||||||
AC_HELP_STRING([--with-libevent-headers=DIR],
|
|
||||||
[search for libevent header files in DIR]),
|
|
||||||
[
|
|
||||||
LIBEVENT_SEARCH_HEADERS="$withval"
|
|
||||||
AC_MSG_NOTICE([will search for libevent header files in $withval])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
AC_ARG_WITH(libevent-libs,
|
|
||||||
AC_HELP_STRING([--with-libevent-libs=DIR],
|
|
||||||
[search for libevent libraries in DIR]),
|
|
||||||
[
|
|
||||||
LIBEVENT_SEARCH_LIBS="$withval"
|
|
||||||
AC_MSG_NOTICE([will search for libevent libraries in $withval])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
if test "x$WANT_NACL" = "xyes"; then
|
if test "x$WANT_NACL" = "xyes"; then
|
||||||
enable_shared=no
|
enable_shared=no
|
||||||
enable_static=yes
|
enable_static=yes
|
||||||
|
@ -462,123 +394,6 @@ elif test "x$LIBSODIUM_FOUND" = "xno"; then
|
||||||
AC_SUBST(LIBSODIUM_LDFLAGS)
|
AC_SUBST(LIBSODIUM_LDFLAGS)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$WANT_LIBEV" = "xyes"; then
|
|
||||||
if test -n "$PKG_CONFIG"; then
|
|
||||||
PKG_CHECK_MODULES([LIBEV], [libev],
|
|
||||||
[
|
|
||||||
LIBEV_PKG_CONFIG="yes"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
LIBEV_PKG_CONFIG="no"
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
LIBEV_PKG_CONFIG="no"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$LIBEV_PKG_CONFIG" = "xno"; then
|
|
||||||
LIBEV_LIBS=
|
|
||||||
LIBEV_LDFLAGS=
|
|
||||||
LDFLAGS_SAVE="$LDFLAGS"
|
|
||||||
|
|
||||||
if test -n "$LIBEV_SEARCH_LIBS"; then
|
|
||||||
LDFLAGS="-L$LIBEV_SEARCH_LIBS $LDFLAGS"
|
|
||||||
AC_CHECK_LIB(ev, ev_run,
|
|
||||||
[
|
|
||||||
LIBEV_LDFLAGS="-L$LIBEV_SEARCH_LIBS"
|
|
||||||
LIBEV_LIBS="-lev"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([required library libev was not found in requested location $LIBEV_SEARCH_LIBS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
AC_CHECK_LIB(ev, ev_run,
|
|
||||||
[
|
|
||||||
LIBEV_LIBS="-lev"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([required library libev was not found in requested location $LIBEV_SEARCH_LIBS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
LDFLAGS="$LDFLAGS_SAVE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_SUBST(LIBEV_LIBS)
|
|
||||||
AC_SUBST(LIBEV_LDFLAGS)
|
|
||||||
AC_DEFINE([HAVE_LIBEV], [1], [Define to 1 if you have the 'libev' library (-lev).])
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$WANT_LIBEVENT" = "xyes"; then
|
|
||||||
if test -n "$PKG_CONFIG"; then
|
|
||||||
if test "x$WIN32" = "xno"; then
|
|
||||||
PKG_CHECK_MODULES([LIBEVENT], [libevent_pthreads],
|
|
||||||
[
|
|
||||||
LIBEVENT_PKG_CONFIG="yes"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
LIBEVENT_PKG_CONFIG="no"
|
|
||||||
],
|
|
||||||
)
|
|
||||||
else
|
|
||||||
PKG_CHECK_MODULES([LIBEVENT], [libevent],
|
|
||||||
[
|
|
||||||
LIBEVENT_PKG_CONFIG="yes"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
LIBEVENT_PKG_CONFIG="no"
|
|
||||||
],
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
LIBEVENT_PKG_CONFIG="no"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$LIBEVENT_PKG_CONFIG" = "xno"; then
|
|
||||||
LIBEVENT_LIBS=
|
|
||||||
LIBEVENT_LDFLAGS=
|
|
||||||
LDFLAGS_SAVE="$LDFLAGS"
|
|
||||||
|
|
||||||
if test -n "$LIBEVENT_SEARCH_LIBS"; then
|
|
||||||
LDFLAGS="-L$LIBEVENT_SEARCH_LIBS $LDFLAGS"
|
|
||||||
AC_CHECK_LIB(event, event_base_loop,
|
|
||||||
[
|
|
||||||
LIBEVENT_LDFLAGS="-L$LIBEVENT_SEARCH_LIBS"
|
|
||||||
if test "x$WIN32" = "xno"; then
|
|
||||||
LIBEVENT_LIBS="-levent -levent_pthreads"
|
|
||||||
else
|
|
||||||
LIBEVENT_LIBS="-levent"
|
|
||||||
fi
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([required library libevent was not found in requested location $LIBEVENT_SEARCH_LIBS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
AC_CHECK_LIB(event, event_base_loop,
|
|
||||||
[
|
|
||||||
if test "x$WIN32" = "xno"; then
|
|
||||||
LIBEVENT_LIBS="-levent -levent_pthreads"
|
|
||||||
else
|
|
||||||
LIBEVENT_LIBS="-levent"
|
|
||||||
fi
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([required library libevent was not found in requested location $LIBEVENT_SEARCH_LIBS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
LDFLAGS="$LDFLAGS_SAVE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_SUBST(LIBEVENT_LIBS)
|
|
||||||
AC_SUBST(LIBEVENT_LDFLAGS)
|
|
||||||
AC_DEFINE([HAVE_LIBEVENT], [1], [Define to 1 if you have the 'libevent' library (-levent).])
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
|
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
|
||||||
|
|
||||||
|
@ -638,72 +453,6 @@ elif test "x$LIBSODIUM_FOUND" = "xno"; then
|
||||||
AC_SUBST(LIBSODIUM_CFLAGS)
|
AC_SUBST(LIBSODIUM_CFLAGS)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$WANT_LIBEV" = "xyes"; then
|
|
||||||
if test "x$LIBEV_PKG_CONFIG" = "xno"; then
|
|
||||||
LIBEV_CFLAGS=
|
|
||||||
CFLAGS_SAVE="$CFLAGS"
|
|
||||||
CPPFLAGS_SAVE="$CPPFLAGS"
|
|
||||||
|
|
||||||
if test -n "$LIBEV_SEARCH_HEADERS"; then
|
|
||||||
CFLAGS="-I$LIBEV_SEARCH_HEADERS $CFLAGS"
|
|
||||||
CPPFLAGS="-I$LIBEV_SEARCH_HEADERS $CPPFLAGS"
|
|
||||||
AC_CHECK_HEADER(ev.h,
|
|
||||||
[
|
|
||||||
LIBEV_CFLAGS="-I$LIBEV_SEARCH_HEADERS"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([header files for required library libev were not found in requested location $LIBEV_SEARCH_HEADERS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
AC_CHECK_HEADER(ev.h,
|
|
||||||
[],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([header files for required library libev was not found on your system, please check http://libev.schmorp.de/])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
CFLAGS="$CFLAGS_SAVE"
|
|
||||||
CPPFLAGS="$CPPFLAGS_SAVE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_SUBST(LIBEV_CFLAGS)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$WANT_LIBEVENT" = "xyes"; then
|
|
||||||
if test "x$LIBEVENT_PKG_CONFIG" = "xno"; then
|
|
||||||
LIBEVENT_CFLAGS=
|
|
||||||
CFLAGS_SAVE="$CFLAGS"
|
|
||||||
CPPFLAGS_SAVE="$CPPFLAGS"
|
|
||||||
|
|
||||||
if test -n "$LIBEVENT_SEARCH_HEADERS"; then
|
|
||||||
CFLAGS="-I$LIBEVENT_SEARCH_HEADERS $CFLAGS"
|
|
||||||
CPPFLAGS="-I$LIBEVENT_SEARCH_HEADERS $CPPFLAGS"
|
|
||||||
AC_CHECK_HEADERS([event2/event.h event2/thread.h],
|
|
||||||
[
|
|
||||||
LIBEVENT_CFLAGS="-I$LIBEVENT_SEARCH_HEADERS"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([header files for required library libevent were not found in requested location $LIBEVENT_SEARCH_HEADERS])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
AC_CHECK_HEADERS([event2/event.h event2/thread.h],
|
|
||||||
[],
|
|
||||||
[
|
|
||||||
AC_MSG_ERROR([header files for required library libevent was not found on your system, please check http://libevent.org/])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
CFLAGS="$CFLAGS_SAVE"
|
|
||||||
CPPFLAGS="$CPPFLAGS_SAVE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_SUBST(LIBEVENT_CFLAGS)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_HEADER_STDBOOL
|
AC_HEADER_STDBOOL
|
||||||
AC_TYPE_INT16_T
|
AC_TYPE_INT16_T
|
||||||
|
|
|
@ -7,5 +7,5 @@ Name: libtoxcore
|
||||||
Description: Tox protocol library
|
Description: Tox protocol library
|
||||||
Requires:
|
Requires:
|
||||||
Version: @PACKAGE_VERSION@
|
Version: @PACKAGE_VERSION@
|
||||||
Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} -ltoxcore @NACL_LDFLAGS@ -ltoxdns -ltoxencryptsave @NACL_LIBS@ @LIBEV_LIBS@ @LIBEVENT_LIBS@ @LIBS@ @MATH_LDFLAGS@ @PTHREAD_LDFLAGS@
|
Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} -ltoxcore @NACL_LDFLAGS@ -ltoxdns -ltoxencryptsave @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ @PTHREAD_LDFLAGS@
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir}
|
||||||
|
|
|
@ -55,16 +55,12 @@ libtoxcore_la_CFLAGS = -I$(top_srcdir) \
|
||||||
-I$(top_srcdir)/toxcore \
|
-I$(top_srcdir)/toxcore \
|
||||||
$(LIBSODIUM_CFLAGS) \
|
$(LIBSODIUM_CFLAGS) \
|
||||||
$(NACL_CFLAGS) \
|
$(NACL_CFLAGS) \
|
||||||
$(LIBEV_CFLAGS) \
|
|
||||||
$(LIBEVENT_CFLAGS) \
|
|
||||||
$(PTHREAD_CFLAGS)
|
$(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
libtoxcore_la_LDFLAGS = $(LT_LDFLAGS) \
|
libtoxcore_la_LDFLAGS = $(LT_LDFLAGS) \
|
||||||
$(EXTRA_LT_LDFLAGS) \
|
$(EXTRA_LT_LDFLAGS) \
|
||||||
$(LIBSODIUM_LDFLAGS) \
|
$(LIBSODIUM_LDFLAGS) \
|
||||||
$(NACL_LDFLAGS) \
|
$(NACL_LDFLAGS) \
|
||||||
$(LIBEV_LDFLAGS) \
|
|
||||||
$(LIBEVENT_LDFLAGS) \
|
|
||||||
$(MATH_LDFLAGS) \
|
$(MATH_LDFLAGS) \
|
||||||
$(RT_LIBS) \
|
$(RT_LIBS) \
|
||||||
$(WINSOCK2_LIBS)
|
$(WINSOCK2_LIBS)
|
||||||
|
@ -72,8 +68,6 @@ libtoxcore_la_LDFLAGS = $(LT_LDFLAGS) \
|
||||||
libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \
|
libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \
|
||||||
$(NACL_OBJECTS) \
|
$(NACL_OBJECTS) \
|
||||||
$(NAC_LIBS) \
|
$(NAC_LIBS) \
|
||||||
$(LIBEV_LIBS) \
|
|
||||||
$(LIBEVENT_LIBS) \
|
|
||||||
$(PTHREAD_LIBS)
|
$(PTHREAD_LIBS)
|
||||||
|
|
||||||
if SET_SO_VERSION
|
if SET_SO_VERSION
|
||||||
|
|
|
@ -1930,28 +1930,6 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
m->dispatcher = ev_loop_new(0);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
|
||||||
evthread_use_windows_threads();
|
|
||||||
#else
|
|
||||||
evthread_use_pthreads();
|
|
||||||
#endif /* WIN32 || _WIN32 || __WIN32__ */
|
|
||||||
m->dispatcher = event_base_new();
|
|
||||||
#else
|
|
||||||
m->loop_run = false;
|
|
||||||
#endif /* HAVE_LIBEV */
|
|
||||||
|
|
||||||
#if defined(HAVE_LIBEV) || defined(HAVE_LIBEVENT)
|
|
||||||
|
|
||||||
if (!m->dispatcher) {
|
|
||||||
free(m);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* HAVE_LIBEV || HAVE_LIBEVENT */
|
|
||||||
|
|
||||||
Logger *log = NULL;
|
Logger *log = NULL;
|
||||||
|
|
||||||
if (options->log_callback) {
|
if (options->log_callback) {
|
||||||
|
@ -2079,12 +2057,6 @@ void kill_messenger(Messenger *m)
|
||||||
clear_receipts(m, i);
|
clear_receipts(m, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
ev_loop_destroy(m->dispatcher);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
event_base_free(m->dispatcher);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
logger_kill(m->log);
|
logger_kill(m->log);
|
||||||
free(m->friendlist);
|
free(m->friendlist);
|
||||||
free(m);
|
free(m);
|
||||||
|
|
|
@ -29,13 +29,6 @@
|
||||||
#include "friend_requests.h"
|
#include "friend_requests.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
#include <ev.h>
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
#include <event2/event.h>
|
|
||||||
#include <event2/thread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_NAME_LENGTH 128
|
#define MAX_NAME_LENGTH 128
|
||||||
/* TODO(irungentoo): this must depend on other variable. */
|
/* TODO(irungentoo): this must depend on other variable. */
|
||||||
#define MAX_STATUSMESSAGE_LENGTH 1007
|
#define MAX_STATUSMESSAGE_LENGTH 1007
|
||||||
|
@ -280,16 +273,9 @@ struct Messenger {
|
||||||
void (*core_connection_change)(struct Messenger *m, unsigned int, void *);
|
void (*core_connection_change)(struct Messenger *m, unsigned int, void *);
|
||||||
unsigned int last_connection_status;
|
unsigned int last_connection_status;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
uint8_t loop_run;
|
||||||
struct ev_loop *dispatcher;
|
void (*loop_begin_cb)(struct Messenger *tox, void *user_data);
|
||||||
ev_async stop_loop;
|
void (*loop_end_cb)(struct Messenger *tox, void *user_data);
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
struct event_base *dispatcher;
|
|
||||||
#else
|
|
||||||
bool loop_run;
|
|
||||||
#endif
|
|
||||||
void (*loop_begin_cb)(struct Messenger *m, void *user_data);
|
|
||||||
void (*loop_end_cb)(struct Messenger *m, void *user_data);
|
|
||||||
|
|
||||||
Messenger_Options options;
|
Messenger_Options options;
|
||||||
};
|
};
|
||||||
|
|
|
@ -985,17 +985,6 @@ void kill_TCP_connection(TCP_Client_Connection *TCP_connection)
|
||||||
|
|
||||||
wipe_priority_list(TCP_connection);
|
wipe_priority_list(TCP_connection);
|
||||||
kill_sock(TCP_connection->sock);
|
kill_sock(TCP_connection->sock);
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
ev_io_stop(TCP_connection->sock_listener.dispatcher, &TCP_connection->sock_listener.listener);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
|
|
||||||
if (TCP_connection->sock_listener) {
|
|
||||||
event_free(TCP_connection->sock_listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
crypto_memzero(TCP_connection, sizeof(TCP_Client_Connection));
|
crypto_memzero(TCP_connection, sizeof(TCP_Client_Connection));
|
||||||
free(TCP_connection);
|
free(TCP_connection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,6 @@
|
||||||
#include "TCP_server.h"
|
#include "TCP_server.h"
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
#include <ev.h>
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
#include <event2/event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TCP_CONNECTION_TIMEOUT 10
|
#define TCP_CONNECTION_TIMEOUT 10
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -59,14 +53,6 @@ enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
Socket sock;
|
Socket sock;
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
struct {
|
|
||||||
ev_io listener;
|
|
||||||
struct ev_loop *dispatcher;
|
|
||||||
} sock_listener;
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
struct event *sock_listener;
|
|
||||||
#endif
|
|
||||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* our public key */
|
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* our public key */
|
||||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* public key of the server */
|
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* public key of the server */
|
||||||
IP_Port ip_port; /* The ip and port of the server */
|
IP_Port ip_port; /* The ip and port of the server */
|
||||||
|
|
|
@ -67,37 +67,6 @@ const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return number of elements of TCP connection array.
|
|
||||||
*
|
|
||||||
* @param tcp_c struct containing TCP_con array
|
|
||||||
*
|
|
||||||
* @return number of elements of TCP connection array
|
|
||||||
*/
|
|
||||||
uint32_t tcp_connections_length(const TCP_Connections *tcp_c)
|
|
||||||
{
|
|
||||||
return tcp_c->tcp_connections_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return TCP connection stored at "idx" position.
|
|
||||||
*
|
|
||||||
* @param tcp_c struct containing TCP_con array
|
|
||||||
* @param idx index of TCP connection to return (values from 0 to tcp_connections_length() - 1)
|
|
||||||
*
|
|
||||||
* @return TCP connection stored at "idx" position, or NULL if errors occurred
|
|
||||||
*/
|
|
||||||
const TCP_con *tcp_connections_connection_at(const TCP_Connections *tcp_c, uint32_t idx)
|
|
||||||
{
|
|
||||||
if (idx >= tcp_c->tcp_connections_length) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &tcp_c->tcp_connections[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Set the size of the array to num.
|
/* Set the size of the array to num.
|
||||||
*
|
*
|
||||||
* return -1 if realloc fails.
|
* return -1 if realloc fails.
|
||||||
|
|
|
@ -82,10 +82,6 @@ typedef struct TCP_Connections TCP_Connections;
|
||||||
|
|
||||||
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
|
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
|
||||||
|
|
||||||
uint32_t tcp_connections_length(const TCP_Connections *tcp_c);
|
|
||||||
|
|
||||||
const TCP_con *tcp_connections_connection_at(const TCP_Connections *tcp_c, uint32_t idx);
|
|
||||||
|
|
||||||
/* Send a packet to the TCP connection.
|
/* Send a packet to the TCP connection.
|
||||||
*
|
*
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
|
|
|
@ -794,16 +794,6 @@ void kill_networking(Networking_Core *net)
|
||||||
kill_sock(net->sock);
|
kill_sock(net->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
ev_io_stop(net->sock_listener.dispatcher, &net->sock_listener.listener);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
|
|
||||||
if (net->sock_listener) {
|
|
||||||
event_free(net->sock_listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
free(net);
|
free(net);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,6 @@
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
#include <ev.h>
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
#include <event2/event.h>
|
|
||||||
#endif
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -323,14 +318,6 @@ typedef struct {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
/* Our UDP socket. */
|
/* Our UDP socket. */
|
||||||
Socket sock;
|
Socket sock;
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
struct {
|
|
||||||
ev_io listener;
|
|
||||||
struct ev_loop *dispatcher;
|
|
||||||
} sock_listener;
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
struct event *sock_listener;
|
|
||||||
#endif
|
|
||||||
} Networking_Core;
|
} Networking_Core;
|
||||||
|
|
||||||
/* Run this before creating sockets.
|
/* Run this before creating sockets.
|
||||||
|
|
|
@ -838,45 +838,19 @@ const uint32_t iteration_interval();
|
||||||
*/
|
*/
|
||||||
void iterate(any user_data);
|
void iterate(any user_data);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error codes for $loop().
|
* Run $iterate() any time a packet arrives, only returns after ${loop.stop}().
|
||||||
*/
|
*/
|
||||||
error for loop {
|
uint32_t loop(any user_data);
|
||||||
/**
|
|
||||||
* Invalid arguments passed.
|
|
||||||
*/
|
|
||||||
NULL,
|
|
||||||
/**
|
|
||||||
* Failed running events dispatcher.
|
|
||||||
*/
|
|
||||||
BREAK,
|
|
||||||
/**
|
|
||||||
* Failed running select().
|
|
||||||
*/
|
|
||||||
SELECT,
|
|
||||||
/**
|
|
||||||
* Failed getting sockets file descriptors.
|
|
||||||
*/
|
|
||||||
GET_FDS,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run $iterate() any time a packet arrives, returns after ${loop.stop}() or ${kill}().
|
|
||||||
*/
|
|
||||||
bool loop(any user_data) with error for loop;
|
|
||||||
|
|
||||||
|
|
||||||
namespace loop {
|
namespace loop {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell $loop() to return.
|
* Tell $loop() to return.
|
||||||
*/
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This callback is invoked when $loop() calls into $iterate(), the client can lock a mutex here.
|
* Callback ran when $loop() calls into $iterate(), the client can lock a mutex here.
|
||||||
*/
|
*/
|
||||||
event begin const {
|
event begin const {
|
||||||
/**
|
/**
|
||||||
|
@ -886,7 +860,7 @@ namespace loop {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This callback is invoked when $loop() is finished with $iterate(), the client can unlock the mutex here.
|
* Callback ran when $loop() is finished with $iterate(), the client can unlock the mutex here.
|
||||||
*/
|
*/
|
||||||
event end const {
|
event end const {
|
||||||
/**
|
/**
|
||||||
|
|
358
toxcore/tox.c
358
toxcore/tox.c
|
@ -34,19 +34,9 @@ typedef struct Messenger Tox;
|
||||||
#include "Messenger.h"
|
#include "Messenger.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "net_crypto.h"
|
|
||||||
|
|
||||||
#include "../toxencryptsave/defines.h"
|
#include "../toxencryptsave/defines.h"
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#if !defined(HAVE_LIBEV) && !defined(HAVE_LIBEVENT)
|
|
||||||
#if defined (WIN32) || defined(_WIN32) || defined(__WIN32__)
|
|
||||||
#include <winsock2.h>
|
|
||||||
#else
|
|
||||||
#include <sys/select.h>
|
|
||||||
#endif /* WIN32 || _WIN32 || __WIN32__ */
|
|
||||||
#endif /* !HAVE_LIBEV && !HAVE_LIBEVENT */
|
|
||||||
|
|
||||||
#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
|
#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
|
||||||
|
|
||||||
#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE
|
#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE
|
||||||
|
@ -81,12 +71,6 @@ typedef struct Messenger Tox;
|
||||||
#error TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH
|
#error TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LIBEV) || defined(HAVE_LIBEVENT)
|
|
||||||
typedef struct {
|
|
||||||
Tox *tox;
|
|
||||||
void *user_data;
|
|
||||||
} Event_Arg;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
|
bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
|
||||||
{
|
{
|
||||||
|
@ -219,8 +203,6 @@ void tox_kill(Tox *tox)
|
||||||
}
|
}
|
||||||
|
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
|
|
||||||
tox_loop_stop(tox);
|
|
||||||
kill_groupchats((Group_Chats *)m->conferences_object);
|
kill_groupchats((Group_Chats *)m->conferences_object);
|
||||||
kill_messenger(m);
|
kill_messenger(m);
|
||||||
}
|
}
|
||||||
|
@ -360,261 +342,68 @@ void tox_iterate(Tox *tox, void *user_data)
|
||||||
do_groupchats((Group_Chats *)m->conferences_object, user_data);
|
do_groupchats((Group_Chats *)m->conferences_object, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_callback_loop_begin(Tox *tox, tox_loop_begin_cb *callback)
|
uint32_t tox_fd_count(Tox *tox)
|
||||||
{
|
{
|
||||||
if (tox == NULL) {
|
Messenger *m = tox;
|
||||||
return;
|
return 1 + m->net_crypto->tcp_c->tcp_connections_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gathers a list of every network FD activity is expected on
|
||||||
|
* @param sockets an array of size tox_fd_count()
|
||||||
|
*/
|
||||||
|
uint32_t tox_fds(Tox *tox, uint32_t *sockets, uint32_t max_sockets)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (max_sockets >= 1) {
|
||||||
|
sockets[count] = m->net->sock;
|
||||||
|
max_sockets--;
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TCP_Connections *conns = m->net_crypto->tcp_c;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
for (x = 0; x < conns->tcp_connections_length; x++) {
|
||||||
|
if (max_sockets == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TCP_con *conn = &conns->tcp_connections[x];
|
||||||
|
sockets[count] = conn->connection->sock;
|
||||||
|
count++;
|
||||||
|
max_sockets--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tox_callback_loop_begin(Tox *tox, tox_loop_begin_cb *callback)
|
||||||
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m->loop_begin_cb = callback;
|
m->loop_begin_cb = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_callback_loop_end(Tox *tox, tox_loop_end_cb *callback)
|
void tox_callback_loop_end(Tox *tox, tox_loop_end_cb *callback)
|
||||||
{
|
{
|
||||||
if (tox == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m->loop_end_cb = callback;
|
m->loop_end_cb = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
uint32_t tox_loop(Tox *tox, void *user_data)
|
||||||
static void tox_stop_loop_cb(struct ev_loop *dispatcher, ev_async *listener, int events)
|
|
||||||
{
|
{
|
||||||
if (dispatcher == NULL || listener == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Event_Arg *tmp = (Event_Arg *) listener->data;
|
|
||||||
Messenger *m = tmp->tox;
|
|
||||||
|
|
||||||
if (ev_is_active(&m->net->sock_listener.listener) || ev_is_pending(&m->net->sock_listener.listener)) {
|
|
||||||
ev_io_stop(dispatcher, &m->net->sock_listener.listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t len = tcp_connections_length(m->net_crypto->tcp_c);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
|
||||||
const TCP_con *conn = tcp_connections_connection_at(m->net_crypto->tcp_c, i);
|
|
||||||
|
|
||||||
if (ev_is_active(&conn->connection->sock_listener.listener)
|
|
||||||
|| ev_is_pending(&conn->connection->sock_listener.listener)) {
|
|
||||||
ev_io_stop(dispatcher, &conn->connection->sock_listener.listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ev_async_stop(dispatcher, listener);
|
|
||||||
|
|
||||||
ev_break(dispatcher, EVBREAK_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tox_do_iterate(struct ev_loop *dispatcher, ev_io *sock_listener, int events)
|
|
||||||
{
|
|
||||||
if (dispatcher == NULL || sock_listener == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Event_Arg *tmp = (Event_Arg *) sock_listener->data;
|
|
||||||
Messenger *m = tmp->tox;
|
|
||||||
|
|
||||||
if (m->loop_begin_cb) {
|
|
||||||
m->loop_begin_cb(m, tmp->user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
tox_iterate(tmp->tox, tmp->user_data);
|
|
||||||
|
|
||||||
if (!ev_is_active(&m->net->sock_listener.listener) && !ev_is_pending(&m->net->sock_listener.listener)) {
|
|
||||||
m->net->sock_listener.dispatcher = dispatcher;
|
|
||||||
ev_io_init(&m->net->sock_listener.listener, tox_do_iterate, m->net->sock, EV_READ);
|
|
||||||
m->net->sock_listener.listener.data = sock_listener->data;
|
|
||||||
ev_io_start(dispatcher, &m->net->sock_listener.listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t len = tcp_connections_length(m->net_crypto->tcp_c);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
|
||||||
const TCP_con *conn = tcp_connections_connection_at(m->net_crypto->tcp_c, i);
|
|
||||||
|
|
||||||
if (!ev_is_active(&conn->connection->sock_listener.listener)
|
|
||||||
&& !ev_is_pending(&conn->connection->sock_listener.listener)) {
|
|
||||||
conn->connection->sock_listener.dispatcher = dispatcher;
|
|
||||||
ev_io_init(&conn->connection->sock_listener.listener, tox_do_iterate, conn->connection->sock, EV_READ);
|
|
||||||
conn->connection->sock_listener.listener.data = sock_listener->data;
|
|
||||||
ev_io_start(m->dispatcher, &conn->connection->sock_listener.listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->loop_end_cb) {
|
|
||||||
m->loop_end_cb(m, tmp->user_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
static void tox_do_iterate(evutil_socket_t fd, short events, void *arg)
|
|
||||||
{
|
|
||||||
if (arg == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Event_Arg *tmp = (Event_Arg *) arg;
|
|
||||||
Messenger *m = tmp->tox;
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
|
int maxfd;
|
||||||
if (m->loop_begin_cb) {
|
uint32_t i, list_size = 0;
|
||||||
m->loop_begin_cb(m, tmp->user_data);
|
uint32_t *fdlist = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
tox_iterate(tmp->tox, tmp->user_data);
|
|
||||||
|
|
||||||
timeout.tv_sec = 0;
|
|
||||||
|
|
||||||
// TODO(cleverca22): use a longer timeout.
|
|
||||||
timeout.tv_usec = tox_iteration_interval(tmp->tox) * 1000 * 2;
|
|
||||||
|
|
||||||
if (!m->net->sock_listener) {
|
|
||||||
m->net->sock_listener = event_new(m->dispatcher, m->net->sock, EV_READ | EV_PERSIST, tox_do_iterate, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
event_add(m->net->sock_listener, &timeout);
|
|
||||||
|
|
||||||
uint32_t len = tcp_connections_length(m->net_crypto->tcp_c);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
|
||||||
const TCP_con *conn = tcp_connections_connection_at(m->net_crypto->tcp_c, i);
|
|
||||||
|
|
||||||
if (!conn->connection->sock_listener) {
|
|
||||||
conn->connection->sock_listener = event_new(m->dispatcher, conn->connection->sock, EV_READ | EV_PERSIST, tox_do_iterate,
|
|
||||||
arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
event_add(conn->connection->sock_listener, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->loop_end_cb) {
|
|
||||||
m->loop_end_cb(m, tmp->user_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/**
|
|
||||||
* Gathers a list of every network file descriptor,
|
|
||||||
* where an activity is expected on.
|
|
||||||
*
|
|
||||||
* @param sockets a pointer to an array (the pointed array can be NULL).
|
|
||||||
* @param sockets_num the number of current known sockets (will be updated by the funciton).
|
|
||||||
*
|
|
||||||
* @return false if errors occurred, true otherwise.
|
|
||||||
*/
|
|
||||||
static bool tox_fds(Messenger *m, Socket **sockets, uint32_t *sockets_num)
|
|
||||||
{
|
|
||||||
if (m == NULL || sockets == NULL || sockets_num == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t len = tcp_connections_length(m->net_crypto->tcp_c);
|
|
||||||
uint32_t fdcount = 1 + len;
|
|
||||||
|
|
||||||
if (fdcount != *sockets_num || *sockets == NULL) {
|
|
||||||
Socket *tmp_sockets = (Socket *) realloc(*sockets, fdcount * sizeof(Socket));
|
|
||||||
|
|
||||||
if (tmp_sockets == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*sockets = tmp_sockets;
|
|
||||||
*sockets_num = fdcount;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*sockets)[0] = m->net->sock;
|
|
||||||
|
|
||||||
uint32_t i = 0;
|
|
||||||
|
|
||||||
while (i < fdcount - 1 && i < len) {
|
|
||||||
const TCP_con *conn = tcp_connections_connection_at(m->net_crypto->tcp_c, i);
|
|
||||||
i++;
|
|
||||||
|
|
||||||
if (conn != NULL) {
|
|
||||||
(*sockets)[i] = conn->connection->sock;
|
|
||||||
} else {
|
|
||||||
(*sockets)[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool tox_loop(Tox *tox, void *user_data, TOX_ERR_LOOP *error)
|
|
||||||
{
|
|
||||||
if (tox == NULL) {
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_NULL);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
bool ret = true;
|
|
||||||
Event_Arg *tmp = (Event_Arg *) calloc(1, sizeof(Event_Arg));
|
|
||||||
|
|
||||||
tmp->tox = tox;
|
|
||||||
tmp->user_data = user_data;
|
|
||||||
|
|
||||||
ev_async_init(&m->stop_loop, tox_stop_loop_cb);
|
|
||||||
m->stop_loop.data = tmp;
|
|
||||||
ev_async_start(m->dispatcher, &m->stop_loop);
|
|
||||||
|
|
||||||
ev_io stub_listener;
|
|
||||||
ev_init(&stub_listener, tox_do_iterate);
|
|
||||||
stub_listener.data = tmp;
|
|
||||||
tox_do_iterate(m->dispatcher, &stub_listener, 0);
|
|
||||||
|
|
||||||
// TODO(Ansa89): travis states that "ev_run" returns "void",
|
|
||||||
// but "man 3 ev" states it returns "bool"
|
|
||||||
#if 0
|
|
||||||
ret = !ev_run(m->dispatcher, 0);
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_OK);
|
|
||||||
} else {
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_BREAK);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ev_run(m->dispatcher, 0);
|
|
||||||
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_OK);
|
|
||||||
|
|
||||||
free(tmp);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
Event_Arg *tmp = (Event_Arg *) calloc(1, sizeof(Event_Arg));
|
|
||||||
|
|
||||||
tmp->tox = tox;
|
|
||||||
tmp->user_data = user_data;
|
|
||||||
|
|
||||||
tox_do_iterate(0, 0, tmp);
|
|
||||||
bool ret = event_base_dispatch(m->dispatcher) < 0 ? false : true;
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_OK);
|
|
||||||
} else {
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_BREAK);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(tmp);
|
|
||||||
#else
|
|
||||||
bool ret = true;
|
|
||||||
uint32_t fdcount = 0;
|
|
||||||
Socket *fdlist = NULL;
|
|
||||||
|
|
||||||
m->loop_run = true;
|
m->loop_run = true;
|
||||||
|
|
||||||
while (m->loop_run) {
|
|
||||||
Socket maxfd;
|
|
||||||
fd_set readable;
|
fd_set readable;
|
||||||
|
|
||||||
|
|
||||||
|
while (m->loop_run) {
|
||||||
if (m->loop_begin_cb) {
|
if (m->loop_begin_cb) {
|
||||||
m->loop_begin_cb(tox, user_data);
|
m->loop_begin_cb(tox, user_data);
|
||||||
}
|
}
|
||||||
|
@ -624,27 +413,16 @@ bool tox_loop(Tox *tox, void *user_data, TOX_ERR_LOOP *error)
|
||||||
maxfd = 0;
|
maxfd = 0;
|
||||||
FD_ZERO(&readable);
|
FD_ZERO(&readable);
|
||||||
|
|
||||||
// TODO(cleverca22): is it a good idea to reuse previous fdlist when
|
uint32_t fdcount = tox_fd_count(tox);
|
||||||
// fdcount!=0 && tox_fds()==false?
|
|
||||||
if (fdcount == 0 && !tox_fds(m, &fdlist, &fdcount)) {
|
if (fdcount > list_size) {
|
||||||
// We must stop because maxfd won't be set.
|
fdlist = realloc(fdlist, fdcount * sizeof(uint32_t));
|
||||||
// TODO(cleverca22): should we call loop_end_cb() on error?
|
list_size = fdcount;
|
||||||
if (m->loop_end_cb) {
|
|
||||||
m->loop_end_cb(tox, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_GET_FDS);
|
fdcount = tox_fds(tox, fdlist, list_size);
|
||||||
|
|
||||||
free(fdlist);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < fdcount; i++) {
|
|
||||||
if (fdlist[i] == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (i = 0; i < fdcount; i++) {
|
||||||
FD_SET(fdlist[i], &readable);
|
FD_SET(fdlist[i], &readable);
|
||||||
|
|
||||||
if (fdlist[i] > maxfd) {
|
if (fdlist[i] > maxfd) {
|
||||||
|
@ -652,49 +430,27 @@ bool tox_loop(Tox *tox, void *user_data, TOX_ERR_LOOP *error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval timeout;
|
|
||||||
|
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_usec = tox_iteration_interval(tox) * 1000 * 2; // TODO, use a longer timeout (cleverca22)
|
||||||
// TODO(cleverca22): use a longer timeout.
|
|
||||||
timeout.tv_usec = tox_iteration_interval(tox) * 1000 * 2;
|
|
||||||
|
|
||||||
if (m->loop_end_cb) {
|
if (m->loop_end_cb) {
|
||||||
m->loop_end_cb(tox, user_data);
|
m->loop_end_cb(tox, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (select(maxfd, &readable, NULL, NULL, &timeout) < 0 && errno != EBADF) {
|
int ret = select(maxfd, &readable, NULL, NULL, &timeout);
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_SELECT);
|
|
||||||
|
|
||||||
free(fdlist);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_LOOP_OK);
|
|
||||||
|
|
||||||
free(fdlist);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_loop_stop(Tox *tox)
|
void tox_loop_stop(Tox *tox)
|
||||||
{
|
{
|
||||||
if (tox == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
|
|
||||||
#ifdef HAVE_LIBEV
|
|
||||||
ev_async_send(m->dispatcher, &m->stop_loop);
|
|
||||||
#elif HAVE_LIBEVENT
|
|
||||||
event_base_loopbreak(m->dispatcher);
|
|
||||||
#else
|
|
||||||
m->loop_run = false;
|
m->loop_run = false;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_self_get_address(const Tox *tox, uint8_t *address)
|
void tox_self_get_address(const Tox *tox, uint8_t *address)
|
||||||
|
|
|
@ -991,42 +991,9 @@ uint32_t tox_iteration_interval(const Tox *tox);
|
||||||
void tox_iterate(Tox *tox, void *user_data);
|
void tox_iterate(Tox *tox, void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error codes for tox_loop().
|
* Run tox_iterate() any time a packet arrives, only returns after tox_loop_stop().
|
||||||
*/
|
*/
|
||||||
typedef enum TOX_ERR_LOOP {
|
uint32_t tox_loop(Tox *tox, void *user_data);
|
||||||
|
|
||||||
/**
|
|
||||||
* The function returned successfully.
|
|
||||||
*/
|
|
||||||
TOX_ERR_LOOP_OK,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalid arguments passed.
|
|
||||||
*/
|
|
||||||
TOX_ERR_LOOP_NULL,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Failed running events dispatcher.
|
|
||||||
*/
|
|
||||||
TOX_ERR_LOOP_BREAK,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Failed running select().
|
|
||||||
*/
|
|
||||||
TOX_ERR_LOOP_SELECT,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Failed getting sockets file descriptors.
|
|
||||||
*/
|
|
||||||
TOX_ERR_LOOP_GET_FDS,
|
|
||||||
|
|
||||||
} TOX_ERR_LOOP;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run tox_iterate() any time a packet arrives, returns after tox_loop_stop() or tox_kill().
|
|
||||||
*/
|
|
||||||
bool tox_loop(Tox *tox, void *user_data, TOX_ERR_LOOP *error);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell tox_loop() to return.
|
* Tell tox_loop() to return.
|
||||||
|
@ -1042,7 +1009,7 @@ typedef void tox_loop_begin_cb(Tox *tox, void *user_data);
|
||||||
/**
|
/**
|
||||||
* Set the callback for the `loop_begin` event. Pass NULL to unset.
|
* Set the callback for the `loop_begin` event. Pass NULL to unset.
|
||||||
*
|
*
|
||||||
* This callback is invoked when tox_loop() calls into tox_iterate(), the client can lock a mutex here.
|
* Callback ran when tox_loop() calls into tox_iterate(), the client can lock a mutex here.
|
||||||
*/
|
*/
|
||||||
void tox_callback_loop_begin(Tox *tox, tox_loop_begin_cb *callback);
|
void tox_callback_loop_begin(Tox *tox, tox_loop_begin_cb *callback);
|
||||||
|
|
||||||
|
@ -1055,7 +1022,7 @@ typedef void tox_loop_end_cb(Tox *tox, void *user_data);
|
||||||
/**
|
/**
|
||||||
* Set the callback for the `loop_end` event. Pass NULL to unset.
|
* Set the callback for the `loop_end` event. Pass NULL to unset.
|
||||||
*
|
*
|
||||||
* This callback is invoked when tox_loop() is finished with tox_iterate(), the client can unlock the mutex here.
|
* Callback ran when tox_loop() is finished with tox_iterate(), the client can unlock the mutex here.
|
||||||
*/
|
*/
|
||||||
void tox_callback_loop_end(Tox *tox, tox_loop_end_cb *callback);
|
void tox_callback_loop_end(Tox *tox, tox_loop_end_cb *callback);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user