After a paste in the other options - I googled someting more specific
about the socketoptions in .Net, and here`s what I came up with - The
intervals are static, but it`s quick and clean. I`d appreciate them
appearing in the main source tree (if it does not break standards,
expectations and so on), but it doesn`t seem like a huge "patch" so I
could add it when I upgrade.
private void SetKeepalives(ref Socket sTmpSocket, bool bOnOff, Int32
iKeepAliveInterval, Int32 iKeepAliveTime)
{
//Set keepalive
sTmpSocket.SetSocketOption(SocketOptionLevel.Tcp,
SocketOptionName.KeepAlive, 1);
// marshal the equivalent of the native structure into a byte
array
uint dummy = 0;
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
BitConverter.GetBytes((uint)(bOnOff ? 1 :
0)).CopyTo(inOptionValues, 0);
BitConverter.GetBytes((uint)iKeepAliveTime).CopyTo(inOptionValues,
Marshal.SizeOf(dummy));
BitConverter.GetBytes((uint)iKeepAliveInterval).CopyTo(inOptionValues,
Marshal.SizeOf(dummy) * 2);
// of course there are other ways to marshal up this byte
array, this is just one way
// call WSAIoctl via IOControl
int ignore = s.IOControl(IOControlCode.KeepAliveValues,
inOptionValues, null);
}
public virtual void Connect()
{
try
{
this.IPAddress = this.GetIPAddress(this.dataSource,
AddressFamily.InterNetwork);
IPEndPoint endPoint = new IPEndPoint(this.IPAddress,
this.portNumber);
this.socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
#if (!NET_CF)
SetKeepalives(ref this.socket,true,60,600);
// Set Receive Buffer size.
this.socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveBuffer, packetSize);
// Set Send Buffer size.
this.socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendBuffer, packetSize);
#endif
// Disables the Nagle algorithm for send coalescing.
this.socket.SetSocketOption(SocketOptionLevel.Tcp,
SocketOptionName.NoDelay, 1);
// Make the socket to connect to the Server
this.socket.Connect(endPoint);
this.networkStream = new NetworkStream(this.socket, true);
GC.SuppressFinalize(this.socket);
GC.SuppressFinalize(this.networkStream);
}
catch (SocketException)
{
throw new IscException(IscCodes.isc_arg_gds,
IscCodes.isc_network_error, dataSource);
}
}
--
Sanity is a sin!
------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider