From: "Torsten Bögershausen" <tboegi@web.de>
To: ramsay@ramsay1.demon.co.uk, mlevedahl@gmail.com, git@vger.kernel.org
Subject: [PATCH] CYGWIN: Use a TCP socket for pipe()
Date: Thu, 27 Jun 2013 18:31:13 +0200 [thread overview]
Message-ID: <201306271831.13865.tboegi@web.de> (raw)
Work around issues that git hangs when doing fetch or pull under
various protocols under CYGWIN.
Replace pipe() with a socket connection using a TCP/IP.
Introduce a new function socket_pipe() in compat/socket_pipe.c
Re-define the pipe() function into socket_pipe() for CYGWIN.
(This redefinition does not work for MinGW, because here a socket can
not be mixed with a file handle)
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
compat/socket_pipe.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
config.mak.uname | 2 ++
git-compat-util.h | 4 ++++
3 files changed, 74 insertions(+)
create mode 100644 compat/socket_pipe.c
diff --git a/compat/socket_pipe.c b/compat/socket_pipe.c
new file mode 100644
index 0000000..eee43b5
--- /dev/null
+++ b/compat/socket_pipe.c
@@ -0,0 +1,68 @@
+#include "git-compat-util.h"
+
+int socket_pipe(int filedes[2])
+{
+ int fd_listen, fd_rd;
+ int fd_wr = -1;
+ struct sockaddr_in sin;
+ socklen_t length;
+ struct linger linger;
+ int reuse_on = 1;
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ fd_listen = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd_listen == -1)
+ die_errno("pipe fd_listen socket");
+ (void)setsockopt(fd_listen, SOL_SOCKET, SO_REUSEADDR,
+ (char*)&reuse_on, sizeof(reuse_on));
+ if (bind(fd_listen, (struct sockaddr *)&sin, sizeof(sin)))
+ die_errno("pipe bind socket");
+
+ length = sizeof(sin);
+ if(getsockname(fd_listen, (struct sockaddr *)&sin, &length))
+ die_errno("pipe getsockname");
+ if (listen(fd_listen, SOMAXCONN))
+ die_errno("pipe listen");
+ fd_rd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd_rd == -1)
+ die_errno("pipe fd_rd socket");
+ if (connect(fd_rd, (struct sockaddr *)&sin, sizeof(sin)))
+ die_errno("pipe connect");
+
+ length = sizeof(struct sockaddr);
+ if(getsockname(fd_rd, (struct sockaddr *)&sin, &length))
+ die_errno("pipe getsockname");
+
+ while (fd_wr == -1) {
+ struct sockaddr_in sacc;
+ length = sizeof(sacc);
+ memset(&sacc, 0, sizeof(sacc));
+ fd_wr = accept(fd_listen, (struct sockaddr *)&sacc, &length);
+ if(fd_wr == -1)
+ die_errno("pipe accept");
+ if (sacc.sin_port != sin.sin_port) {
+ // Wrong connecting socket
+ close(fd_wr);
+ fd_wr = -1;
+ }
+ }
+
+ close(fd_listen);
+
+ linger.l_onoff = 1;
+ linger.l_linger = 5;
+ if (setsockopt(fd_wr, SOL_SOCKET, SO_LINGER,
+ (char*)&linger, sizeof(linger)))
+ die_errno("pipe socket linger");
+ if (shutdown(fd_rd, SHUT_WR))
+ die_errno("pipe socket shutdown fd_rd");
+ if (shutdown(fd_wr, SHUT_RD))
+ die_errno("pipe socket shutdown fd_wr");
+
+ filedes[0] = fd_rd;
+ filedes[1] = fd_wr;
+ return 0;
+}
diff --git a/config.mak.uname b/config.mak.uname
index d78fd3d..66bf446 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -170,7 +170,9 @@ ifeq ($(uname_O),Cygwin)
# Try commenting this out if you suspect MMAP is more efficient
NO_MMAP = YesPlease
X = .exe
+ BASIC_CFLAGS += -DGIT_USE_SOCKET_PIPE
COMPAT_OBJS += compat/cygwin.o
+ COMPAT_OBJS += compat/socket_pipe.o
UNRELIABLE_FSTAT = UnfortunatelyYes
SPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield
endif
diff --git a/git-compat-util.h b/git-compat-util.h
index c1f8a47..88632ab 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -176,6 +176,10 @@ int get_st_mode_bits(const char *path, int *mode);
#endif
#endif
+int socket_pipe(int filedes[2]);
+#ifdef GIT_USE_SOCKET_PIPE
+#define pipe(a) socket_pipe(a)
+#endif
/* used on Mac OS X */
#ifdef PRECOMPOSE_UNICODE
#include "compat/precompose_utf8.h"
--
1.8.3
next reply other threads:[~2013-06-27 16:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-27 16:31 Torsten Bögershausen [this message]
2013-06-27 17:38 ` [PATCH] CYGWIN: Use a TCP socket for pipe() Junio C Hamano
2013-06-28 2:46 ` Mark Levedahl
2013-06-30 19:47 ` Torsten Bögershausen
2013-06-30 22:56 ` Junio C Hamano
2013-07-02 14:57 ` Torsten Bögershausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201306271831.13865.tboegi@web.de \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
--cc=mlevedahl@gmail.com \
--cc=ramsay@ramsay1.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.