Beispiel #1
0
        public static async Task <bool> InitiateUpgradeAsync(StreamUpgradeInitiator upgradeInitiator, OutWrapper <IConnection> connectionWrapper,
                                                             ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeSpan timeout)
        {
            IConnection connection         = connectionWrapper.Value;
            string      upgradeContentType = upgradeInitiator.GetNextUpgrade();

            while (upgradeContentType != null)
            {
                EncodedUpgrade encodedUpgrade = new EncodedUpgrade(upgradeContentType);
                // write upgrade request framing for synchronization
                await connection.WriteAsync(encodedUpgrade.EncodedBytes, 0, encodedUpgrade.EncodedBytes.Length, true, timeout);

                byte[] buffer = new byte[1];

                // read upgrade response framing
                int size = await connection.ReadAsync(buffer, 0, buffer.Length, timeout);

                if (!ValidateUpgradeResponse(buffer, size, decoder)) // we have a problem
                {
                    return(false);
                }

                // initiate wire upgrade
                ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
                Stream           upgradedStream   = await upgradeInitiator.InitiateUpgradeAsync(connectionStream);

                // and re-wrap connection
                connection = new StreamConnection(upgradedStream, connectionStream);
                connectionWrapper.Value = connection;

                upgradeContentType = upgradeInitiator.GetNextUpgrade();
            }

            return(true);
        }
Beispiel #2
0
        public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref IConnection connection,
                                           ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref TimeoutHelper timeoutHelper)
        {
            string upgradeContentType = upgradeInitiator.GetNextUpgrade();

            while (upgradeContentType != null)
            {
                EncodedUpgrade encodedUpgrade = new EncodedUpgrade(upgradeContentType);
                // write upgrade request framing for synchronization
                connection.Write(encodedUpgrade.EncodedBytes, 0, encodedUpgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
                byte[] buffer = new byte[1];

                // read upgrade response framing
                int size = connection.Read(buffer, 0, buffer.Length, timeoutHelper.RemainingTime());

                if (!ValidateUpgradeResponse(buffer, size, decoder)) // we have a problem
                {
                    return(false);
                }

                // initiate wire upgrade
                ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
                Stream           upgradedStream   = upgradeInitiator.InitiateUpgrade(connectionStream);

                // and re-wrap connection
                connection = new StreamConnection(upgradedStream, connectionStream);

                upgradeContentType = upgradeInitiator.GetNextUpgrade();
            }

            return(true);
        }
Beispiel #3
0
 private bool Begin()
 {
     for (string str = this.upgradeInitiator.GetNextUpgrade(); str != null; str = this.upgradeInitiator.GetNextUpgrade())
     {
         EncodedUpgrade upgrade = new EncodedUpgrade(str);
         IAsyncResult   result  = this.connection.BeginWrite(upgrade.EncodedBytes, 0, upgrade.EncodedBytes.Length, true, this.timeoutHelper.RemainingTime(), onWriteUpgradeBytes, this);
         if (!result.CompletedSynchronously)
         {
             return(false);
         }
         if (!this.CompleteWriteUpgradeBytes(result))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #4
0
 public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref IConnection connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref TimeoutHelper timeoutHelper)
 {
     for (string str = upgradeInitiator.GetNextUpgrade(); str != null; str = upgradeInitiator.GetNextUpgrade())
     {
         EncodedUpgrade upgrade = new EncodedUpgrade(str);
         connection.Write(upgrade.EncodedBytes, 0, upgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
         byte[] buffer = new byte[1];
         int    count  = connection.Read(buffer, 0, buffer.Length, timeoutHelper.RemainingTime());
         if (!ValidateUpgradeResponse(buffer, count, decoder))
         {
             return(false);
         }
         ConnectionStream stream  = new ConnectionStream(connection, defaultTimeouts);
         Stream           stream2 = upgradeInitiator.InitiateUpgrade(stream);
         connection = new StreamConnection(stream2, stream);
     }
     return(true);
 }
 public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref IConnection connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref TimeoutHelper timeoutHelper)
 {
     for (string str = upgradeInitiator.GetNextUpgrade(); str != null; str = upgradeInitiator.GetNextUpgrade())
     {
         EncodedUpgrade upgrade = new EncodedUpgrade(str);
         connection.Write(upgrade.EncodedBytes, 0, upgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
         byte[] buffer = new byte[1];
         int count = connection.Read(buffer, 0, buffer.Length, timeoutHelper.RemainingTime());
         if (!ValidateUpgradeResponse(buffer, count, decoder))
         {
             return false;
         }
         ConnectionStream stream = new ConnectionStream(connection, defaultTimeouts);
         Stream stream2 = upgradeInitiator.InitiateUpgrade(stream);
         connection = new StreamConnection(stream2, stream);
     }
     return true;
 }
 private bool Begin()
 {
     for (string str = this.upgradeInitiator.GetNextUpgrade(); str != null; str = this.upgradeInitiator.GetNextUpgrade())
     {
         EncodedUpgrade upgrade = new EncodedUpgrade(str);
         IAsyncResult result = this.connection.BeginWrite(upgrade.EncodedBytes, 0, upgrade.EncodedBytes.Length, true, this.timeoutHelper.RemainingTime(), onWriteUpgradeBytes, this);
         if (!result.CompletedSynchronously)
         {
             return false;
         }
         if (!this.CompleteWriteUpgradeBytes(result))
         {
             return false;
         }
     }
     return true;
 }