diff options
Diffstat (limited to 'lib/Handle.cc')
| -rw-r--r-- | lib/Handle.cc | 48 | 
1 files changed, 36 insertions, 12 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc index 50e7bee..70683b1 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -15,20 +15,26 @@  Handle::Handle(const Handle & nh) : itell(0), h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0)  { -//    cerr << "Duplication of handle " << nh.h << " to " << h << endl; +#ifdef DEBUG +    std::cerr << "Duplication of handle " << nh.h << " to " << h << std::endl; +#endif      if ((h >= 0) && (nh.z)) {  	SetZ(nh.z);      }  }  Handle::~Handle() { -//    cerr << "Destroying handle " << h << endl; +#ifdef DEBUG +    std::cerr << "Destroying handle " << h << std::endl; +#endif      close();  }  Handle::Handle(int nh) : h(nh), closed(false), nonblock(false), zfile(0), z(0)  { -//    cerr << "Initialising handle " << h << endl; +#ifdef DEBUG +    std::cerr << "Initialising handle " << h << std::endl; +#endif  }  int Handle::GetHandle() { @@ -61,7 +67,9 @@ ssize_t Handle::write(const void *cbuf, size_t count) throw (GeneralException) {  		    done = false;  		    full = true;  		    if (nonblock) { -//			cerr << "write: throwing IOAgain for handle " << GetName() << endl; +#ifdef DEBUG +			std::cerr << "write: throwing IOAgain for handle " << GetName() << std::endl; +#endif  			throw IOAgain();  		    } else {  #ifdef HAVE_SLEEP @@ -94,7 +102,9 @@ ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) {  	    // Avant de déclarer une erreur, on vérifie si ce n'est pas un  	    // problème lié au fait qu'il n'y a plus d'octets.  	    if (nonblock) { -//		cerr << "read: throwing IOAgain for handle " << GetName() << endl; +#ifdef DEBUG +		std::cerr << "read: throwing IOAgain for handle " << GetName() << std::endl; +#endif  		throw IOAgain();  	    }  	} else { @@ -165,9 +175,13 @@ void Handle::close() throw (GeneralException) {      if (h >= 0) {  	if (z) { -//	    cerr << "Performing gzclose on handle " << h << endl; +#ifdef DEBUG +	    std::cerr << "Performing gzclose on handle " << h << std::endl; +#endif  	    int err = gzclose(zfile); -//	    cerr << "gzclose returned " << err << endl; +#ifdef DEBUG +	    std::cerr << "gzclose returned " << err << std::endl; +#endif  	    if (err) {  		if (err == Z_ERRNO) {  		    throw GeneralException(String(_("Error during close: ")) + strerror(errno)); @@ -237,7 +251,9 @@ void Handle::SetZ(int az) throw (GeneralException) {  	}  	format[index++] = (char) (az + '0');  	format[index] = 0; -//	cerr << "Performing gzdopen on handle " << h << " with mode \"" << format << "\"\n"; +#ifdef DEBUG +	std::cerr << "Performing gzdopen on handle " << h << " with mode \"" << format << "\"\n"; +#endif  	if (!(zfile = gzdopen(h, format))) {  	    throw GeneralException(_("Was not able to gzdopen."));  	} @@ -248,13 +264,17 @@ void Handle::SetZ(int az) throw (GeneralException) {  ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException) {      if (z) {  	itell += count; -//	cerr << "Performing gzwrite of " << count << " byte for handle " << h << endl; +#ifdef DEBUG +	std::cerr << "Performing gzwrite of " << count << " byte for handle " << h << std::endl; +#endif  #ifdef HAVE_WD_ZLIB  	int err = gzwrite(zfile, buf, count);  #else  	int err = gzwrite(zfile, (char *) buf, count);  #endif -//	cerr << "gzwrite returned " << err << endl; +#ifdef DEBUG +	std::cerr << "gzwrite returned " << err << std::endl; +#endif  	if (err == 0) {  	    const char * m = gzerror(zfile, &err);  	    if (err == Z_ERRNO) { @@ -273,9 +293,13 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException)  ssize_t Handle::uread(void * buf, size_t count) {      if (z) {  	itell += count; -//	cerr << "Performing gzread of " << count << " byte for handle " << h << endl; +#ifdef DEBUG +	std::cerr << "Performing gzread of " << count << " byte for handle " << h << std::endl; +#endif  	int err = gzread(zfile, buf, count); -//	cerr << "gzwrite returned " << err << endl; +#ifdef DEBUG +	std::cerr << "gzwrite returned " << err << std::endl; +#endif  	if (err == -1) {  	    gzerror(zfile, &err);  	    if (err == Z_ERRNO) {  | 
