adding tracing facility to socket transport, NOT PART OF THE BUILD

This commit is contained in:
darin%meer.net 2004-06-09 22:40:02 +00:00
Родитель 125814a072
Коммит 84e22da18c
2 изменённых файлов: 92 добавлений и 0 удалений

Просмотреть файл

@ -335,6 +335,11 @@ nsSocketInputStream::Read(char *buf, PRUint32 count, PRUint32 *countRead)
{
nsAutoLock lock(mTransport->mLock);
#ifdef ENABLE_SOCKET_TRACING
if (n > 0)
mTransport->TraceInBuf(buf, n);
#endif
mTransport->ReleaseFD_Locked(fd);
if (n > 0)
@ -543,6 +548,11 @@ nsSocketOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *countWrit
{
nsAutoLock lock(mTransport->mLock);
#ifdef ENABLE_SOCKET_TRACING
if (n > 0)
mTransport->TraceOutBuf(buf, n);
#endif
mTransport->ReleaseFD_Locked(fd);
if (n > 0)
@ -1730,3 +1740,76 @@ nsSocketTransport::OnLookupComplete(nsIDNSRequest *request,
return NS_OK;
}
#ifdef ENABLE_SOCKET_TRACING
#include <stdio.h>
#include <ctype.h>
#include "prenv.h"
static void
DumpBytesToFile(const char *path, const char *header, const char *buf, PRInt32 n)
{
FILE *fp = fopen(path, "a");
fprintf(fp, "\n%s [%d bytes]\n", header, n);
const unsigned char *p;
while (n) {
p = (const unsigned char *) buf;
PRInt32 i, row_max = PR_MIN(16, n);
for (i = 0; i < row_max; ++i)
fprintf(fp, "%02x ", *p++);
for (i = row_max; i < 16; ++i)
fprintf(fp, " ");
p = (const unsigned char *) buf;
for (i = 0; i < row_max; ++i, ++p) {
if (isprint(*p))
fprintf(fp, "%c", *p);
else
fprintf(fp, ".");
}
fprintf(fp, "\n");
buf += row_max;
n -= row_max;
}
fprintf(fp, "\n");
fclose(fp);
}
void
nsSocketTransport::TraceInBuf(const char *buf, PRInt32 n)
{
char *val = PR_GetEnv("NECKO_SOCKET_TRACE_LOG");
if (!val || !*val)
return;
nsCAutoString header;
header.Assign(NS_LITERAL_CSTRING("Reading from: ") + mHost);
header.Append(':');
header.AppendInt(mPort);
DumpBytesToFile(val, header.get(), buf, n);
}
void
nsSocketTransport::TraceOutBuf(const char *buf, PRInt32 n)
{
char *val = PR_GetEnv("NECKO_SOCKET_TRACE_LOG");
if (!val || !*val)
return;
nsCAutoString header;
header.Assign(NS_LITERAL_CSTRING("Writing to: ") + mHost);
header.Append(':');
header.AppendInt(mPort);
DumpBytesToFile(val, header.get(), buf, n);
}
#endif

Просмотреть файл

@ -38,6 +38,10 @@
#ifndef nsSocketTransport2_h__
#define nsSocketTransport2_h__
#ifdef DEBUG_darinf
#define ENABLE_SOCKET_TRACING
#endif
#include "nsSocketTransportService2.h"
#include "nsString.h"
#include "nsCOMPtr.h"
@ -297,6 +301,11 @@ private:
else
PostEvent(MSG_OUTPUT_PENDING);
}
#ifdef ENABLE_SOCKET_TRACING
void TraceInBuf(const char *buf, PRInt32 n);
void TraceOutBuf(const char *buf, PRInt32 n);
#endif
};
#endif // !nsSocketTransport_h__