From: Howard Chu Date: Fri, 21 Sep 2001 17:53:16 +0000 (+0000) Subject: Check debug level before invoking debug routine, slight optimization X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1076 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2f6b7e3d43ee1cb271feab6cf38eb202ed17fb0a;p=openldap Check debug level before invoking debug routine, slight optimization --- diff --git a/include/ldap_log.h b/include/ldap_log.h index caa4ee2d2c..455e29995c 100644 --- a/include/ldap_log.h +++ b/include/ldap_log.h @@ -111,14 +111,18 @@ LDAP_BEGIN_DECL # ifdef LDAP_SYSLOG # define Debug( level, fmt, arg1, arg2, arg3 ) \ do { \ - lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \ + if ( ldap_debug & (level) ) \ + lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \ if ( ldap_syslog & (level) ) \ syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \ } while ( 0 ) # else # define Debug( level, fmt, arg1, arg2, arg3 ) \ - lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ) + do { \ + if ( ldap_debug & (level) ) \ + lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \ + } while ( 0 ) # endif #ifndef LDAP_LOG diff --git a/libraries/liblber/bprint.c b/libraries/liblber/bprint.c index 13f0f2508d..2d341b771a 100644 --- a/libraries/liblber/bprint.c +++ b/libraries/liblber/bprint.c @@ -16,7 +16,7 @@ typedef void (*BER_LOG_FN) LDAP_P((FILE *file, char *subsys, int level, const char *fmt, va_list vl)); -static int ber_log_check( int errlvl, int loglvl ); +#define ber_log_check(errlvl, loglvl) (errlvl & loglvl) BER_LOG_FN ber_int_log_proc = NULL; @@ -102,11 +102,6 @@ int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... ) return 1; } -static int ber_log_check( int errlvl, int loglvl ) -{ - return errlvl & loglvl ? 1 : 0; -} - int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... ) { char buf[ 1024 ]; diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c index 154c355fcc..e201157433 100644 --- a/libraries/liblber/sockbuf.c +++ b/libraries/liblber/sockbuf.c @@ -819,17 +819,20 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len ) ber_slen_t ret; ret = LBER_SBIOD_READ_NEXT( sbiod, buf, len ); - if ( ret < 0 ) { + if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) + { + if ( ret < 0 ) { ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt, (long)len, STRERROR( errno ) ); - } else { + } else { ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, "%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt, (long)len, (long)ret ); ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, (const char *)buf, ret ); + } } return ret; } @@ -840,18 +843,21 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len ) ber_slen_t ret; ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ); - if ( ret < 0 ) { + if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) + { + if ( ret < 0 ) { ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, "%swrite: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt, (long)len, STRERROR( errno ) ); - } else { + } else { ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, "%swrite: want=%ld, written=%ld\n", (char *)sbiod->sbiod_pvt, (long)len, (long)ret ); ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, (const char *)buf, ret ); + } } return ret;