Exemple #1
0
        public RequestProxy(IncomingMessageEx request)
        {
            this.proxies = new List <IProxie>(1);
            this.bestResponseStatusCode = int.MaxValue;

            this.ServerTransactionId = request.TransactionId;
            this.ConnectionAddresses = request.ConnectionAddresses;

            this.Headers      = request.Headers;
            this.Content      = request.Content;
            this.bufferHandle = request.DetachBuffers();
        }
Exemple #2
0
		public RequestProxy(IncomingMessageEx request)
		{
			this.proxies = new List<IProxie>(1);
			this.bestResponseStatusCode = int.MaxValue;

			this.ServerTransactionId = request.TransactionId;
			this.ConnectionAddresses = request.ConnectionAddresses;

			this.Headers = request.Headers;
			this.Content = request.Content;
			this.bufferHandle = request.DetachBuffers();
		}
		private void Validate(string messageText, bool addKeepAlive, int messagesCount, IEnumerable<int> splitSizes, bool detachBuffer, bool websocket)
		{
			var message = Encoding.UTF8.GetBytes(messageText);

			var expected = new SipMessageReader();
			expected.SetDefaultValue();
			int parsed = expected.Parse(message, 0, message.Length);
			expected.SetArray(message);
			if (expected.ContentLength < 0)
				expected.ContentLength = 0;
			var expectedUri = expected.RequestUri.Value.ToString();
			var content = Encoding.UTF8.GetString(message, parsed, message.Length - parsed);

			if (addKeepAlive)
				message = Encoding.UTF8.GetBytes("\r\n\r\n" + messageText + "\r\n\r\n\r\n\r\n\r\n\r\n");

			var extra = new byte[0];
			if (websocket)
				extra = PrepareForWebsocket(message);

			var stream = CreateStream(messagesCount, extra, message);
			int headersLength = messageText.IndexOf("\r\n\r\n") + 4;
			var headersText = messageText.Substring(0, headersLength);

			int oldUsedBuffers = EventArgsManager.Created - EventArgsManager.Queued;

			ServerAsyncEventArgs e = null;
			using (var connection = new Connection())
			using (var threads = new Threads(connection))
			{
				if (websocket)
					connection.UpgradeToWebsocket();

				foreach (int splitSize in splitSizes)
				{
					int realMessageCount = 0;

					for (int offset = 0; offset < stream.Length; offset += splitSize)
					{
						var info = "Split by: " + splitSize + "; Message #: " + realMessageCount +
							"\r\nMessage Sizes: " + message.Length + " " + (message.Length - content.Length) + " " + content.Length;

						if (e == null)
							e = EventArgsManager.Get();

						e.BytesTransferred = Math.Min(splitSize, stream.Length - offset);
						Buffer.BlockCopy(stream, offset, e.Buffer, e.Offset, e.BytesTransferred);

						bool closeConnection;
						for (bool repeat = true; repeat; )
						{
							//repeat = connection.Proccess(ref e, out closeConnection);
							repeat = threads.Proccess(ref e, out closeConnection);

							Assert.IsFalse(closeConnection, info);

							if (connection.IsMessageReady)
							{
								var actualHeaders = Encoding.UTF8.GetString(connection.Header.Array, connection.Header.Offset, connection.Header.Count);

								Assert.AreEqual(expected.Method, connection.Reader.Method, info);
								Assert.AreEqual(expectedUri, connection.Reader.RequestUri.Value.ToString(), info);

								Assert.AreEqual(headersLength, connection.Header.Count);
								Assert.AreEqual(headersText, actualHeaders);

								Assert.AreEqual(expected.ContentLength, connection.Content.Count);
								if (expected.ContentLength > 0)
									Assert.AreEqual(content, Encoding.UTF8.GetString(connection.Content.Array, connection.Content.Offset, connection.Content.Count), info);

								BufferHandle handle = new BufferHandle();
								if (detachBuffer)
									handle = connection.Dettach(ref e);

								connection.ResetState();
								realMessageCount++;

								if (detachBuffer)
									handle.Free();
							}
						}
					}

					EventArgsManager.Put(ref e);

					Assert.AreEqual(messagesCount, realMessageCount);
				}
			}

			Assert.AreEqual(oldUsedBuffers, EventArgsManager.Created - EventArgsManager.Queued);
		}