mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1109338: Part 1: Separate UDPSocket logging from network logging r=dragana
This commit is contained in:
parent
2b068009de
commit
859e49874b
@ -318,8 +318,10 @@ UDPSocket::Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData,
|
||||
nsCString remoteAddress;
|
||||
if (aRemoteAddress.WasPassed()) {
|
||||
remoteAddress = NS_ConvertUTF16toUTF8(aRemoteAddress.Value());
|
||||
UDPSOCKET_LOG(("%s: Send to %s", __FUNCTION__, remoteAddress.get()));
|
||||
} else if (!mRemoteAddress.IsVoid()) {
|
||||
remoteAddress = mRemoteAddress;
|
||||
UDPSOCKET_LOG(("%s: Send to %s", __FUNCTION__, remoteAddress.get()));
|
||||
} else {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
||||
return false;
|
||||
@ -413,6 +415,7 @@ UDPSocket::InitLocal(const nsAString& aLocalAddress,
|
||||
PRNetAddr prAddr;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, aLocalPort, &prAddr);
|
||||
PR_StringToNetAddr(NS_ConvertUTF16toUTF8(aLocalAddress).BeginReading(), &prAddr);
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, NS_ConvertUTF16toUTF8(aLocalAddress).get(), aLocalPort));
|
||||
|
||||
mozilla::net::NetAddr addr;
|
||||
PRNetAddrToNetAddr(&prAddr, &addr);
|
||||
|
@ -18,6 +18,15 @@
|
||||
|
||||
struct JSContext;
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// set NSPR_LOG_MODULES=UDPSocket:5
|
||||
//
|
||||
extern PRLogModuleInfo *gUDPSocketLog;
|
||||
#endif
|
||||
#define UDPSOCKET_LOG(args) PR_LOG(gUDPSocketLog, PR_LOG_DEBUG, args)
|
||||
#define UDPSOCKET_LOG_ENABLED() PR_LOG_TEST(gUDPSocketLog, PR_LOG_DEBUG)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
@ -12,6 +12,15 @@
|
||||
|
||||
using mozilla::net::gNeckoChild;
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// set NSPR_LOG_MODULES=UDPSocket:5
|
||||
//
|
||||
extern PRLogModuleInfo *gUDPSocketLog;
|
||||
#endif
|
||||
#define UDPSOCKET_LOG(args) PR_LOG(gUDPSocketLog, PR_LOG_DEBUG, args)
|
||||
#define UDPSOCKET_LOG_ENABLED() PR_LOG_TEST(gUDPSocketLog, PR_LOG_DEBUG)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -72,6 +81,8 @@ UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
|
||||
bool aAddressReuse,
|
||||
bool aLoopback)
|
||||
{
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
|
||||
|
||||
NS_ENSURE_ARG(aSocket);
|
||||
|
||||
mSocket = aSocket;
|
||||
@ -99,6 +110,7 @@ UDPSocketChild::Send(const nsACString& aHost,
|
||||
{
|
||||
NS_ENSURE_ARG(aData);
|
||||
|
||||
UDPSOCKET_LOG(("%s: %s:%u - %u bytes", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort, aByteLength));
|
||||
return SendDataInternal(UDPSocketAddr(UDPAddressInfo(nsCString(aHost), aPort)),
|
||||
aData, aByteLength);
|
||||
}
|
||||
@ -114,6 +126,7 @@ UDPSocketChild::SendWithAddr(nsINetAddr* aAddr,
|
||||
NetAddr addr;
|
||||
aAddr->GetNetAddr(&addr);
|
||||
|
||||
UDPSOCKET_LOG(("%s: %u bytes", __FUNCTION__, aByteLength));
|
||||
return SendDataInternal(UDPSocketAddr(addr), aData, aByteLength);
|
||||
}
|
||||
|
||||
@ -125,6 +138,7 @@ UDPSocketChild::SendWithAddress(const NetAddr* aAddr,
|
||||
NS_ENSURE_ARG(aAddr);
|
||||
NS_ENSURE_ARG(aData);
|
||||
|
||||
UDPSOCKET_LOG(("%s: %u bytes", __FUNCTION__, aByteLength));
|
||||
return SendDataInternal(UDPSocketAddr(*aAddr), aData, aByteLength);
|
||||
}
|
||||
|
||||
@ -161,6 +175,7 @@ UDPSocketChild::SendBinaryStream(const nsACString& aHost,
|
||||
|
||||
MOZ_ASSERT(fds.IsEmpty());
|
||||
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
|
||||
SendOutgoingData(UDPData(stream), UDPSocketAddr(UDPAddressInfo(nsCString(aHost), aPort)));
|
||||
|
||||
return NS_OK;
|
||||
@ -223,6 +238,7 @@ UDPSocketChild::RecvCallbackOpened(const UDPAddressInfo& aAddressInfo)
|
||||
mLocalAddress = aAddressInfo.addr();
|
||||
mLocalPort = aAddressInfo.port();
|
||||
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, mLocalAddress.get(), mLocalPort));
|
||||
nsresult rv = mSocket->CallListenerOpened();
|
||||
mozilla::unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
||||
@ -242,6 +258,8 @@ bool
|
||||
UDPSocketChild::RecvCallbackReceivedData(const UDPAddressInfo& aAddressInfo,
|
||||
InfallibleTArray<uint8_t>&& aData)
|
||||
{
|
||||
UDPSOCKET_LOG(("%s: %s:%u length %u", __FUNCTION__,
|
||||
aAddressInfo.addr().get(), aAddressInfo.port(), aData.Length()));
|
||||
nsresult rv = mSocket->CallListenerReceivedData(aAddressInfo.addr(), aAddressInfo.port(),
|
||||
aData.Elements(), aData.Length());
|
||||
mozilla::unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
@ -254,6 +272,7 @@ UDPSocketChild::RecvCallbackError(const nsCString& aMessage,
|
||||
const nsCString& aFilename,
|
||||
const uint32_t& aLineNumber)
|
||||
{
|
||||
UDPSOCKET_LOG(("%s: %s:%s:%u", __FUNCTION__, aMessage.get(), aFilename.get(), aLineNumber));
|
||||
nsresult rv = mSocket->CallListenerError(aMessage, aFilename, aLineNumber);
|
||||
mozilla::unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
||||
|
@ -21,6 +21,15 @@
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// set NSPR_LOG_MODULES=UDPSocket:5
|
||||
//
|
||||
extern PRLogModuleInfo *gUDPSocketLog;
|
||||
#endif
|
||||
#define UDPSOCKET_LOG(args) PR_LOG(gUDPSocketLog, PR_LOG_DEBUG, args)
|
||||
#define UDPSOCKET_LOG_ENABLED() PR_LOG_TEST(gUDPSocketLog, PR_LOG_DEBUG)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -134,6 +143,8 @@ bool
|
||||
UDPSocketParent::RecvBind(const UDPAddressInfo& aAddressInfo,
|
||||
const bool& aAddressReuse, const bool& aLoopback)
|
||||
{
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, aAddressInfo.addr().get(), aAddressInfo.port()));
|
||||
|
||||
if (NS_FAILED(BindInternal(aAddressInfo.addr(), aAddressInfo.port(), aAddressReuse, aLoopback))) {
|
||||
FireInternalError(__LINE__);
|
||||
return true;
|
||||
@ -154,6 +165,7 @@ UDPSocketParent::RecvBind(const UDPAddressInfo& aAddressInfo,
|
||||
return true;
|
||||
}
|
||||
|
||||
UDPSOCKET_LOG(("%s: SendCallbackOpened: %s:%u", __FUNCTION__, addr.get(), port));
|
||||
mozilla::unused << SendCallbackOpened(UDPAddressInfo(addr, port));
|
||||
|
||||
return true;
|
||||
@ -165,6 +177,8 @@ UDPSocketParent::BindInternal(const nsCString& aHost, const uint16_t& aPort,
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, nsCString(aHost).get(), aPort));
|
||||
|
||||
nsCOMPtr<nsIUDPSocket> sock =
|
||||
do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
|
||||
@ -398,6 +412,7 @@ UDPSocketParent::OnPacketReceived(nsIUDPSocket* aSocket, nsIUDPMessage* aMessage
|
||||
|
||||
const char* buffer = data.get();
|
||||
uint32_t len = data.Length();
|
||||
UDPSOCKET_LOG(("%s: %s:%u, length %u", __FUNCTION__, ip.get(), port, len));
|
||||
|
||||
if (mFilter) {
|
||||
bool allowed;
|
||||
@ -409,6 +424,9 @@ UDPSocketParent::OnPacketReceived(nsIUDPSocket* aSocket, nsIUDPMessage* aMessage
|
||||
&allowed);
|
||||
// Receiving unallowed data, drop.
|
||||
if (NS_WARN_IF(NS_FAILED(rv)) || !allowed) {
|
||||
if (!allowed) {
|
||||
UDPSOCKET_LOG(("%s: not allowed", __FUNCTION__));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
|
||||
PRLogModuleInfo *gSocketTransportLog = nullptr;
|
||||
PRLogModuleInfo *gUDPSocketLog = nullptr;
|
||||
|
||||
nsSocketTransportService *gSocketTransportService = nullptr;
|
||||
PRThread *gSocketThread = nullptr;
|
||||
@ -111,6 +112,7 @@ nsSocketTransportService::nsSocketTransportService()
|
||||
, mProbedMaxCount(false)
|
||||
{
|
||||
gSocketTransportLog = PR_NewLogModule("nsSocketTransport");
|
||||
gUDPSocketLog = PR_NewLogModule("UDPSocket");
|
||||
|
||||
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
||||
|
||||
|
@ -32,6 +32,13 @@ extern PRLogModuleInfo *gSocketTransportLog;
|
||||
#define SOCKET_LOG(args) MOZ_LOG(gSocketTransportLog, PR_LOG_DEBUG, args)
|
||||
#define SOCKET_LOG_ENABLED() PR_LOG_TEST(gSocketTransportLog, PR_LOG_DEBUG)
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=UDPSocket:5
|
||||
//
|
||||
extern PRLogModuleInfo *gUDPSocketLog;
|
||||
#define UDPSOCKET_LOG(args) PR_LOG(gUDPSocketLog, PR_LOG_DEBUG, args)
|
||||
#define UDPSOCKET_LOG_ENABLED() PR_LOG_TEST(gUDPSocketLog, PR_LOG_DEBUG)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define NS_SOCKET_POLL_TIMEOUT PR_INTERVAL_NO_TIMEOUT
|
||||
|
@ -487,7 +487,7 @@ nsUDPSocket::AddOutputBytes(uint64_t aBytes)
|
||||
void
|
||||
nsUDPSocket::OnMsgClose()
|
||||
{
|
||||
SOCKET_LOG(("nsUDPSocket::OnMsgClose [this=%p]\n", this));
|
||||
UDPSOCKET_LOG(("nsUDPSocket::OnMsgClose [this=%p]\n", this));
|
||||
|
||||
if (NS_FAILED(mCondition))
|
||||
return;
|
||||
@ -505,7 +505,7 @@ nsUDPSocket::OnMsgClose()
|
||||
void
|
||||
nsUDPSocket::OnMsgAttach()
|
||||
{
|
||||
SOCKET_LOG(("nsUDPSocket::OnMsgAttach [this=%p]\n", this));
|
||||
UDPSOCKET_LOG(("nsUDPSocket::OnMsgAttach [this=%p]\n", this));
|
||||
|
||||
if (NS_FAILED(mCondition))
|
||||
return;
|
||||
@ -1314,7 +1314,7 @@ nsUDPSocket::SetSocketOption(const PRSocketOptionData& aOpt)
|
||||
}
|
||||
|
||||
if (PR_SetSocketOption(mFD, &aOpt) != PR_SUCCESS) {
|
||||
SOCKET_LOG(("nsUDPSocket::SetSocketOption [this=%p] failed for type %d, "
|
||||
UDPSOCKET_LOG(("nsUDPSocket::SetSocketOption [this=%p] failed for type %d, "
|
||||
"error %d\n", this, aOpt.option, PR_GetError()));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user