Skip to content

Commit 78fdfbe

Browse files
committed
net: dedup MSG_NOSIGNAL and MSG_DONTWAIT definitions
Deduplicate `MSG_NOSIGNAL` and `MSG_DONTWAIT` definitions from `net.cpp` and `netbase.cpp` to `compat.h` where they can also be reused by other code.
1 parent 34bcfab commit 78fdfbe

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/compat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,14 @@ bool static inline IsSelectableSocket(const SOCKET& s) {
9696
#endif
9797
}
9898

99+
// MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define it as 0
100+
#if !defined(MSG_NOSIGNAL)
101+
#define MSG_NOSIGNAL 0
102+
#endif
103+
104+
// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0
105+
#if !defined(MSG_DONTWAIT)
106+
#define MSG_DONTWAIT 0
107+
#endif
108+
99109
#endif // BITCOIN_COMPAT_H

src/net.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <banman.h>
1313
#include <clientversion.h>
14+
#include <compat.h>
1415
#include <consensus/consensus.h>
1516
#include <crypto/sha256.h>
1617
#include <net_permissions.h>
@@ -72,16 +73,6 @@ static constexpr std::chrono::seconds MAX_UPLOAD_TIMEFRAME{60 * 60 * 24};
7273
// We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
7374
#define FEELER_SLEEP_WINDOW 1
7475

75-
// MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define it as 0
76-
#if !defined(MSG_NOSIGNAL)
77-
#define MSG_NOSIGNAL 0
78-
#endif
79-
80-
// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0
81-
#if !defined(MSG_DONTWAIT)
82-
#define MSG_DONTWAIT 0
83-
#endif
84-
8576
/** Used to pass flags to the Bind() function */
8677
enum BindFlags {
8778
BF_NONE = 0,

src/netbase.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <netbase.h>
77

8+
#include <compat.h>
89
#include <sync.h>
910
#include <tinyformat.h>
1011
#include <util/sock.h>
@@ -30,10 +31,6 @@
3031
#include <poll.h>
3132
#endif
3233

33-
#if !defined(MSG_NOSIGNAL)
34-
#define MSG_NOSIGNAL 0
35-
#endif
36-
3734
// Settings
3835
static Mutex g_proxyinfo_mutex;
3936
static proxyType proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);

0 commit comments

Comments
 (0)