diff --git a/crypto/src/crypto/tls/DtlsRecordLayer.cs b/crypto/src/crypto/tls/DtlsRecordLayer.cs
index 5f3ec9e9c..69870dd91 100644
--- a/crypto/src/crypto/tls/DtlsRecordLayer.cs
+++ b/crypto/src/crypto/tls/DtlsRecordLayer.cs
@@ -1,6 +1,8 @@
using System;
using System.IO;
+#if !PORTABLE || DOTNET
using System.Net.Sockets;
+#endif
using Org.BouncyCastle.Utilities.Date;
@@ -312,24 +314,15 @@ namespace Org.BouncyCastle.Crypto.Tls
private int ReceiveDatagram(byte[] buf, int off, int len, int waitMillis)
{
- //try
- //{
- // return mTransport.Receive(buf, off, len, waitMillis);
- //}
- //catch (SocketTimeoutException e)
- //{
- // return -1;
- //}
- //catch (InterruptedIOException e)
- //{
- // e.bytesTransferred = 0;
- // throw e;
- //}
-
try
{
return mTransport.Receive(buf, off, len, waitMillis);
}
+ catch (TlsTimeoutException)
+ {
+ return -1;
+ }
+#if !PORTABLE || DOTNET
catch (SocketException e)
{
if (TlsUtilities.IsTimeout(e))
@@ -337,6 +330,12 @@ namespace Org.BouncyCastle.Crypto.Tls
throw e;
}
+#endif
+ //catch (InterruptedIOException e)
+ //{
+ // e.bytesTransferred = 0;
+ // throw e;
+ //}
}
private int ProcessRecord(int received, byte[] record, byte[] buf, int off)
diff --git a/crypto/src/crypto/tls/DtlsTransport.cs b/crypto/src/crypto/tls/DtlsTransport.cs
index bc09707c1..f2f716561 100644
--- a/crypto/src/crypto/tls/DtlsTransport.cs
+++ b/crypto/src/crypto/tls/DtlsTransport.cs
@@ -1,6 +1,8 @@
using System;
using System.IO;
+#if !PORTABLE || DOTNET
using System.Net.Sockets;
+#endif
namespace Org.BouncyCastle.Crypto.Tls
{
@@ -44,15 +46,11 @@ namespace Org.BouncyCastle.Crypto.Tls
mRecordLayer.Fail(fatalAlert.AlertDescription);
throw fatalAlert;
}
- //catch (InterruptedIOException e)
- //{
- // throw e;
- //}
- catch (IOException e)
+ catch (TlsTimeoutException e)
{
- mRecordLayer.Fail(AlertDescription.internal_error);
throw e;
}
+#if !PORTABLE || DOTNET
catch (SocketException e)
{
if (TlsUtilities.IsTimeout(e))
@@ -61,6 +59,16 @@ namespace Org.BouncyCastle.Crypto.Tls
mRecordLayer.Fail(AlertDescription.internal_error);
throw new TlsFatalAlert(AlertDescription.internal_error, e);
}
+#endif
+ //catch (InterruptedIOException e)
+ //{
+ // throw e;
+ //}
+ catch (IOException e)
+ {
+ mRecordLayer.Fail(AlertDescription.internal_error);
+ throw e;
+ }
catch (Exception e)
{
mRecordLayer.Fail(AlertDescription.internal_error);
@@ -86,15 +94,11 @@ namespace Org.BouncyCastle.Crypto.Tls
mRecordLayer.Fail(fatalAlert.AlertDescription);
throw fatalAlert;
}
- //catch (InterruptedIOException e)
- //{
- // throw e;
- //}
- catch (IOException e)
+ catch (TlsTimeoutException e)
{
- mRecordLayer.Fail(AlertDescription.internal_error);
throw e;
}
+#if !PORTABLE || DOTNET
catch (SocketException e)
{
if (TlsUtilities.IsTimeout(e))
@@ -103,6 +107,16 @@ namespace Org.BouncyCastle.Crypto.Tls
mRecordLayer.Fail(AlertDescription.internal_error);
throw new TlsFatalAlert(AlertDescription.internal_error, e);
}
+#endif
+ //catch (InterruptedIOException e)
+ //{
+ // throw e;
+ //}
+ catch (IOException e)
+ {
+ mRecordLayer.Fail(AlertDescription.internal_error);
+ throw e;
+ }
catch (Exception e)
{
mRecordLayer.Fail(AlertDescription.internal_error);
diff --git a/crypto/src/crypto/tls/TlsException.cs b/crypto/src/crypto/tls/TlsException.cs
index cea9e3e77..18ca22a58 100644
--- a/crypto/src/crypto/tls/TlsException.cs
+++ b/crypto/src/crypto/tls/TlsException.cs
@@ -6,6 +6,16 @@ namespace Org.BouncyCastle.Crypto.Tls
public class TlsException
: IOException
{
+ public TlsException()
+ : base()
+ {
+ }
+
+ public TlsException(string message)
+ : base(message)
+ {
+ }
+
public TlsException(string message, Exception cause)
: base(message, cause)
{
diff --git a/crypto/src/crypto/tls/TlsTimeoutException.cs b/crypto/src/crypto/tls/TlsTimeoutException.cs
new file mode 100644
index 000000000..71931e43d
--- /dev/null
+++ b/crypto/src/crypto/tls/TlsTimeoutException.cs
@@ -0,0 +1,23 @@
+using System;
+
+namespace Org.BouncyCastle.Crypto.Tls
+{
+ public class TlsTimeoutException
+ : TlsException
+ {
+ public TlsTimeoutException()
+ : base()
+ {
+ }
+
+ public TlsTimeoutException(string message)
+ : base(message)
+ {
+ }
+
+ public TlsTimeoutException(string message, Exception cause)
+ : base(message, cause)
+ {
+ }
+ }
+}
diff --git a/crypto/src/crypto/tls/TlsUtilities.cs b/crypto/src/crypto/tls/TlsUtilities.cs
index 5aad6b0a1..2fb631edd 100644
--- a/crypto/src/crypto/tls/TlsUtilities.cs
+++ b/crypto/src/crypto/tls/TlsUtilities.cs
@@ -1,8 +1,9 @@
using System;
using System.Collections;
+#if !PORTABLE || DOTNET
using System.Net.Sockets;
+#endif
using System.IO;
-using System.Text;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
@@ -2347,11 +2348,15 @@ namespace Org.BouncyCastle.Crypto.Tls
return v;
}
+#if !PORTABLE || DOTNET
public static bool IsTimeout(SocketException e)
{
- // TODO Net 2.0+
- //return SocketError.TimedOut == e.SocketErrorCode;
+#if NET_1_1
return 10060 == e.ErrorCode;
+#else
+ return SocketError.TimedOut == e.SocketErrorCode;
+#endif
}
+#endif
}
}
|