mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
log contents of udp packets as b64-encoded strings for debugging; off
by default.
This commit is contained in:
parent
06dd9a99a1
commit
2ce097629f
2 changed files with 27 additions and 7 deletions
|
@ -51,6 +51,7 @@ CPPFLAGS += -DSPAWN_SELF -g -Wall
|
||||||
CPPFLAGS += -I $(shell pg_config --includedir)
|
CPPFLAGS += -I $(shell pg_config --includedir)
|
||||||
CPPFLAGS += -DSVN_REV=\"$(shell cat $(GITINFO) 2>/dev/null || echo -n $(HASH) )\"
|
CPPFLAGS += -DSVN_REV=\"$(shell cat $(GITINFO) 2>/dev/null || echo -n $(HASH) )\"
|
||||||
CPPFLAGS += $(shell pkg-config --cflags glib-2.0)
|
CPPFLAGS += $(shell pkg-config --cflags glib-2.0)
|
||||||
|
# CPPFLAGS += -DLOG_UDP_PACKETS
|
||||||
# CPPFLAGS += -DDO_HTTP
|
# CPPFLAGS += -DDO_HTTP
|
||||||
# CPPFLAGS += -DHAVE_STIME
|
# CPPFLAGS += -DHAVE_STIME
|
||||||
|
|
||||||
|
|
|
@ -449,6 +449,21 @@ send_via_udp( int socket, const struct sockaddr* dest_addr,
|
||||||
}
|
}
|
||||||
va_end( ap );
|
va_end( ap );
|
||||||
|
|
||||||
|
#ifdef LOG_UDP_PACKETS
|
||||||
|
gsize size = 0;
|
||||||
|
gint state = 0;
|
||||||
|
gint save = 0;
|
||||||
|
gchar out[1024];
|
||||||
|
for ( unsigned int ii = 0; ii < iocount; ++ii ) {
|
||||||
|
size += g_base64_encode_step( (const guchar*)vec[ii].iov_base,
|
||||||
|
vec[ii].iov_len,
|
||||||
|
FALSE, &out[size], &state, &save );
|
||||||
|
}
|
||||||
|
size += g_base64_encode_close( FALSE, &out[size], &state, &save );
|
||||||
|
assert( size < sizeof(out) );
|
||||||
|
out[size] = '\0';
|
||||||
|
#endif
|
||||||
|
|
||||||
struct msghdr mhdr = {0};
|
struct msghdr mhdr = {0};
|
||||||
mhdr.msg_iov = vec;
|
mhdr.msg_iov = vec;
|
||||||
mhdr.msg_iovlen = iocount;
|
mhdr.msg_iovlen = iocount;
|
||||||
|
@ -457,15 +472,19 @@ send_via_udp( int socket, const struct sockaddr* dest_addr,
|
||||||
|
|
||||||
ssize_t nSent = sendmsg( socket, &mhdr, 0 /* flags */);
|
ssize_t nSent = sendmsg( socket, &mhdr, 0 /* flags */);
|
||||||
if ( 0 > nSent ) {
|
if ( 0 > nSent ) {
|
||||||
logf( XW_LOGERROR, "sendmsg->errno %d (%s)", errno, strerror(errno) );
|
logf( XW_LOGERROR, "%s: sendmsg->errno %d (%s)", __func__, errno,
|
||||||
|
strerror(errno) );
|
||||||
}
|
}
|
||||||
|
|
||||||
XW_LogLevel level = XW_LOGINFO;
|
#ifdef LOG_UDP_PACKETS
|
||||||
if ( willLog( level ) ) {
|
gchar* b64 = g_base64_encode( (unsigned char*)dest_addr,
|
||||||
gchar* b64 = g_base64_encode( (unsigned char*)dest_addr, sizeof(*dest_addr) );
|
sizeof(*dest_addr) );
|
||||||
logf( level, "%s()=>%d; addr='%s'", __func__, nSent, b64 );
|
logf( XW_LOGINFO, "%s()=>%d; addr='%s'; msg='%s'", __func__, nSent,
|
||||||
g_free( b64 );
|
b64, out );
|
||||||
}
|
g_free( b64 );
|
||||||
|
#else
|
||||||
|
logf( XW_LOGINFO, "%s()=>%d", __func__, nSent );
|
||||||
|
#endif
|
||||||
|
|
||||||
return nSent;
|
return nSent;
|
||||||
} // send_via_udp
|
} // send_via_udp
|
||||||
|
|
Loading…
Reference in a new issue