Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions runtime/streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,15 @@ Optional<int64_t> f$stream_select(mixed& read, mixed& write, mixed& except, cons
return false;
}

// TODO use pselect
struct timespec ts, *timeout_ts = nullptr;
if (timeout) {
ts.tv_sec = timeout->tv_sec;
ts.tv_nsec = static_cast<long>(timeout->tv_usec) * 1000;
timeout_ts = &ts;
}

dl::enter_critical_section(); // OK
int32_t select_result = select(nfds + 1, &rfds, &wfds, &efds, timeout);
int32_t select_result = pselect(nfds + 1, &rfds, &wfds, &efds, timeout_ts, nullptr);
dl::leave_critical_section();

if (select_result == -1) {
Expand Down
3 changes: 2 additions & 1 deletion tests/cpp/runtime/runtime-tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ prepend(RUNTIME_TESTS_SOURCES ${BASE_DIR}/tests/cpp/runtime/
memory_resource/unsynchronized_pool_resource-test.cpp
string-list-test.cpp
string-test.cpp
zstd-test.cpp)
zstd-test.cpp
stream-select-test.cpp)

allow_deprecated_declarations_for_apple(${BASE_DIR}/tests/cpp/runtime/inter-process-mutex-test.cpp)
vk_add_unittest(runtime "${RUNTIME_LIBS};${RUNTIME_LINK_TEST_LIBS}" ${RUNTIME_TESTS_SOURCES})
22 changes: 22 additions & 0 deletions tests/cpp/runtime/stream-select-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <gtest/gtest.h>
#include "runtime/streams.h"
#include "runtime/critical_section.h"

TEST(stream_select, udp_writable) {
mixed err_no;
mixed err_desc;
Stream udp_stream = f$stream_socket_client(
CONST_STRING("udp://127.0.0.1:9"), err_no, err_desc, 1.0);

ASSERT_TRUE(f$boolval(udp_stream));

mixed read_arr = array<Stream>();
mixed write_arr = array<Stream>::create(udp_stream);
mixed except_arr = array<Stream>();

Optional<int64_t> res = f$stream_select(read_arr, write_arr, except_arr, 0, 0);
ASSERT_TRUE(res.has_value());
ASSERT_EQ(res.val(), 1);

f$fclose(udp_stream);
}