<commit_before>
/****************************************************************************

Tilde

Copyright (c) 2008 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Reflection;

namespace Tilde.LuaDebugger
{
	public class Target
	{
		private DebugManager mDebugManager;
		private Form mForm;
		private IConnection mConnection;
		private Thread m_thread;
		private AutoResetEvent mHostEvent;
		private AutoResetEvent mTargetEvent;
		private MessageQueue mMessageQueue;
		private bool m_shutdown = false;

		StateUpdateEventArgs mLastUpdateMessage;
		ReceiveMessageBuffer m_readBuffer;
		SendMessageBuffer m_writeBuffer;

		private object m_lock = new object();

		public Target(DebugManager debugger, Form form, IConnection connection)
		{
			mDebugManager = debugger;
			mForm = form;
			mConnection = connection;

			mConnection.ConnectionClosed += new ConnectionClosedEventHandler(Connection_ConnectionClosed);
			mConnection.ConnectionAborted += new ConnectionAbortedEventHandler(Connection_ConnectionAborted);
			mConnection.DataReceived += new ConnectionDataReceivedEventHandler(Connection_DataReceived);

			mMessageQueue = new MessageQueue();
			mHostEvent = new AutoResetEvent(false);
			mTargetEvent = new AutoResetEvent(false);

			m_readBuffer = new ReceiveMessageBuffer(512 * 1024);
			m_writeBuffer = new SendMessageBuffer(4 * 1024);

			m_thread = new Thread(new ThreadStart(ThreadMain));
			m_thread.Name = "LuaDebuggerThread";
			m_thread.Start();
		}

		public Form Form
		{
			get { return mForm; }
		}

		public MessageQueue MessageQueue
		{
			get { return mMessageQueue; }
		}

		public AutoResetEvent Event
		{
			get { return mHostEvent; }
		}

		public bool IsShutdown
		{
			get { return m_shutdown; }
		}

		void ProcessEvents()
		{
			while(!mMessageQueue.Empty)
			{
				// Retrieve a message from the queue
				MessageQueue.Message message = mMessageQueue.Pop();

				// Execute it
				message.Invoke();
			}
		}

		void Abort()
		{
			m_shutdown = true;
			mHostEvent.Set();
		}

		void Abort(string message)
		{
			OnErrorMessage("Connection error", message);
			Abort();
		}

		private delegate void VoidDelegate();
		private delegate object ReturnDelegate();<commit_msg>* Hide the annoying forcibly closed socket connection error exception dialog.<commit_after>
/****************************************************************************

Tilde

Copyright (c) 2008 Tantalus Media Pty

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Reflection;

namespace Tilde.LuaDebugger
{
	public class Target
	{
		private DebugManager mDebugManager;
		private Form mForm;
		private IConnection mConnection;
		private Thread m_thread;
		private AutoResetEvent mHostEvent;
		private AutoResetEvent mTargetEvent;
		private MessageQueue mMessageQueue;
		private bool m_shutdown = false;

		StateUpdateEventArgs mLastUpdateMessage;
		ReceiveMessageBuffer m_readBuffer;
		SendMessageBuffer m_writeBuffer;

		private object m_lock = new object();

		public Target(DebugManager debugger, Form form, IConnection connection)
		{
			mDebugManager = debugger;
			mForm = form;
			mConnection = connection;

			mConnection.ConnectionClosed += new ConnectionClosedEventHandler(Connection_ConnectionClosed);
			mConnection.ConnectionAborted += new ConnectionAbortedEventHandler(Connection_ConnectionAborted);
			mConnection.DataReceived += new ConnectionDataReceivedEventHandler(Connection_DataReceived);

			mMessageQueue = new MessageQueue();
			mHostEvent = new AutoResetEvent(false);
			mTargetEvent = new AutoResetEvent(false);

			m_readBuffer = new ReceiveMessageBuffer(512 * 1024);
			m_writeBuffer = new SendMessageBuffer(4 * 1024);

			m_thread = new Thread(new ThreadStart(ThreadMain));
			m_thread.Name = "LuaDebuggerThread";
			m_thread.Start();
		}

		public Form Form
		{
			get { return mForm; }
		}

		public MessageQueue MessageQueue
		{
			get { return mMessageQueue; }
		}

		public AutoResetEvent Event
		{
			get { return mHostEvent; }
		}

		public bool IsShutdown
		{
			get { return m_shutdown; }
		}

		void ProcessEvents()
		{
			while(!mMessageQueue.Empty)
			{
				// Retrieve a message from the queue
				MessageQueue.Message message = mMessageQueue.Pop();

				// Execute it
				message.Invoke();
			}
		}

		void Abort()
		{
			m_shutdown = true;
			mHostEvent.Set();
		}

		void Abort(string message)
		{
			if (!message.Contains("forcibly closed"))
				OnErrorMessage("Connection error", message);
			Abort();
		}

		private delegate void VoidDelegate();
		private delegate object ReturnDelegate();
{'fraction_non_alphanumeric': 0.10684377707190297, 'fraction_numerical': 0.004620271440947156, 'mean_word_length': 4.696546052631579, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6412364', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1771, 'n_words': 666}