From a05d7015e0a2b4cbd243d1cfbf4963b01c50411f Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 26 Oct 2009 23:36:39 +0000 Subject: [PATCH] ITS#6327, #6334 take ret=-1/EINTR into account --- libraries/libldap/sasl.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libraries/libldap/sasl.c b/libraries/libldap/sasl.c index 82321ee5ab..268a94e3f6 100644 --- a/libraries/libldap/sasl.c +++ b/libraries/libldap/sasl.c @@ -698,24 +698,21 @@ sb_sasl_generic_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) } } - /* If we're just retrying a partial write, ignore - * the first byte of this request since we fudged it - * below on the previous call. + len2 = p->max_send - 100; /* For safety margin */ + len2 = len > len2 ? len2 : len; + + /* If we're just retrying a partial write, tell the + * caller it's done. Let them call again if there's + * still more left to write. */ if ( p->flags & LDAP_PVT_SASL_PARTIAL_WRITE ) { p->flags ^= LDAP_PVT_SASL_PARTIAL_WRITE; - len--; - if ( !len ) - return 1; - buf = (char *)buf + 1; + return len2; } /* now encode the next packet. */ p->ops->reset_buf( p, &p->buf_out ); - len2 = p->max_send - 100; /* For safety margin */ - len2 = len > len2 ? len2 : len; - ret = p->ops->encode( p, buf, len2, &p->buf_out ); if ( ret != 0 ) { @@ -729,10 +726,14 @@ sb_sasl_generic_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) if ( ret < 0 ) { /* error? */ + int err = sock_errno(); + /* caller can retry this */ + if ( err == EAGAIN ) + p->flags |= LDAP_PVT_SASL_PARTIAL_WRITE; return ret; } else if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) { - /* partial write? */ - len2--; + /* partial write? pretend nothing got written */ + len2 = 0; p->flags |= LDAP_PVT_SASL_PARTIAL_WRITE; } -- 2.39.5