Skip to content

Commit

Permalink
Various tweaks to better support Windows.
Browse files Browse the repository at this point in the history
The socket timeouts did not function properly on Windows.  After some
testing, I've added some changes so that they do work.

While this will be part of the next version of `aprs-weather-submit`,
I've applied them to the v1.8.1 binaries.
  • Loading branch information
rhymeswithmogul committed Nov 4, 2024
1 parent 73d925b commit a627077
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log for `aprs-weather-submit`

## Next version
- Fixed a bug where v1.8.1 would not handle timeouts correctly using the Win32 API. The changes are queued for the next version, though I've already included them in the released binaries.

## Version 1.8.1
<time datetime="2024-11-03">November 3, 2024</time>
Fixed a bug where compilation would fail on `armhf` platforms due to an improper cast when `printf()`-ing a `time_t`. It's a `long long int` on that platform, while `printf()` was expecting a `long int` instead.
Expand Down
7 changes: 7 additions & 0 deletions src/aprs-is.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
#else /* _WIN32 */
#include <winsock2.h> /* all that socket stuff on Windows */
#include <ws2tcpip.h> /* inet_pton(), only available on Windows Vista and up */
#include <stdint.h> /* intmax_t */
#endif /* _WIN32 */

/**
Expand Down Expand Up @@ -176,11 +177,17 @@ sendPacket (const char* const restrict server,
want to wait forever (like v1.7.2 and older). */
if (timeout > 0)
{
#ifndef _WIN32
struct timeval socket_timeout;
socket_timeout.tv_sec = timeout;
socket_timeout.tv_usec = 0;
setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, &socket_timeout, sizeof(socket_timeout));
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, &socket_timeout, sizeof(socket_timeout));
#else
DWORD socket_timeout = timeout * 1000;
setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&socket_timeout, sizeof(socket_timeout));
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&socket_timeout, sizeof(socket_timeout));
#endif
}

if (connect(socket_desc, addressinfo, (size_t)(result->ai_addrlen)) >= 0)
Expand Down

0 comments on commit a627077

Please sign in to comment.