first time after all. see read(2) and write(2)...)
                        continue;
 #endif
                if ( ret <= 0 )
-                       return ret;
+                       return bufptr ? bufptr : ret;
 
                p->sec_buf_in.buf_ptr += ret;
        }
                        continue;
 #endif
                if ( ret <= 0 )
-                       return ret;
+                       return bufptr ? bufptr : ret;
 
                p->sec_buf_in.buf_ptr += ret;
        }
                        return ret;
                /* Still have something left?? */
                if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
-                       errno = EWOULDBLOCK;
+                       errno = EAGAIN;
                        return 0;
                }
        }
 
        LDAPConn *lc = lr->lr_conn;
 
        if ( ber_flush( lc->lconn_sb, lr->lr_ber, 0 ) != 0 ) {
-               if ( errno == EWOULDBLOCK ) {
+               if ( errno == EAGAIN ) {
                        /* need to continue write later */
                        lr->lr_status = LDAP_REQST_WRITING;
                        ldap_mark_select_write( ld, lc->lconn_sb );