Bug 1713689 - Add a way to set the don't-frament flag to nsUDPSocket r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D116430
This commit is contained in:
Dragana Damjanovic 2021-06-15 13:51:33 +00:00
Родитель 294f10eff7
Коммит 2c49a89614
3 изменённых файлов: 39 добавлений и 0 удалений

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

@ -292,6 +292,14 @@ interface nsIUDPSocket : nsISupports
* The size of the send buffer. Default depends on the OS. * The size of the send buffer. Default depends on the OS.
*/ */
[noscript] attribute long sendBufferSize; [noscript] attribute long sendBufferSize;
/**
* dontFragment
*
* The don't fragment flag.
* The socket must be initialized before calling this function.
*/
[noscript] attribute boolean dontFragment;
}; };
/** /**

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

@ -1398,6 +1398,29 @@ nsUDPSocket::SetRecvBufferSize(int size) {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsUDPSocket::GetDontFragment(bool* dontFragment) {
// Bug 1252759 - missing support for GetSocketOption
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsUDPSocket::SetDontFragment(bool dontFragment) {
if (NS_WARN_IF(!mFD)) {
return NS_ERROR_NOT_INITIALIZED;
}
PRSocketOptionData opt;
opt.option = PR_SockOpt_DontFrag;
opt.value.dont_fragment = dontFragment;
nsresult rv = SetSocketOption(opt);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsUDPSocket::GetSendBufferSize(int* size) { nsUDPSocket::GetSendBufferSize(int* size) {
// Bug 1252759 - missing support for GetSocketOption // Bug 1252759 - missing support for GetSocketOption

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

@ -110,6 +110,14 @@ nsresult HttpConnectionUDP::Init(nsHttpConnectionInfo* info,
return rv; return rv;
} }
if (peerAddr.raw.family == AF_INET) {
rv = mSocket->SetDontFragment(true);
if (NS_FAILED(rv)) {
LOG(("HttpConnectionUDP::Init SetDontFragment failed %d [this=%p]",
static_cast<uint32_t>(rv), this));
}
}
// get the resulting socket address. // get the resulting socket address.
rv = mSocket->GetLocalAddr(getter_AddRefs(mSelfAddr)); rv = mSocket->GetLocalAddr(getter_AddRefs(mSelfAddr));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {