From c9c0f8d58c8d707b5a6b644bc2954d2f23349e14 Mon Sep 17 00:00:00 2001 From: Jason Duell Date: Fri, 5 Apr 2013 13:52:12 -0700 Subject: [PATCH] Bug 855906 - Convert nsIWebsocketChannel pingInterval to seconds r=mcmanus --- .../websocket/BaseWebSocketChannel.cpp | 22 ++++++++++++------- .../protocol/websocket/BaseWebSocketChannel.h | 8 +++---- .../websocket/WebSocketChannelParent.cpp | 7 ++++-- .../websocket/nsIWebSocketChannel.idl | 7 +++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp index 346d0d5831c3..f8078b0f767e 100644 --- a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp +++ b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp @@ -121,40 +121,46 @@ BaseWebSocketChannel::SetProtocol(const nsACString &aProtocol) } NS_IMETHODIMP -BaseWebSocketChannel::GetPingInterval(uint32_t *aMilliSeconds) +BaseWebSocketChannel::GetPingInterval(uint32_t *aSeconds) { - *aMilliSeconds = mPingInterval; + // stored in ms but should only have second resolution + MOZ_ASSERT(!(mPingInterval % 1000)); + + *aSeconds = mPingInterval / 1000; return NS_OK; } NS_IMETHODIMP -BaseWebSocketChannel::SetPingInterval(uint32_t aMilliSeconds) +BaseWebSocketChannel::SetPingInterval(uint32_t aSeconds) { if (mWasOpened) { return NS_ERROR_IN_PROGRESS; } - mPingInterval = aMilliSeconds; + mPingInterval = aSeconds * 1000; mClientSetPingInterval = 1; return NS_OK; } NS_IMETHODIMP -BaseWebSocketChannel::GetPingTimeout(uint32_t *aMilliSeconds) +BaseWebSocketChannel::GetPingTimeout(uint32_t *aSeconds) { - *aMilliSeconds = mPingResponseTimeout; + // stored in ms but should only have second resolution + MOZ_ASSERT(!(mPingResponseTimeout % 1000)); + + *aSeconds = mPingResponseTimeout / 1000; return NS_OK; } NS_IMETHODIMP -BaseWebSocketChannel::SetPingTimeout(uint32_t aMilliSeconds) +BaseWebSocketChannel::SetPingTimeout(uint32_t aSeconds) { if (mWasOpened) { return NS_ERROR_IN_PROGRESS; } - mPingResponseTimeout = aMilliSeconds; + mPingResponseTimeout = aSeconds * 1000; mClientSetPingTimeout = 1; return NS_OK; diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.h b/netwerk/protocol/websocket/BaseWebSocketChannel.h index 1fbc0923c2c1..2e3611a0dd7f 100644 --- a/netwerk/protocol/websocket/BaseWebSocketChannel.h +++ b/netwerk/protocol/websocket/BaseWebSocketChannel.h @@ -42,10 +42,10 @@ class BaseWebSocketChannel : public nsIWebSocketChannel, NS_IMETHOD GetExtensions(nsACString &aExtensions); NS_IMETHOD GetProtocol(nsACString &aProtocol); NS_IMETHOD SetProtocol(const nsACString &aProtocol); - NS_IMETHOD GetPingInterval(uint32_t *aMilliSeconds); - NS_IMETHOD SetPingInterval(uint32_t aMilliSeconds); - NS_IMETHOD GetPingTimeout(uint32_t *aMilliSeconds); - NS_IMETHOD SetPingTimeout(uint32_t aMilliSeconds); + NS_IMETHOD GetPingInterval(uint32_t *aSeconds); + NS_IMETHOD SetPingInterval(uint32_t aSeconds); + NS_IMETHOD GetPingTimeout(uint32_t *aSeconds); + NS_IMETHOD SetPingTimeout(uint32_t aSeconds); protected: nsCOMPtr mOriginalURI; diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.cpp b/netwerk/protocol/websocket/WebSocketChannelParent.cpp index 176171d27e64..04d0240f83e1 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelParent.cpp @@ -88,10 +88,13 @@ WebSocketChannelParent::RecvAsyncOpen(const URIParams& aURI, // only use ping values from child if they were overridden by client code. if (aClientSetPingInterval) { - mChannel->SetPingInterval(aPingInterval); + // IDL allows setting in seconds, so must be multiple of 1000 ms + MOZ_ASSERT(aPingInterval >= 1000 && !(aPingInterval % 1000)); + mChannel->SetPingInterval(aPingInterval / 1000); } if (aClientSetPingTimeout) { - mChannel->SetPingTimeout(aPingTimeout); + MOZ_ASSERT(aPingTimeout >= 1000 && !(aPingTimeout % 1000)); + mChannel->SetPingTimeout(aPingTimeout / 1000); } rv = mChannel->AsyncOpen(uri, aOrigin, this, nullptr); diff --git a/netwerk/protocol/websocket/nsIWebSocketChannel.idl b/netwerk/protocol/websocket/nsIWebSocketChannel.idl index 5b700efa9521..3fd14258465f 100644 --- a/netwerk/protocol/websocket/nsIWebSocketChannel.idl +++ b/netwerk/protocol/websocket/nsIWebSocketChannel.idl @@ -135,7 +135,7 @@ interface nsIWebSocketChannel : nsISupports in unsigned long length); /** - * This value determines how often (in milliseconds) websocket keepalive + * This value determines how often (in seconds) websocket keepalive * pings are sent. If set to 0 (the default), no pings are ever sent. * * This value can currently only be set before asyncOpen is called, else @@ -147,8 +147,9 @@ interface nsIWebSocketChannel : nsISupports attribute unsigned long pingInterval; /** - * This value determines how long (in milliseconds) the websocket waits for - * the server to reply to a ping that has been sent. + * This value determines how long (in seconds) the websocket waits for + * the server to reply to a ping that has been sent before considering the + * connection broken. * * This value can currently only be set before asyncOpen is called, else * NS_ERROR_IN_PROGRESS is thrown.