Skip to content

Commit

Permalink
Fix windows socket timeout value (#411)
Browse files Browse the repository at this point in the history
* fix: replace windows sockopt timeout value type

* fix: void functions returning value
  • Loading branch information
jean-roland authored May 15, 2024
1 parent 6528094 commit aa46390
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/deprecated/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ uint8_t zp_random_u8(void) { return z_random_u8(); };
uint16_t zp_random_u16(void) { return z_random_u16(); };
uint32_t zp_random_u32(void) { return z_random_u32(); };
uint64_t zp_random_u64(void) { return z_random_u64(); };
void zp_random_fill(void *buf, size_t len) { return z_random_fill(buf, len); };
void zp_random_fill(void *buf, size_t len) { z_random_fill(buf, len); };

void *zp_malloc(size_t size) { return z_malloc(size); };
void *zp_realloc(void *ptr, size_t size) { return z_realloc(ptr, size); };
void zp_free(void *ptr) { return z_free(ptr); };
void zp_free(void *ptr) { z_free(ptr); };

#if Z_FEATURE_MULTI_THREAD == 1

int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) {
return z_task_init(task, attr, fun, arg);
};
int8_t zp_task_join(zp_task_t *task) { return z_task_join(task); };
void zp_task_free(zp_task_t **task) { return z_task_free(task); };
void zp_task_free(zp_task_t **task) { z_task_free(task); };

int8_t zp_mutex_init(zp_mutex_t *m) { return z_mutex_init(m); };
int8_t zp_mutex_free(zp_mutex_t *m) { return z_mutex_free(m); };
Expand Down
17 changes: 4 additions & 13 deletions src/system/windows/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u

sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol);
if (sock->_sock._fd != INVALID_SOCKET) {
z_time_t tv;
tv.time = tout / (uint32_t)1000;
tv.millitm = tout % (uint32_t)1000;
DWORD tv = tout;
if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) {
ret = _Z_ERR_GENERIC;
}
Expand Down Expand Up @@ -200,13 +198,10 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_

sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol);
if (sock->_sock._fd != INVALID_SOCKET) {
z_time_t tv;
tv.time = tout / (uint32_t)1000;
tv.millitm = tout % (uint32_t)1000;
DWORD tv = tout;
if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) {
ret = _Z_ERR_GENERIC;
}

if (ret != _Z_RES_OK) {
closesocket(sock->_sock._fd);
WSACleanup();
Expand Down Expand Up @@ -326,9 +321,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin
if (addrlen != 0U) {
sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol);
if (sock->_sock._fd != INVALID_SOCKET) {
z_time_t tv;
tv.time = tout / (uint32_t)1000;
tv.millitm = tout % (uint32_t)1000;
DWORD tv = tout;
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) {
ret = _Z_ERR_GENERIC;
Expand Down Expand Up @@ -430,9 +423,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo
if (addrlen != 0U) {
sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol);
if (sock->_sock._fd != INVALID_SOCKET) {
z_time_t tv;
tv.time = tout / (uint32_t)1000;
tv.millitm = tout % (uint32_t)1000;
DWORD tv = tout;
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) {
ret = _Z_ERR_GENERIC;
Expand Down

0 comments on commit aa46390

Please sign in to comment.