Bug 855906 - Convert nsIWebsocketChannel pingInterval to seconds r=mcmanus

This commit is contained in:
Jason Duell 2013-04-05 13:52:12 -07:00
parent 3a3bac1699
commit 54bf6f54da
4 changed files with 27 additions and 17 deletions

View File

@ -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;

View File

@ -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<nsIURI> mOriginalURI;

View File

@ -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);

View File

@ -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.