implement ProjectInstance.GetItems() which is now actually used.
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls / RecordProtocol.cs
index 7806a39bcc0e7013ac5841264227475a66f544da..9ef45da2c4452226391c9bf53552677fdb4298d8 100644 (file)
@@ -1,6 +1,6 @@
 // Transport Security Layer (TLS)
 // Copyright (c) 2003-2004 Carlos Guzman Alvarez
-// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -35,6 +35,8 @@ namespace Mono.Security.Protocol.Tls
        {
                #region Fields
 
+               private static ManualResetEvent record_processing = new ManualResetEvent (true);
+
                protected Stream        innerStream;
                protected Context       context;
 
@@ -309,13 +311,14 @@ namespace Mono.Security.Protocol.Tls
 
                public IAsyncResult BeginReceiveRecord(Stream record, AsyncCallback callback, object state)
                {
-                       if (this.context.ConnectionEnd)
+                       if (this.context.ReceivedConnectionEnd)
                        {
                                throw new TlsException(
                                        AlertDescription.InternalError,
                                        "The session is finished and it's no longer valid.");
                        }
 
+                       record_processing.Reset ();
                        byte[] recordTypeBuffer = new byte[1];
 
                        ReceiveRecordAsyncResult internalResult = new ReceiveRecordAsyncResult(callback, state, recordTypeBuffer, record);
@@ -426,8 +429,10 @@ namespace Mono.Security.Protocol.Tls
 
                        if (internalResult.CompletedWithError)
                                throw internalResult.AsyncException;
-                       else
-                               return internalResult.ResultingBuffer;
+
+                       byte[] result = internalResult.ResultingBuffer;
+                       record_processing.Set ();
+                       return result;
                }
 
                public byte[] ReceiveRecord(Stream record)
@@ -575,7 +580,7 @@ namespace Mono.Security.Protocol.Tls
                                switch (alertDesc)
                                {
                                        case AlertDescription.CloseNotify:
-                                               this.context.ConnectionEnd = true;
+                                               this.context.ReceivedConnectionEnd = true;
                                                break;
                                }
                                break;
@@ -619,9 +624,8 @@ namespace Mono.Security.Protocol.Tls
                        // Write record
                        this.SendRecord (ContentType.Alert, new byte[2] { (byte) level, (byte) description });
 
-                       if (close)
-                       {
-                               this.context.ConnectionEnd = true;
+                       if (close) {
+                               this.context.SentConnectionEnd = true;
                        }
                }
 
@@ -690,7 +694,7 @@ namespace Mono.Security.Protocol.Tls
 
                public IAsyncResult BeginSendRecord(ContentType contentType, byte[] recordData, AsyncCallback callback, object state)
                {
-                       if (this.context.ConnectionEnd)
+                       if (this.context.SentConnectionEnd)
                        {
                                throw new TlsException(
                                        AlertDescription.InternalError,
@@ -740,7 +744,7 @@ namespace Mono.Security.Protocol.Tls
                        int                     offset,
                        int                     count)
                {
-                       if (this.context.ConnectionEnd)
+                       if (this.context.SentConnectionEnd)
                        {
                                throw new TlsException(
                                        AlertDescription.InternalError,
@@ -838,7 +842,6 @@ namespace Mono.Security.Protocol.Tls
                                {
                                        this.Context.RecordProtocol.SendAlert(AlertDescription.DecryptionFailed);
                                }
-
                                throw;
                        }