File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed
src/MongoDB.Driver.Core/Core/Connections Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -250,13 +250,30 @@ private Socket CreateSocket(EndPoint endPoint)
250
250
}
251
251
252
252
var socket = new Socket ( addressFamily , SocketType . Stream , ProtocolType . Tcp ) ;
253
- var keepAliveValues = new KeepAliveValues
253
+
254
+ // not all platforms support IOControl
255
+ try
254
256
{
255
- OnOff = 1 ,
256
- KeepAliveTime = 300000 , // 300 seconds in milliseconds
257
- KeepAliveInterval = 10000 // 10 seconds in milliseconds
258
- } ;
259
- socket . IOControl ( IOControlCode . KeepAliveValues , keepAliveValues . ToBytes ( ) , null ) ;
257
+ var keepAliveValues = new KeepAliveValues
258
+ {
259
+ OnOff = 1 ,
260
+ KeepAliveTime = 300000 , // 300 seconds in milliseconds
261
+ KeepAliveInterval = 10000 // 10 seconds in milliseconds
262
+ } ;
263
+ socket . IOControl ( IOControlCode . KeepAliveValues , keepAliveValues . ToBytes ( ) , null ) ;
264
+ }
265
+ catch ( PlatformNotSupportedException )
266
+ {
267
+ // most platforms should support this call to SetSocketOption, but just in case call it in a try/catch also
268
+ try
269
+ {
270
+ socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
271
+ }
272
+ catch ( PlatformNotSupportedException )
273
+ {
274
+ // ignore PlatformNotSupportedException
275
+ }
276
+ }
260
277
261
278
return socket ;
262
279
}
You can’t perform that action at this time.
0 commit comments