Skip to content

Commit 8d64ea7

Browse files
committed
compat/platform_{sched,pipe} can be C
+ fixed includes in rtp/net_udp.h (stdint.h needed to be included for platform_pipe.c to compile in MSW now)
1 parent de63fbe commit 8d64ea7

6 files changed

Lines changed: 39 additions & 23 deletions

File tree

gui/QT/uv-qt.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@ SOURCES += window/ultragrid_window.cpp \
112112
../../tools/astat.cpp \
113113
../../tools/ipc_frame.cpp \
114114
../../tools/ipc_frame_unix.cpp \
115-
../../src/compat/platform_pipe.cpp \
115+
../../src/compat/platform_pipe.c \
116116
../../src/utils/string_view_utils.cpp \
117117
main.cpp
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
@@ -37,19 +37,19 @@
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;

src/compat/platform_pipe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define platform_pipe_h
4040

4141
#ifndef _WIN32
42-
#include <unistd.h> //for read, write
42+
#include <unistd.h> // for read, write // IWYU pragma: keep
4343
#endif
4444
#include "compat/net.h" //for fd_t
4545

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <sched.h>
99

1010
bool set_realtime_sched_this_thread(){
11-
sched_param p = {};
11+
struct sched_param p = { 0 };
1212

1313
int policy = SCHED_RR;
1414
p.sched_priority = sched_get_priority_max(policy);

src/compat/platform_sched.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#ifndef PLATFORM_SCEHD_H_41e7a5bebbfc
22
#define PLATFORM_SCEHD_H_41e7a5bebbfc
33

4+
#if !defined __cplusplus
5+
#include <stdbool.h>
6+
#endif // !defined __cplusplus
7+
48
#ifdef __cplusplus
59
extern "C" {
610
#endif
711

8-
bool set_realtime_sched_this_thread();
12+
bool set_realtime_sched_this_thread(void);
913

1014
#ifdef __cplusplus
1115
}

src/rtp/net_udp.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* AUTHORS: Colin Perkins
44
*
55
* Copyright (c) 1998-2000 University College London
6-
* Copyright (c) 2005-2021 CESNET, z. s. p. o.
6+
* Copyright (c) 2005-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
@@ -42,11 +42,22 @@
4242

4343
#include "compat/net.h"
4444

45-
#ifndef __cplusplus
45+
#ifdef __cplusplus
46+
#include <cstdint>
47+
#else
4648
#include <stdbool.h>
49+
#include <stdint.h>
50+
#endif
51+
52+
#ifdef _WIN32
53+
#include <winsock2.h> // for fd_set
54+
#else
55+
#include <sys/select.h> // for fd_set
4756
#endif
4857

4958
typedef struct _socket_udp socket_udp;
59+
struct iovec;
60+
struct timeval;
5061
struct socket_udp_local;
5162

5263
#if defined(__cplusplus)

0 commit comments

Comments
 (0)