From 2f6b7e3d43ee1cb271feab6cf38eb202ed17fb0a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 21 Sep 2001 17:53:16 +0000 Subject: [PATCH] Check debug level before invoking debug routine, slight optimization --- include/ldap_log.h | 8 ++++++-- libraries/liblber/bprint.c | 7 +------ libraries/liblber/sockbuf.c | 14 ++++++++++---- 3 files changed, 17 insertions(+), 12 deletions(-) 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; -- 2.39.5