Skip to content

Commit

Permalink
sudo killall -HUP mDNSResponder
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Dec 3, 2023
1 parent c7ca499 commit 8dc5055
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 45 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: C/C++ CI

on: [push, pull_request]
on: [push]

jobs:
Linux:
Expand Down Expand Up @@ -66,6 +66,7 @@ jobs:
- name: liblo make x86_64
run:
make
&& echo -e "\n127.0.0.1 $(hostname)\n" | sudo tee -a /etc/hosts
&& (cd src && ls testlo && ./testlo && ls test_bidirectional_tcp && ./test_bidirectional_tcp && ls cpp_test && ./cpp_test)
&& (make check || (for i in src/*.log; do echo === $i ===; cat $i; done; false))
&& make install
Expand Down Expand Up @@ -107,3 +108,8 @@ jobs:
cd bld\
cmake ..\cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . --target all_build --config Release
- name: Run tests
shell: pwsh
run: |
cd bld\
ctest
13 changes: 11 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if (WITH_TOOLS)
endif()
if (WITH_TESTS)
set(TESTLO testlo)
set(TESTTCP test_bidirectional_tcp)
set(SUBTEST subtest)
if (WITH_CPP_TESTS)
set(CPPTEST cpp_test)
Expand All @@ -94,7 +95,7 @@ if (WITH_EXAMPLES)
endif()

set(TOOLS ${OSCDUMP} ${OSCSEND} ${OSCSENDFILE})
set(TESTS ${TESTLO} ${SUBTEST})
set(TESTS ${TESTLO} ${TESTTCP} ${SUBTEST})
list(APPEND TESTS ${CPPTEST})
set(EXAMPLES ${EXAMPLE_CLIENT} ${EXAMPLE_SERVER}
${EXAMPLE_TCP_ECHO_SERVER} ${NONBLOCKING_SERVER_EXAMPLE})
Expand Down Expand Up @@ -130,6 +131,7 @@ set(OSCDUMP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscdump.c)
set(OSCSEND_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscsend.c)
set(OSCSENDFILE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscsendfile.c)
set(TESTLO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/testlo.c)
set(TESTTCP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/test_bidirectional_tcp.c)
set(SUBTEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/subtest.c)
if (WITH_CPP_TESTS)
set(CPPTEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/cpp_test.cpp)
Expand Down Expand Up @@ -174,7 +176,7 @@ set(BUILD_LANGUAGE C CACHE STRING "Build language (C or CXX)")
mark_as_advanced(BUILD_LANGUAGE)
set_source_files_properties(
${LIBRARY_SOURCES} ${OSCDUMP_SOURCES} ${OSCSEND_SOURCES} ${OSCSENDFILE_SOURCES}
${TESTLO_SOURCES} ${EXAMPLE_CLIENT_SOURCES}
${TESTLO_SOURCES} ${TESTTCP_SOURCES} ${EXAMPLE_CLIENT_SOURCES}
${EXAMPLE_SERVER_SOURCES} ${EXAMPLE_TCP_ECHO_SERVER_SOURCES}
${NONBLOCKING_SERVER_EXAMPLE_SOURCES}
PROPERTIES LANGUAGE ${BUILD_LANGUAGE})
Expand All @@ -201,10 +203,16 @@ endif()
if (WITH_TESTS)
add_executable(${TESTLO} ${TESTLO_SOURCES})
add_executable(${SUBTEST} ${SUBTEST_SOURCES})
add_executable(${TESTTCP} ${TESTTCP_SOURCES})
target_link_libraries(${TESTLO} PRIVATE Threads::Threads)
target_link_libraries(${TESTTCP} PRIVATE Threads::Threads)
add_test(${TESTLO} tests/${TESTLO})
add_test("test-bidirectional-tcp" tests/${TESTTCP})
enable_testing()
endif()
if (WITH_CPP_TESTS)
add_executable(${CPPTEST} ${CPPTEST_SOURCES})
add_test(${CPPTEST} tests/${CPPTEST})
endif()

# Examples
Expand Down Expand Up @@ -237,6 +245,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
endif()
target_link_libraries(${NONBLOCKING_SERVER_EXAMPLE} PRIVATE "wsock32")
target_link_libraries(${TESTLO} PRIVATE "wsock32")
target_link_libraries(${TESTTCP} PRIVATE "wsock32")

set_target_properties(${LIBRARY_SHARED} PROPERTIES
COMPILE_DEFINITIONS "LIBLO_DLL")
Expand Down
25 changes: 17 additions & 8 deletions src/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,24 @@ int lo_address_resolve(lo_address a)
#endif
hints.ai_socktype =
a->protocol == LO_UDP ? SOCK_DGRAM : SOCK_STREAM;

if ((ret = getaddrinfo(host, lo_address_get_port(a), &hints, &ai))) {
a->errnum = ret;
a->errstr = gai_strerror(ret);
a->ai = NULL;
a->ai_first = NULL;
return -1;
}

/*if (getaddrinfo(host, lo_address_get_port(a), &hints, &ai)) {
usleep(100000);
if (getaddrinfo(host, lo_address_get_port(a), &hints, &ai)) {
usleep(200000);
if (getaddrinfo(host, lo_address_get_port(a), &hints, &ai)) {
usleep(400000);*/
if ((ret = getaddrinfo(host, lo_address_get_port(a), &hints, &ai))) {
puts("MAC ERROR!");
a->errnum = ret;
a->errstr = gai_strerror(ret);
a->ai = NULL;
a->ai_first = NULL;
return -1;
}
/* }
}
}*/
a->ai = ai;
a->ai_first = ai;
}
Expand Down
46 changes: 32 additions & 14 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ lo_server lo_server_new_multicast_iface(const char *group, const char *port,
lo_server lo_server_new_with_proto(const char *port, int proto,
lo_err_handler err_h)
{
fprintf(stderr, "-4");
return lo_server_new_with_proto_internal(NULL, port, 0, 0, proto, err_h, 0);
}

Expand Down Expand Up @@ -452,14 +453,14 @@ lo_server lo_server_new_with_proto_internal(const char *group,
char pnum[16];
const char *service;
int err = 0;

fprintf(stderr, "-4\n");
#if defined(WIN32) || defined(_MSC_VER)
/* Windows Server 2003 or later (Vista, 7, etc.) must join the
* multicast group before bind(), but Windows XP must join
* after bind(). */
int wins2003_or_later = detect_windows_server_2003_or_later();
#endif

fprintf(stderr, "-3\n");
// Set real protocol, if Default is requested
if (proto == LO_DEFAULT) {
#if !defined(WIN32) && !defined(_MSC_VER)
Expand All @@ -469,11 +470,12 @@ lo_server lo_server_new_with_proto_internal(const char *group,
#endif
proto = LO_UDP;
}
fprintf(stderr, "-2\n");
#if defined(WIN32) || defined(_MSC_VER)
if (!initWSock())
return NULL;
#endif

fprintf(stderr, "-1\n");
s = (lo_server) calloc(1, sizeof(struct _lo_server));
if (!s)
return 0;
Expand All @@ -499,15 +501,15 @@ lo_server lo_server_new_with_proto_internal(const char *group,
s->bundle_handler_user_data = NULL;
s->addr_if.iface = 0;
s->addr_if.size = 0;

fprintf(stderr, "0\n");
if (!(s->sockets && s->contexts && s->sources)) {
free(s->sockets);
free(s->contexts);
free(s->sources);
free(s);
return 0;
}

fprintf(stderr, "1\n");
s->sockets[0].fd = -1;
s->max_msg_size = LO_DEFAULT_MAX_MSG_SIZE;

Expand Down Expand Up @@ -556,7 +558,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,

return NULL;
}

fprintf(stderr, "2\n");
#ifdef ENABLE_IPV6
/* Determine the address family based on provided IP string or
multicast group, if available, otherwise let the operating
Expand All @@ -577,6 +579,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
service = port;
}
do {
fprintf(stderr, "3\n");
int ret;
if (!port) {
/* not a good way to get random numbers, but its not critical */
Expand Down Expand Up @@ -604,7 +607,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
for (it = ai; it && s->sockets[0].fd == -1; it = it->ai_next) {
used = it;
s->sockets[0].fd = socket(it->ai_family, hints.ai_socktype, 0);

fprintf(stderr, "4\n");
if (s->sockets[0].fd != -1
&& it->ai_family == AF_INET
&& hints.ai_socktype == SOCK_DGRAM)
Expand All @@ -624,7 +627,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
lo_server_free(s);
return NULL;
}

fprintf(stderr, "5\n");
#ifdef ENABLE_IPV6
unsigned int v6only_off = 0;
if (setsockopt(s->sockets[0].fd, IPPROTO_IPV6, IPV6_V6ONLY,
Expand Down Expand Up @@ -675,7 +678,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
}
#endif
}}

fprintf(stderr, "6\n");
if ((used != NULL) &&
(bind(s->sockets[0].fd, used->ai_addr, used->ai_addrlen) <
0)) {
Expand All @@ -695,7 +698,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
return NULL;
}
} while (!used && tries++ < 16);

fprintf(stderr, "7\n");
if (!used) {
lo_throw(s, LO_NOPORT, "cannot find free port", NULL);

Expand Down Expand Up @@ -732,7 +735,7 @@ lo_server lo_server_new_with_proto_internal(const char *group,
lo_throw(s, LO_UNKNOWNPROTO, "unknown protocol family", NULL);
s->port = atoi(port);
}

fprintf(stderr, "8\n");
return s;
}

Expand Down Expand Up @@ -1645,10 +1648,13 @@ int lo_server_recv(lo_server s)

again:
if (sched_time > 0.01) {
fprintf(stderr, "r1\n");
if (sched_time > 10.0) {
fprintf(stderr, "r2\n");
sched_time = 10.0;
}
#ifdef HAVE_POLL
fprintf(stderr, "r3\n");
for (i = 0; i < s->sockets_len; i++) {
s->sockets[i].events = POLLIN | POLLPRI | POLLERR | POLLHUP;
s->sockets[i].revents = 0;
Expand All @@ -1660,9 +1666,12 @@ int lo_server_recv(lo_server s)
goto got_data;
}
}
fprintf(stderr, "r4\n");

poll(s->sockets, s->sockets_len, (int) (sched_time * 1000.0));

fprintf(stderr, "r5\n");

for (i = 0; i < s->sockets_len; i++) {
if (!s->sockets[i].revents)
continue;
Expand All @@ -1676,6 +1685,8 @@ int lo_server_recv(lo_server s)
}
break;
}

fprintf(stderr, "r6\n");

if (i >= s->sockets_len) {
sched_time = lo_server_next_event_delay(s);
Expand All @@ -1685,13 +1696,14 @@ int lo_server_recv(lo_server s)

return dispatch_queued(s, 0);
}
fprintf(stderr, "r7\n");
#else
#ifdef HAVE_SELECT
#if defined(WIN32) || defined(_MSC_VER)
if (!initWSock())
return 0;
#endif

fprintf(stderr, "r8\n");
FD_ZERO(&ps);
for (i = 0; i < s->sockets_len; i++) {
FD_SET(s->sockets[i].fd, &ps);
Expand All @@ -1706,14 +1718,14 @@ int lo_server_recv(lo_server s)
goto got_data;
}
}

fprintf(stderr, "r9\n");
stimeout.tv_sec = sched_time;
stimeout.tv_usec = (sched_time - stimeout.tv_sec) * 1.e6;
res = select(nfds + 1, &ps, NULL, NULL, &stimeout);
if (res == SOCKET_ERROR) {
return 0;
}

fprintf(stderr, "r10\n");
if (!res) {
sched_time = lo_server_next_event_delay(s);

Expand All @@ -1722,25 +1734,31 @@ int lo_server_recv(lo_server s)

return dispatch_queued(s, 0);
}
fprintf(stderr, "r11\n");
#endif
#endif
} else {
fprintf(stderr, "r12\n");
return dispatch_queued(s, 0);
}
if (s->protocol == LO_TCP) {
fprintf(stderr, "r13\n");
data = lo_server_recv_raw_stream(s, &size, &sock);
} else {
data = lo_server_recv_raw(s, &size);
}
fprintf(stderr, "r14\n");

if (!data) {
return 0;
}
got_data:
fprintf(stderr, "r15\n");
if (dispatch_data(s, data, size, sock) < 0) {
free(data);
return -1;
}
fprintf(stderr, "r16\n");
free(data);
return (int) size;
}
Expand Down
Loading

0 comments on commit 8dc5055

Please sign in to comment.