fixing stuff

master
Steffen Pohle 14 hours ago
parent a576e2f4f2
commit 42b2e69361

@ -74,16 +74,15 @@ std::string string_to_upper(std::string s);
int file_is_readable (const char *fname); int file_is_readable (const char *fname);
#ifndef UDPTCPNETWORK_DISABLE_DEBUG void UDPTCPNetwork_debug_set_logfile (std::string fname);
void debug_set_logfile (std::string fname); void UDPTCPNetwork_debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...);
void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...); void UDPTCPNetwork_errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...);
void _errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...); void UDPTCPNetwork_enable_debug (int enable);
#ifndef debug
#define debug(...) _debug ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__)
#endif
#define errorexit(...) _errorexit ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__)
#ifndef UDPTCPNETWORK_DISABLE_DEBUG
#define debug(...) UDPTCPNetwork_debug ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__)
#define errorexit(...) UDPTCPNetwork_errorexit ((char*)__FILE__, __LINE__, (char*)__FUNCTION__, (char*)__VA_ARGS__)
#define debug_enable(enable) UDPTCPNetwork_enable_debug (enable)
#endif #endif
/************************************************************************ /************************************************************************

@ -14,6 +14,7 @@ using namespace std;
char dnsip[NET_HOSTLEN]; char dnsip[NET_HOSTLEN];
int UDPTCPNetwork_init = 0; int UDPTCPNetwork_init = 0;
std::string debug_file = ""; std::string debug_file = "";
int debug_enabeld = 0;
// //
// convert host and port to sockaddr_in6 // convert host and port to sockaddr_in6
@ -96,7 +97,7 @@ std::string string_to_lower(std::string s) {
}; };
void debug_set_logfile(std::string fname) { void UDPTCPNetwork_debug_set_logfile(std::string fname) {
debug_file = fname; debug_file = fname;
}; };
@ -104,7 +105,7 @@ void debug_set_logfile(std::string fname) {
#define LEN_TEXT 256 #define LEN_TEXT 256
#define DEBUG_TEXT1LEN 4096 #define DEBUG_TEXT1LEN 4096
#define DEBUG_TEXT2LEN (DEBUG_TEXT1LEN+LEN_TEXT) #define DEBUG_TEXT2LEN (DEBUG_TEXT1LEN+LEN_TEXT)
void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { void UDPTCPNetwork_debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) {
va_list args; va_list args;
char texttime[LEN_TEXT]; char texttime[LEN_TEXT];
char text1[DEBUG_TEXT1LEN]; char text1[DEBUG_TEXT1LEN];
@ -115,6 +116,8 @@ void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) {
struct tm tmp; struct tm tmp;
struct tm *tmptr = NULL; struct tm *tmptr = NULL;
if (debug_enabeld == 0) return;
va_start (args, fmt); va_start (args, fmt);
vsnprintf (text1, (DEBUG_TEXT1LEN-1), fmt, args); vsnprintf (text1, (DEBUG_TEXT1LEN-1), fmt, args);
va_end (args); va_end (args);
@ -143,11 +146,16 @@ void _debug (char *srcfile, int srcline, char *srcfunc, char *fmt,...) {
}; };
void _errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...) { void UDPTCPNetwork_enable_debug (int enable) {
debug_enabeld = enable;
};
void UDPTCPNetwork_errorexit (char *srcfile, int srcline, char *srcfunc, char *fmt,...) {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
_debug (srcfile, srcline, srcfunc, fmt, args); UDPTCPNetwork_debug (srcfile, srcline, srcfunc, fmt, args);
va_end (args); va_end (args);
exit (1); exit (1);

Loading…
Cancel
Save