Skip to content
Closed
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
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,20 @@ endif()
add_library(iio_common_config INTERFACE)

if (MSVC)
target_compile_options(iio_common_config INTERFACE /Zi /W4 /wd4200 /wd4127 /wd4100)
# Zi produces a separate PDB file that contains all the symbolic debugging information
# W4 displays level 1, 2, 3, and 4 (informational) warnings that aren't off by default
# C4200: nonstandard extension used : zero-sized array in struct (usb.h)
# C4127: conditional expression is constant (IIO_ERROR and IIO_DEBUG macros)
# C4100: unreferenced parameter; same as -Wno-unused-parameter
string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

target_compile_options(iio_common_config INTERFACE
/Zi /W4 /wd4200 /wd4127 /wd4100

# Apply /O1 and /Ob1 for dead code elimination.
# We also manually add /RTC1 back ONLY if we are NOT using /O1.
# But for your case, we want /O1 in Debug:
$<$<CONFIG:Debug>:/O1 /Ob1>
)
target_link_options(iio_common_config INTERFACE
$<$<CONFIG:Debug>:/OPT:REF /INCREMENTAL:NO>
)

set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
Expand Down
37 changes: 36 additions & 1 deletion network-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ int set_blocking_mode(int s, bool blocking)

int setup_cancel(struct iiod_client_pdata *io_ctx)
{
CRITICAL_SECTION *lock;

io_ctx->events[0] = WSACreateEvent();
if (io_ctx->events[0] == WSA_INVALID_EVENT)
return -ENOMEM; /* Pretty much the only error that can happen */
Expand All @@ -42,11 +44,26 @@ int setup_cancel(struct iiod_client_pdata *io_ctx)
return -ENOMEM;
}

lock = malloc(sizeof(*lock));
if (!lock) {
WSACloseEvent(io_ctx->events[0]);
WSACloseEvent(io_ctx->events[1]);
return -ENOMEM;
}

InitializeCriticalSection(lock);
io_ctx->event_lock = lock;
io_ctx->read_waiters = 0;
io_ctx->write_waiters = 0;

return 0;
}

void cleanup_cancel(struct iiod_client_pdata *io_ctx)
{
CRITICAL_SECTION *lock = io_ctx->event_lock;
DeleteCriticalSection(lock);
free(lock);
WSACloseEvent(io_ctx->events[0]);
WSACloseEvent(io_ctx->events[1]);
}
Expand All @@ -59,21 +76,39 @@ void do_cancel(struct iiod_client_pdata *io_ctx)
int wait_cancellable(struct iiod_client_pdata *io_ctx,
bool read, unsigned int timeout_ms)
{
CRITICAL_SECTION *lock = io_ctx->event_lock;
long wsa_events = FD_CLOSE;
DWORD ret, timeout = timeout_ms > 0 ? (DWORD) timeout_ms : WSA_INFINITE;

EnterCriticalSection(lock);
if (read)
wsa_events |= FD_READ;
io_ctx->read_waiters++;
else
io_ctx->write_waiters++;

if (io_ctx->read_waiters > 0)
wsa_events |= FD_READ;
if (io_ctx->write_waiters > 0)
wsa_events |= FD_WRITE;

printf("\nwait_cancellable: read=%d, timeout_ms=%u, fd=0x%d\n\n",
read, timeout_ms, io_ctx->fd);
WSAEventSelect(io_ctx->fd, NULL, 0);
WSAResetEvent(io_ctx->events[0]);
WSAEventSelect(io_ctx->fd, io_ctx->events[0], wsa_events);

LeaveCriticalSection(lock);

ret = WSAWaitForMultipleEvents(2, io_ctx->events, FALSE,
timeout, FALSE);

EnterCriticalSection(lock);
if (read)
io_ctx->read_waiters--;
else
io_ctx->write_waiters--;
LeaveCriticalSection(lock);

if (ret == WSA_WAIT_TIMEOUT)
return -ETIMEDOUT;

Expand Down
7 changes: 6 additions & 1 deletion network.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ struct addrinfo;

struct iiod_client_pdata {
int fd;


#ifdef _WIN32
void *event_lock;
int read_waiters;
int write_waiters;
#endif
bool cancelled;
void * events[2];
int cancel_fd[2];
Expand Down
Loading