コード例 #1
0
        public static void Start(int controlPort)
        {
            if (thread != null)
                throw new InvalidOperationException("ContorlListener already started");
            port = controlPort;

            thread = Threads.Create("Controller Listener", Run, null);
            thread.Start();
        }
コード例 #2
0
        public VanillaSession(VanillaWorld world, Client player)
            : base(player)
        {
            this.World = world;
            this.Vanilla = world;

            OreTracker = new OreTracker(player);

            if (player.MinecraftUsername == null)
                throw new ArgumentException("Player must be logged in, missing minecraftusername");

            thread = Threads.Create(this, RunServerReader, WatchdogKilled);
            thread.User = Player.MinecraftUsername;
            thread.Start();
        }
コード例 #3
0
ファイル: ConnectionTest.cs プロジェクト: hungdluit/sipserver
		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);
		}
コード例 #4
0
ファイル: BackupProxy.cs プロジェクト: mctraveler/MineSharp
 public static void Start()
 {
     thread = Threads.Create("Backup", BackupThreadRun, null);
     thread.Start();
 }