private void SetBufSize(int rcvSize, int sndSize) { Debug.Assert(_fd != null); for (int i = 0; i < 2; ++i) { bool isSnd; string direction; string prop; int dfltSize; int sizeRequested; if (i == 0) { isSnd = false; direction = "receive"; prop = "Ice.UDP.RcvSize"; dfltSize = Network.GetRecvBufferSize(_fd); sizeRequested = rcvSize; _rcvSize = dfltSize; } else { isSnd = true; direction = "send"; prop = "Ice.UDP.SndSize"; dfltSize = Network.GetSendBufferSize(_fd); sizeRequested = sndSize; _sndSize = dfltSize; } // // Get property for buffer size if size not passed in. // if (sizeRequested == -1) { sizeRequested = _instance.Communicator.GetPropertyAsInt(prop) ?? dfltSize; } // // Check for sanity. // if (sizeRequested < (UdpOverhead + IceInternal.Protocol.headerSize)) { _instance.Logger.Warning($"Invalid {prop} value of {sizeRequested} adjusted to {dfltSize}"); sizeRequested = dfltSize; } if (sizeRequested != dfltSize) { // // Try to set the buffer size. The kernel will silently adjust // the size to an acceptable value. Then read the size back to // get the size that was actually set. // int sizeSet; if (i == 0) { Network.SetRecvBufferSize(_fd, sizeRequested); _rcvSize = Network.GetRecvBufferSize(_fd); sizeSet = _rcvSize; } else { Network.SetSendBufferSize(_fd, sizeRequested); _sndSize = Network.GetSendBufferSize(_fd); sizeSet = _sndSize; } // // Warn if the size that was set is less than the requested size // and we have not already warned // if (sizeSet < sizeRequested) { Ice.BufSizeWarnInfo winfo = _instance.GetBufSizeWarn(Ice.UDPEndpointType.Value); if ((isSnd && (!winfo.SndWarn || winfo.SndSize != sizeRequested)) || (!isSnd && (!winfo.RcvWarn || winfo.RcvSize != sizeRequested))) { _instance.Logger.Warning( $"UDP {direction} buffer size: requested size of {sizeRequested} adjusted to {sizeSet}"); if (isSnd) { _instance.SetSndBufSizeWarn(Ice.UDPEndpointType.Value, sizeRequested); } else { _instance.SetRcvBufSizeWarn(Ice.UDPEndpointType.Value, sizeRequested); } } } } } }