[PATCH] tstream: Make socketpair nonblocking
Volker Lendecke
Volker.Lendecke at SerNet.DE
Fri Jun 5 03:06:05 MDT 2015
On Fri, Jun 05, 2015 at 10:21:47AM +0200, Stefan (metze) Metzmacher wrote:
> Yes, please.
While there: The attached patch builds for me. Interesting?
Removes 22 lines of code duplication.
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 2cb0608f95f59a32a3ce665d45040a53d62f0407 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 5 Jun 2015 11:02:45 +0200
Subject: [PATCH] tsocket: Use common code in tsocket_bsd_common_prepare_fd
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tsocket/tsocket_bsd.c | 34 ++++++----------------------------
lib/tsocket/wscript_build | 2 +-
2 files changed, 7 insertions(+), 29 deletions(-)
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index 79235c6..18402ec 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -27,6 +27,7 @@
#include "tsocket.h"
#include "tsocket_internal.h"
#include "lib/util/iov_buf.h"
+#include "lib/util/blocking.h"
static int tsocket_bsd_error_from_errno(int ret,
int sys_errno,
@@ -85,6 +86,7 @@ static int tsocket_bsd_common_prepare_fd(int fd, bool high_fd)
int num_fds = 0;
int result, flags;
+ bool ok;
if (fd == -1) {
return -1;
@@ -109,40 +111,16 @@ static int tsocket_bsd_common_prepare_fd(int fd, bool high_fd)
}
}
- /* fd should be nonblocking. */
-
-#ifdef O_NONBLOCK
-#define FLAG_TO_SET O_NONBLOCK
-#else
-#ifdef SYSV
-#define FLAG_TO_SET O_NDELAY
-#else /* BSD */
-#define FLAG_TO_SET FNDELAY
-#endif
-#endif
-
- if ((flags = fcntl(fd, F_GETFL)) == -1) {
+ result = set_blocking(fd, false);
+ if (result == -1) {
goto fail;
}
- flags |= FLAG_TO_SET;
- if (fcntl(fd, F_SETFL, flags) == -1) {
+ ok = smb_set_close_on_exec(fd);
+ if (!ok) {
goto fail;
}
-#undef FLAG_TO_SET
-
- /* fd should be closed on exec() */
-#ifdef FD_CLOEXEC
- result = flags = fcntl(fd, F_GETFD, 0);
- if (flags >= 0) {
- flags |= FD_CLOEXEC;
- result = fcntl(fd, F_SETFD, flags);
- }
- if (result < 0) {
- goto fail;
- }
-#endif
return fd;
fail:
diff --git a/lib/tsocket/wscript_build b/lib/tsocket/wscript_build
index 31ef14e..420daff 100644
--- a/lib/tsocket/wscript_build
+++ b/lib/tsocket/wscript_build
@@ -3,7 +3,7 @@
bld.SAMBA_SUBSYSTEM('LIBTSOCKET',
source='tsocket.c tsocket_helpers.c tsocket_bsd.c',
- public_deps='talloc tevent iov_buf',
+ public_deps='talloc tevent iov_buf socket-blocking',
public_headers='tsocket.h tsocket_internal.h',
)
--
1.9.1
More information about the samba-technical
mailing list