You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
3 years ago
|
From 5dc2d2261224c9533d2b5ec4df6ed822de4cfc3b Mon Sep 17 00:00:00 2001
|
||
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
||
|
Date: Thu, 4 Feb 2021 17:57:06 +0000
|
||
|
Subject: [PATCH] generator: Refactor CONNECT.START state.
|
||
|
|
||
|
Small, neutral refactoring to the CONNECT.START to make the subsequent
|
||
|
commit easier.
|
||
|
|
||
|
(cherry picked from commit cd231fd94bbfaacdd9b89e7d355ba2bbc83c2aeb)
|
||
|
---
|
||
|
generator/states-connect.c | 21 ++++++++++-----------
|
||
|
1 file changed, 10 insertions(+), 11 deletions(-)
|
||
|
|
||
|
diff --git a/generator/states-connect.c b/generator/states-connect.c
|
||
|
index 392879d..03b34c7 100644
|
||
|
--- a/generator/states-connect.c
|
||
|
+++ b/generator/states-connect.c
|
||
|
@@ -47,11 +47,12 @@ disable_nagle (int sock)
|
||
|
|
||
|
STATE_MACHINE {
|
||
|
CONNECT.START:
|
||
|
- int fd;
|
||
|
+ sa_family_t family;
|
||
|
+ int fd, r;
|
||
|
|
||
|
assert (!h->sock);
|
||
|
- fd = socket (h->connaddr.ss_family,
|
||
|
- SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
|
||
|
+ family = h->connaddr.ss_family;
|
||
|
+ fd = socket (family, SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
|
||
|
if (fd == -1) {
|
||
|
SET_NEXT_STATE (%.DEAD);
|
||
|
set_error (errno, "socket");
|
||
|
@@ -65,14 +66,12 @@ STATE_MACHINE {
|
||
|
|
||
|
disable_nagle (fd);
|
||
|
|
||
|
- if (connect (fd, (struct sockaddr *) &h->connaddr,
|
||
|
- h->connaddrlen) == -1) {
|
||
|
- if (errno != EINPROGRESS) {
|
||
|
- SET_NEXT_STATE (%.DEAD);
|
||
|
- set_error (errno, "connect");
|
||
|
- return 0;
|
||
|
- }
|
||
|
- }
|
||
|
+ r = connect (fd, (struct sockaddr *) &h->connaddr, h->connaddrlen);
|
||
|
+ if (r == 0 || (r == -1 && errno == EINPROGRESS))
|
||
|
+ return 0;
|
||
|
+ assert (r == -1);
|
||
|
+ SET_NEXT_STATE (%.DEAD);
|
||
|
+ set_error (errno, "connect");
|
||
|
return 0;
|
||
|
|
||
|
CONNECT.CONNECTING:
|
||
|
--
|
||
|
2.31.1
|
||
|
|