[CSHARP-1151] C# doesn't have a "keepAlive" option, which exists in Java driver Created: 17/Dec/14  Updated: 02/Nov/18  Resolved: 02/Jan/15

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: None
Fix Version/s: 2.0

Type: Improvement Priority: Major - P3
Reporter: Boris Uchitel Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-1156 socketKeepAlive in C# Closed
Related
Case:

 Description   

Looks like there is no way to set keepAlive for the connection socket in C# opposed to Java driver, which have the following property:

socketKeepAlive(boolean socketKeepAlive)



 Comments   
Comment by Robert Stam [ 02/Jan/15 ]

The implementation we've chosen is more general than just adding support for KeepAlive. We've added a SocketConfigurator hook that gets called when a socket is created, and you can configure the Socket anyway you want in your callback.

For example, to set KeepAlive to true, you could use the hook this way:

var url = new MongoUrl("mongodb://localhost");
var clientSettings = MongoClientSettings.FromUrl(url);
Action<Socket> socketConfigurator = s => s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
clientSettings.ClusterConfigurator = cb => cb.ConfigureTcp(tcp => tcp.With(socketConfigurator: socketConfigurator));
var client = new MongoClient(clientSettings);

Comment by Githook User [ 01/Jan/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1151: Introduce a SocketConfigurator in TcpStreamSettings that can be used to configure a socket (e.g. setting KeepAlive).
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/472b3930695288a5efdaa3a21f7ed5d9e96a2880

Comment by Craig Wilson [ 23/Dec/14 ]

There is no current way to set this. We'll look at making this available in the next version of the driver.

Generated at Wed Feb 07 21:38:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.