diff --git a/xwords4/relay/Makefile b/xwords4/relay/Makefile index 06d8a8c73..83e0f9382 100644 --- a/xwords4/relay/Makefile +++ b/xwords4/relay/Makefile @@ -51,6 +51,7 @@ CPPFLAGS += -DSPAWN_SELF -g -Wall CPPFLAGS += -I $(shell pg_config --includedir) CPPFLAGS += -DSVN_REV=\"$(shell cat $(GITINFO) 2>/dev/null || echo -n $(HASH) )\" CPPFLAGS += $(shell pkg-config --cflags glib-2.0) +# CPPFLAGS += -DLOG_UDP_PACKETS # CPPFLAGS += -DDO_HTTP # CPPFLAGS += -DHAVE_STIME diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index c4111a918..2359b5bf9 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -449,6 +449,21 @@ send_via_udp( int socket, const struct sockaddr* dest_addr, } 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}; mhdr.msg_iov = vec; 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 */); 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; - if ( willLog( level ) ) { - gchar* b64 = g_base64_encode( (unsigned char*)dest_addr, sizeof(*dest_addr) ); - logf( level, "%s()=>%d; addr='%s'", __func__, nSent, b64 ); - g_free( b64 ); - } +#ifdef LOG_UDP_PACKETS + gchar* b64 = g_base64_encode( (unsigned char*)dest_addr, + sizeof(*dest_addr) ); + logf( XW_LOGINFO, "%s()=>%d; addr='%s'; msg='%s'", __func__, nSent, + b64, out ); + g_free( b64 ); +#else + logf( XW_LOGINFO, "%s()=>%d", __func__, nSent ); +#endif return nSent; } // send_via_udp