Added basic implementation to gtpsocket, started to sketch out networkthread
This commit is contained in:
parent
da583678c1
commit
4f5227cd82
3 changed files with 134 additions and 8 deletions
33
lib/networkthread.py
Normal file
33
lib/networkthread.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# This class implements a thread that handles the networking connection.
|
||||
# It expects a copy of the board and an open socket to the remote host, which
|
||||
# it will bind to a GTPSocket.
|
||||
# This is the only thread that should be calling get(), but send() could be called
|
||||
# twice, so we wrap it in a mutex.
|
||||
# The board is also wrapped in a mutex, even though only this thread should modify it
|
||||
# if it exists.
|
||||
|
||||
import threading
|
||||
|
||||
|
||||
class NetworkThread(threading.Thread):
|
||||
dispatcher = {
|
||||
'quit': None,
|
||||
'boardsize': None,
|
||||
'clear_board': None,
|
||||
'komi': None,
|
||||
'play': None,
|
||||
'genmove': None
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, goban, socket):
|
||||
self.goban = goban
|
||||
self.goban_lock = threading.Lock()
|
||||
self.socket = GTPSocket(socket)
|
||||
self.send_lock = threading.Lock()
|
||||
|
||||
GTPSocket.known_cmds.extend(dispatcher.keys())
|
||||
|
||||
|
||||
def run(self):
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue