33 * @author Martin Pulec <pulec@cesnet.cz>
44 */
55/*
6- * Copyright (c) 2015-2021 CESNET, z. s. p. o.
6+ * Copyright (c) 2015-2026 CESNET, zájmové sdružení právnických osob
77 * All rights reserved.
88 *
99 * Redistribution and use in source and binary forms, with or without
3737
3838#include "compat/platform_pipe.h"
3939
40- #include < cstdio> // for perror, NULL, fprintf, stderr
41- #include < cstring> // for memset
40+ #include <pthread.h> // for pthread_t
41+ #include <stdio.h> // for perror, NULL, fprintf, stderr
42+ #include <string.h> // for memset
4243#include <sys/time.h> // for timeval
43- #include < thread>
4444
4545#ifndef _WIN32
4646#include <unistd.h> // for pipe
4747#endif
4848
49- #include " rtp/net_udp .h" // socket_error
49+ #include "compat/c23 .h"
5050#include "compat/net.h" // htons etc.
51+ #include "rtp/net_udp.h" // socket_error
5152
52- using std::thread;
5353
5454#ifdef _WIN32
5555#define DECLARE_TIMEOUT (name , init_val_s ) DWORD name = init_val_s * 1000
@@ -76,7 +76,7 @@ static fd_t open_socket(int *port)
7676 s_in .sin_family = AF_INET ;
7777 s_in .sin_addr .s_addr = htonl (INADDR_ANY );
7878 s_in .sin_port = htons (0 );
79- if (:: bind (sock, (const struct sockaddr *) &s_in,
79+ if (bind (sock , (const struct sockaddr * ) & s_in ,
8080 sizeof (s_in )) != 0 ) {
8181 CLOSESOCKET (sock );
8282 return INVALID_SOCKET ;
@@ -110,10 +110,10 @@ static fd_t connect_to_socket(int local_port)
110110 DECLARE_TIMEOUT (timeout , 1 );
111111 DECLARE_TIMEOUT (old_timeout , 0 );
112112 socklen_t old_timeout_len = sizeof old_timeout ;
113- if (getsockopt (fd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast < sockopt_t >( &old_timeout) , &old_timeout_len) != 0 ) {
113+ if (getsockopt (fd , SOL_SOCKET , SO_SNDTIMEO , ( sockopt_t ) & old_timeout , & old_timeout_len ) != 0 ) {
114114 socket_error ("pipe getsockopt" );
115115 }
116- if (setsockopt (fd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast < sockopt_t >( &timeout) , sizeof timeout) != 0 ) {
116+ if (setsockopt (fd , SOL_SOCKET , SO_SNDTIMEO , ( sockopt_t ) & timeout , sizeof timeout ) != 0 ) {
117117 socket_error ("pipe setsockopt" );
118118 }
119119 ret = connect (fd , (struct sockaddr * ) & s_in ,
@@ -123,7 +123,7 @@ static fd_t connect_to_socket(int local_port)
123123 CLOSESOCKET (fd );
124124 return INVALID_SOCKET ;
125125 }
126- if (setsockopt (fd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast < sockopt_t >( &old_timeout) , old_timeout_len) != 0 ) {
126+ if (setsockopt (fd , SOL_SOCKET , SO_SNDTIMEO , ( sockopt_t ) & old_timeout , old_timeout_len ) != 0 ) {
127127 socket_error ("pipe setsockopt" );
128128 }
129129
@@ -186,7 +186,7 @@ int platform_pipe_init(fd_t p[2])
186186 }
187187#endif
188188
189- struct params par{ };
189+ struct params par = { 0 };
190190 fd_t sock = open_socket (& par .port );
191191 if (sock == INVALID_SOCKET ) {
192192 perror ("open_socket" );
@@ -196,24 +196,25 @@ int platform_pipe_init(fd_t p[2])
196196 DECLARE_TIMEOUT (timeout , 1 );
197197 DECLARE_TIMEOUT (old_timeout , 0 );
198198 socklen_t old_timeout_len = sizeof old_timeout ;
199- if (getsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast < sockopt_t >( &old_timeout) , &old_timeout_len) != 0 ) {
199+ if (getsockopt (sock , SOL_SOCKET , SO_RCVTIMEO , ( sockopt_t ) & old_timeout , & old_timeout_len ) != 0 ) {
200200 socket_error ("pipe getsockopt" );
201201 }
202- if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast < sockopt_t >( &timeout) , sizeof timeout) != 0 ) {
202+ if (setsockopt (sock , SOL_SOCKET , SO_RCVTIMEO , ( sockopt_t ) & timeout , sizeof timeout ) != 0 ) {
203203 socket_error ("pipe setsockopt" );
204204 }
205205
206- thread thr (worker, &par);
206+ pthread_t thread_id ;
207+ pthread_create (& thread_id , nullptr , worker , & par );
207208
208209 p [0 ] = accept (sock , NULL , NULL );
209210 if (p [0 ] == INVALID_SOCKET ) {
210211 perror ("pipe accept" );
211- thr. join ( );
212+ pthread_join ( thread_id , nullptr );
212213 CLOSESOCKET (sock );
213214 return system_pipe (p );
214215 }
215- thr. join ( );
216- if (setsockopt (p[0 ], SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast < sockopt_t >( &old_timeout) , old_timeout_len) != 0 ) {
216+ pthread_join ( thread_id , nullptr );
217+ if (setsockopt (p [0 ], SOL_SOCKET , SO_RCVTIMEO , ( sockopt_t ) & old_timeout , old_timeout_len ) != 0 ) {
217218 socket_error ("pipe setsockopt" );
218219 }
219220 p [1 ] = par .sock ;
0 commit comments