Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 01c051e

Browse files
committed
more portable way to switch socket to nonblock mode
1 parent 3ebf193 commit 01c051e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

contrib/mmts/arbiter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <errno.h>
1717
#include <netdb.h>
1818
#include <time.h>
19+
#include <fcntl.h>
1920

2021
#include "postgres.h"
2122
#include "fmgr.h"
@@ -380,10 +381,11 @@ static int MtmConnectSocket(char const* host, int port, int max_attempts)
380381
while (1) {
381382
int rc = -1;
382383

383-
sd = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0);
384+
sd = socket(AF_INET, SOCK_STREAM, 0);
384385
if (sd < 0) {
385386
elog(ERROR, "Arbiter failed to create socket: %d", errno);
386387
}
388+
fcntl(sd, F_SETFL, O_NONBLOCK);
387389
busy_socket = sd;
388390
for (i = 0; i < n_addrs; ++i) {
389391
memcpy(&sock_inet.sin_addr, &addrs[i], sizeof sock_inet.sin_addr);

contrib/raftable/raftable.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <arpa/inet.h>
2929

3030
#include <unistd.h>
31+
#include <fcntl.h>
3132
#include <time.h>
3233

3334
void _PG_init(void);
@@ -194,12 +195,13 @@ static bool connect_leader(timeout_t *timeout)
194195
{
195196
int one = 1;
196197

197-
sd = socket(a->ai_family, SOCK_STREAM | SOCK_NONBLOCK, 0);
198+
sd = socket(a->ai_family, SOCK_STREAM, 0);
198199
if (sd == -1)
199200
{
200201
elog(WARNING, "failed to create a socket: %s", strerror(errno));
201202
continue;
202203
}
204+
fcntl(sd, F_SETFL, O_NONBLOCK);
203205
setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
204206

205207
if (connect(sd, a->ai_addr, a->ai_addrlen) == -1)

0 commit comments

Comments
 (0)