From a09aa3ead995ddb5af2cd20106943aa4f0fdaf7f Mon Sep 17 00:00:00 2001 From: "mcs%pearlcrescent.com" Date: Fri, 15 Oct 2004 13:10:04 +0000 Subject: [PATCH] Fix bug # 263557 - Sending a request fails on Windows when the ber size is larger than 64MB. Break up large messages into <= 8MB sized chunks inside prldap_write(). git-svn-id: svn://10.0.0.236/trunk@163820 18797224-902f-48f8-a5cc-f745e15eee43 --- .../ldap/libraries/libprldap/ldappr-int.h | 9 ++++++ .../ldap/libraries/libprldap/ldappr-io.c | 32 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-int.h b/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-int.h index d3c40e0d024..cc7554357bb 100644 --- a/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-int.h +++ b/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-int.h @@ -61,6 +61,15 @@ */ #define PRLDAP_DEFAULT_ADDRESS_FAMILY PR_AF_INET6 +/* + * Max length for sending message with one PR_Send. + * If a single message is larger than this size, the message is divided + * into multiple pieces up to this length and sent out. This is necessary + * on Microsoft Windows at least where attempts to send really large + * messages in one PR_Send() call result in an error. + */ +#define PRLDAP_MAX_SEND_SIZE (8*1024*1024) /* 8MB */ + /* * Data structures: diff --git a/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-io.c b/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-io.c index 65bfd4ec873..931e0bd26e3 100644 --- a/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-io.c +++ b/mozilla/directory/c-sdk/ldap/libraries/libprldap/ldappr-io.c @@ -198,15 +198,37 @@ prldap_write( int s, const void *buf, int len, struct lextiof_socket_private *socketarg ) { PRIntervalTime prit; + char *ptr = (char *)buf; + int rest = len; prit = prldap_timeout2it( LDAP_X_IO_TIMEOUT_NO_TIMEOUT, socketarg->prsock_io_max_timeout ); - /* - * Note the 4th parameter (flags) to PR_Send() has been obsoleted and - * must always be 0 - */ - return( PR_Send( PRLDAP_GET_PRFD(socketarg), buf, len, 0, prit )); + while ( rest > 0 ) { + int rval; + if ( rest > PRLDAP_MAX_SEND_SIZE ) { + len = PRLDAP_MAX_SEND_SIZE; + } else { + len = rest; + } + /* + * Note the 4th parameter (flags) to PR_Send() has been obsoleted and + * must always be 0 + */ + rval = PR_Send( PRLDAP_GET_PRFD(socketarg), ptr, len, 0, prit ); + if ( 0 > rval ) { + return rval; + } + + if ( 0 == rval ) { + break; + } + + ptr += rval; + rest -= rval; + } + + return (int)( ptr - (char *)buf ); }