2008-12-19 00:39:56 +00:00
|
|
|
/***************************************************************************
|
2008-12-19 00:36:04 +00:00
|
|
|
* Copyright (C) 2008 by Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of pokerth_console. *
|
|
|
|
|
* pokerth_console is free software: you can redistribute it and/or *
|
|
|
|
|
* modify it under the terms of the GNU Affero General Public License *
|
|
|
|
|
* as published by the Free Software Foundation, either version 3 of *
|
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* pokerth_console is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the *
|
|
|
|
|
* GNU Affero General Public License along with pokerth_console. *
|
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2008-12-23 17:24:31 +00:00
|
|
|
using System.Threading;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
2008-12-19 00:36:04 +00:00
|
|
|
using System.IO;
|
|
|
|
|
|
2008-12-23 17:24:31 +00:00
|
|
|
namespace pokerth_lib
|
2008-12-19 00:36:04 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
abstract class NetThread
|
2008-12-19 00:36:04 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
public NetThread(NetworkStream stream)
|
2008-12-19 00:36:04 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
m_thread = new Thread(ThreadProc);
|
|
|
|
|
m_terminateFlag = false;
|
|
|
|
|
m_terminateFlagMutex = new System.Object();
|
|
|
|
|
m_netStream = stream;
|
2008-12-19 00:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-23 17:24:31 +00:00
|
|
|
public void Run()
|
2008-12-19 00:36:04 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
m_thread.Start(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected NetworkStream NetStream
|
|
|
|
|
{
|
|
|
|
|
get
|
2008-12-19 00:36:04 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
return m_netStream;
|
2008-12-19 00:36:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-23 17:24:31 +00:00
|
|
|
protected static void ThreadProc(object obj)
|
2008-12-22 23:03:15 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
NetThread me = (NetThread)obj;
|
|
|
|
|
me.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void Start();
|
|
|
|
|
|
|
|
|
|
public void WaitTermination()
|
|
|
|
|
{
|
|
|
|
|
m_thread.Join();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetTerminateFlag()
|
|
|
|
|
{
|
|
|
|
|
lock (m_terminateFlagMutex)
|
2008-12-22 23:03:15 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
m_terminateFlag = true;
|
2008-12-22 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-23 17:24:31 +00:00
|
|
|
protected bool IsTerminateFlagSet()
|
2008-12-22 23:03:15 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
lock (m_terminateFlagMutex)
|
2008-12-22 23:03:15 +00:00
|
|
|
{
|
2008-12-23 17:24:31 +00:00
|
|
|
return m_terminateFlag;
|
2008-12-22 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-23 17:24:31 +00:00
|
|
|
private Thread m_thread;
|
|
|
|
|
private bool m_terminateFlag;
|
|
|
|
|
private Object m_terminateFlagMutex;
|
|
|
|
|
private NetworkStream m_netStream;
|
2008-12-19 00:36:04 +00:00
|
|
|
}
|
|
|
|
|
}
|