From aa1af7d82ac605c373062861ebe07c6bc8e5d744 Mon Sep 17 00:00:00 2001
From: sobomax <sobomax@FreeBSD.org>
Date: Mon, 29 Oct 2001 17:05:04 +0000
Subject: Huh, finally implement writev(2) wrapper that actually works. Boys,
 never ever try to use writev(2) in a non-blocking mode, especially on
 sockets. Not only this makes handling of EAGAIN rather weird, but in the case
 of sockets makes your code subject of a ENOBUFS, which is absolutely unclear
 how to handle properly. *sigh*

Bump PORTREVISION.
---
 devel/ORBit2/Makefile                              |   5 +-
 devel/ORBit2/files/patch-ae                        | 102 ++++++++++++++++++++-
 devel/ORBit2/files/patch-configure.in              |  57 ++++++++++++
 .../files/patch-src::IIOP::giop-msg-buffer.c       |  38 +++++---
 devel/ORBit2/files/patch-src::ORBitutil::compat.c  |  47 ++++++++++
 .../patch-src::ORBitutil::orbit-os-config.h.in     |  12 +++
 6 files changed, 241 insertions(+), 20 deletions(-)
 create mode 100644 devel/ORBit2/files/patch-configure.in
 create mode 100644 devel/ORBit2/files/patch-src::ORBitutil::compat.c
 create mode 100644 devel/ORBit2/files/patch-src::ORBitutil::orbit-os-config.h.in

(limited to 'devel/ORBit2')

diff --git a/devel/ORBit2/Makefile b/devel/ORBit2/Makefile
index 94f54b4b06b0..87a39098386c 100644
--- a/devel/ORBit2/Makefile
+++ b/devel/ORBit2/Makefile
@@ -7,7 +7,7 @@
 
 PORTNAME=	ORBit
 PORTVERSION=	0.5.10
-PORTREVISION=	4
+PORTREVISION=	2
 CATEGORIES=	devel gnome
 MASTER_SITES=	${MASTER_SITE_GNOME}
 MASTER_SITE_SUBDIR=	stable/sources/ORBit
@@ -26,6 +26,9 @@ CONFIGURE_ARGS= --disable-indent
 CONFIGURE_ENV=	CPPFLAGS="-I${LOCALBASE}/include" \
 		LIBS="-L${LOCALBASE}/lib"
 
+post-patch:
+	@${TOUCH} ${WRKSRC}/configure
+
 post-install:
 	@${ECHO} "ORBIIOPIPv4=0" > ${PREFIX}/etc/orbitrc.default
 	@${ECHO} "ORBIIOPIPv6=0" >> ${PREFIX}/etc/orbitrc.default
diff --git a/devel/ORBit2/files/patch-ae b/devel/ORBit2/files/patch-ae
index 7ba0a489c38b..7e43d15302c9 100644
--- a/devel/ORBit2/files/patch-ae
+++ b/devel/ORBit2/files/patch-ae
@@ -1,9 +1,12 @@
---- configure.orig	Fri Feb 19 00:50:06 1999
-+++ configure	Fri Feb 19 00:50:21 1999
-@@ -2499,9 +2499,9 @@
-   
+
+$FreeBSD$
+
+--- configure	2001/10/27 12:43:19	1.1
++++ configure	2001/10/27 12:43:58
+@@ -5747,9 +5747,9 @@
    rm -f conf.glibtest
  
+ 
 -GMODULE_CFLAGS=`glib-config --cflags gmodule`
 +GMODULE_CFLAGS=`$GLIB_CONFIG --cflags gmodule`
  
@@ -12,7 +15,96 @@
  
  
  for ac_prog in 'bison -y' byacc
-@@ -5288,10 +5288,6 @@
+@@ -7273,57 +7273,47 @@
+ fi
+ 
+ 
++echo $ac_n "checking how many vectors writev is capable to handle""... $ac_c" 1>&6
++echo "configure:7278: checking how many vectors writev is capable to handle" >&5
+ if test "$cross_compiling" = yes; then
+-  cat >> confdefs.h <<\EOF
+-#define HAVE_LIMITED_WRITEV 1
+-EOF
+-
++  MAXIOV=16
+ else
+   cat > conftest.$ac_ext <<EOF
+-#line 7284 "configure"
++#line 7283 "configure"
+ #include "confdefs.h"
+ 
+-#include <fcntl.h>
++#include <sys/types.h>
+ #include <sys/uio.h>
+-#define NIOVECS 50
+-int main(int argc, char *argv[])
++#include <fcntl.h>
++#include <stdio.h>
++int main()
+ {
+-	char dumbuf[20] = "\n";
+-	struct iovec iovecs[NIOVECS];
+-	int i,fd;
+-
+-	for(i = 0; i < NIOVECS; i++) {
+-		iovecs[i].iov_base = dumbuf;
+-		iovecs[i].iov_len = 1;
+-	}
+-
+-	fd=open("/dev/null", O_WRONLY);
+-	if(fd==-1)
+-		return(1);
+-
+-	if(writev(fd, iovecs, NIOVECS) < 0)
+-		return 1;
+-
++	FILE *f;
++	int fd, i;
++	static struct iovec iovecs[4097];
++	if ((f = fopen("conftestval", "w")) == NULL || \
++	    (fd = open("/dev/null", O_WRONLY)) < 0)
++		exit(1);
++	for (i = 1; i < 4098 && writev(fd, iovecs, i) >= 0; i++);
++	fprintf(f, "%d\n", i - 1);
++	fclose(f);
+ 	close(fd);
+-	return 0;
++	exit(0);
+ }
+ 
+ EOF
+-if { (eval echo configure:7313: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
++if { (eval echo configure:7306: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+ then
+-  :
++  MAXIOV=`cat conftestval`
+ else
+   echo "configure: failed program was:" >&5
+   cat conftest.$ac_ext >&5
+   rm -fr conftest*
+-  cat >> confdefs.h <<\EOF
+-#define HAVE_LIMITED_WRITEV 1
+-EOF
+-
++  MAXIOV=16
+ fi
+ rm -fr conftest*
+ fi
+-
++echo "$ac_t""$MAXIOV" 1>&6
+ 
+ 
+ #######################
+@@ -8260,7 +8250,7 @@
+ s%@LIB_WRAP@%$LIB_WRAP%g
+ s%@HAVE_HOSTS_ACCESS_TRUE@%$HAVE_HOSTS_ACCESS_TRUE%g
+ s%@HAVE_HOSTS_ACCESS_FALSE@%$HAVE_HOSTS_ACCESS_FALSE%g
+-s%@HAVE_LIMITED_WRITEV@%$HAVE_LIMITED_WRITEV%g
++s%@MAXIOV@%$MAXIOV%g
+ s%@subdirs@%$subdirs%g
+ s%@pkglibdir@%$pkglibdir%g
+ 
+@@ -8584,10 +8574,6 @@
        *) # Relative path.
          ac_sub_cache_file="$ac_dots$cache_file" ;;
        esac
diff --git a/devel/ORBit2/files/patch-configure.in b/devel/ORBit2/files/patch-configure.in
new file mode 100644
index 000000000000..abd947f9dfe7
--- /dev/null
+++ b/devel/ORBit2/files/patch-configure.in
@@ -0,0 +1,57 @@
+
+$FreeBSD$
+
+--- configure.in	2001/10/27 12:08:05	1.1
++++ configure.in	2001/10/27 12:33:26
+@@ -241,33 +241,29 @@
+ dnl This generates warnings from autoconf...
+ AC_C_BIGENDIAN
+ 
++AC_MSG_CHECKING(how many vectors writev is capable to handle)
+ AC_TRY_RUN([
+-#include <fcntl.h>
++#include <sys/types.h>
+ #include <sys/uio.h>
+-#define NIOVECS 50
+-int main(int argc, char *argv[])
++#include <fcntl.h>
++#include <stdio.h>
++int main()
+ {
+-	char dumbuf[20] = "\n";
+-	struct iovec iovecs[NIOVECS];
+-	int i,fd;
+-
+-	for(i = 0; i < NIOVECS; i++) {
+-		iovecs[i].iov_base = dumbuf;
+-		iovecs[i].iov_len = 1;
+-	}
+-
+-	fd=open("/dev/null", O_WRONLY);
+-	if(fd==-1)
+-		return(1);
+-
+-	if(writev(fd, iovecs, NIOVECS) < 0)
+-		return 1;
+-
++	FILE *f;
++	int fd, i;
++	static struct iovec iovecs[4097];
++	if ((f = fopen("conftestval", "w")) == NULL || \
++	    (fd = open("/dev/null", O_WRONLY)) < 0)
++		exit(1);
++	for (i = 1; i < 4098 && writev(fd, iovecs, i) >= 0; i++);
++	fprintf(f, "%d\n", i - 1);
++	fclose(f);
+ 	close(fd);
+-	return 0;
++	exit(0);
+ }
+-], , AC_DEFINE(HAVE_LIMITED_WRITEV), AC_DEFINE(HAVE_LIMITED_WRITEV))
+-AC_SUBST(HAVE_LIMITED_WRITEV)
++], MAXIOV=`cat conftestval`, MAXIOV=16, MAXIOV=16)dnl
++AC_MSG_RESULT($MAXIOV)
++AC_SUBST(MAXIOV)
+ 
+ #######################
+ # type alignment test #
diff --git a/devel/ORBit2/files/patch-src::IIOP::giop-msg-buffer.c b/devel/ORBit2/files/patch-src::IIOP::giop-msg-buffer.c
index a42320410527..d6184df8952a 100644
--- a/devel/ORBit2/files/patch-src::IIOP::giop-msg-buffer.c
+++ b/devel/ORBit2/files/patch-src::IIOP::giop-msg-buffer.c
@@ -1,24 +1,34 @@
 
 $FreeBSD$
 
---- src/IIOP/giop-msg-buffer.c	2001/10/26 12:42:42	1.1
-+++ src/IIOP/giop-msg-buffer.c	2001/10/26 12:42:53
-@@ -197,7 +197,17 @@
+--- src/IIOP/giop-msg-buffer.c.orig	Wed Oct  3 09:51:21 2001
++++ src/IIOP/giop-msg-buffer.c	Sat Oct 27 15:52:11 2001
+@@ -34,10 +34,6 @@
+ #include "IIOP.h"
+ #include "IIOP-private.h"
+ 
+-#ifdef HAVE_LIMITED_WRITEV
+-#define writev g_writev
+-#endif
+-
+ /* type defs */
+ 
+ #ifdef        __GNUC__
+@@ -197,7 +193,7 @@
  	    sum);
    }
  #endif
 -  res = writev(fd, curvec, nvecs);
-+  for(sum = 0, t = 0; t < nvecs; t++) {
-+    do {
-+      res = write(fd, curvec[t].iov_base, curvec[t].iov_len);
-+    } while (res < 0 && errno == EAGAIN);
-+    if (res < 0) {
-+      break;
-+    } else
-+      sum += res;
-+  }
-+  if (res >= 0)
-+    res = sum;
++  res = g_writev(fd, curvec, nvecs);
  
    sum = (GIOP_MESSAGE_BUFFER(send_buffer)->message_header.message_size + sizeof(GIOPMessageHeader));
    if(res < sum) {
+@@ -227,7 +223,7 @@
+ 
+     fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
+ 
+-    t = writev(fd, curvec, nvecs);
++    t = g_writev(fd, curvec, nvecs);
+ 
+     fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+ 
diff --git a/devel/ORBit2/files/patch-src::ORBitutil::compat.c b/devel/ORBit2/files/patch-src::ORBitutil::compat.c
new file mode 100644
index 000000000000..e907c22b66b9
--- /dev/null
+++ b/devel/ORBit2/files/patch-src::ORBitutil::compat.c
@@ -0,0 +1,47 @@
+
+$FreeBSD$
+
+--- src/ORBitutil/compat.c.orig	Wed Sep  9 07:08:14 1998
++++ src/ORBitutil/compat.c	Mon Oct 29 18:50:04 2001
+@@ -1,18 +1,34 @@
++#include <errno.h>
++#include <fcntl.h>
++
+ #include "config.h"
+ #include "util.h"
+ 
+-#define MAX_IOVS 16
+-
+ int g_writev(int fd, const struct  iovec *  vector,  size_t count)
+ {
+-  int retval = 0;
++  int fdflags, retval, wcur;
++  int sum = 0;
+ 
+-  while(count > MAX_IOVS) {
+-    retval += writev(fd, vector, MAX_IOVS);
+-    vector += MAX_IOVS; count -= MAX_IOVS;
++  fdflags = fcntl(fd, F_GETFL);
++  /* Get rid of the O_NONBLOCK - we don't need it here */
++  fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK);
++  for (wcur = MAXIOV; wcur == MAXIOV && count != 0; count -= MAXIOV) {
++    if (wcur > count)
++      wcur = count;
++    do {
++      retval = writev(fd, vector, wcur);
++    } while (retval <= 0 && (errno == EAGAIN || errno == EINTR));
++    if (retval < 0) {
++      sum = retval;
++      break;
++    }
++    vector += wcur;
++    sum += retval;
+   }
+ 
+-  return writev(fd, vector, count) + retval;
++  /* Restore flags */
++  fcntl(fd, F_SETFD, fdflags);
++  return sum;
+ }
+ 
+ #ifndef HAVE_INET_ATON
diff --git a/devel/ORBit2/files/patch-src::ORBitutil::orbit-os-config.h.in b/devel/ORBit2/files/patch-src::ORBitutil::orbit-os-config.h.in
new file mode 100644
index 000000000000..35697338049f
--- /dev/null
+++ b/devel/ORBit2/files/patch-src::ORBitutil::orbit-os-config.h.in
@@ -0,0 +1,12 @@
+
+$FreeBSD$
+
+--- src/ORBitutil/orbit-os-config.h.in	2001/10/27 12:25:39	1.1
++++ src/ORBitutil/orbit-os-config.h.in	2001/10/27 12:26:13
+@@ -2,5 +2,6 @@
+ #define OS_CONFIG_H 1
+ 
+ #define ORBIT_HAVE_ALLOCA_H @ORBIT_HAVE_ALLOCA_H@
++#define MAXIOV @MAXIOV@
+ 
+ #endif
-- 
cgit