Skip to content

Commit 823ed61

Browse files
committed
Fix the nopoll version of the POSIX TCP transport profile
This commit fixes the socket type used with getaddrinfo(). It was SOCK_DGRAM, but it should be SOCK_STREAM for TCP. Additionally, it adds a signal handler for SIGPIPE on Linux, similar to the polling implementation. Signed-off-by: J. S. Seldenthuis <[email protected]>
1 parent e3f6439 commit 823ed61

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/c/profile/transport/ip/tcp/tcp_transport_posix_nopoll.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88
#include <unistd.h>
99
#include <string.h>
1010
#include <errno.h>
11+
#include <signal.h>
12+
13+
#ifdef UCLIENT_PLATFORM_LINUX
14+
static void sigpipe_handler(
15+
int fd)
16+
{
17+
(void)fd;
18+
}
19+
20+
#endif /* ifdef UCLIENT_PLATFORM_LINUX */
1121

1222
bool uxr_init_tcp_platform(
13-
uxrTCPPlatform* platform,
23+
struct uxrTCPPlatform* platform,
1424
uxrIpProtocol ip_protocol,
1525
const char* ip,
1626
const char* port)
@@ -29,6 +39,9 @@ bool uxr_init_tcp_platform(
2939

3040
if (-1 != platform->fd)
3141
{
42+
#ifdef UCLIENT_PLATFORM_LINUX
43+
signal(SIGPIPE, sigpipe_handler);
44+
#endif /* ifdef UCLIENT_PLATFORM_LINUX */
3245
struct addrinfo hints;
3346
struct addrinfo* result;
3447
struct addrinfo* ptr;
@@ -43,7 +56,7 @@ bool uxr_init_tcp_platform(
4356
hints.ai_family = AF_INET6;
4457
break;
4558
}
46-
hints.ai_socktype = SOCK_DGRAM;
59+
hints.ai_socktype = SOCK_STREAM;
4760

4861
if (0 == getaddrinfo(ip, port, &hints, &result))
4962
{
@@ -62,13 +75,13 @@ bool uxr_init_tcp_platform(
6275
}
6376

6477
bool uxr_close_tcp_platform(
65-
uxrTCPPlatform* platform)
78+
struct uxrTCPPlatform* platform)
6679
{
6780
return (-1 == platform->fd) ? true : (0 == close(platform->fd));
6881
}
6982

7083
size_t uxr_write_tcp_data_platform(
71-
uxrTCPPlatform* platform,
84+
struct uxrTCPPlatform* platform,
7285
const uint8_t* buf,
7386
size_t len,
7487
uint8_t* errcode)
@@ -88,7 +101,7 @@ size_t uxr_write_tcp_data_platform(
88101
}
89102

90103
size_t uxr_read_tcp_data_platform(
91-
uxrTCPPlatform* platform,
104+
struct uxrTCPPlatform* platform,
92105
uint8_t* buf,
93106
size_t len,
94107
int timeout,

0 commit comments

Comments
 (0)