Remove TMSP Commit/Rollback; Add CheckTx

This commit is contained in:
Jae Kwon
2016-01-08 16:52:02 -08:00
parent aa3e87450a
commit f15476b157
17 changed files with 227 additions and 376 deletions

View File

@ -2,7 +2,6 @@ import socket
import select
import sys
from wire import decode_varint, encode
from reader import BytesBuffer
from msg import RequestDecoder, message_types
@ -10,12 +9,11 @@ from msg import RequestDecoder, message_types
# hold the asyncronous state of a connection
# ie. we may not get enough bytes on one read to decode the message
class Connection():
def __init__(self, fd, appCtx):
def __init__(self, fd, app):
self.fd = fd
self.appCtx = appCtx
self.app = app
self.recBuf = BytesBuffer(bytearray())
self.resBuf = BytesBuffer(bytearray())
self.msgLength = 0
@ -30,12 +28,11 @@ class Connection():
# TMSP server responds to messges by calling methods on the app
class TMSPServer():
def __init__(self, app, port=5410):
self.app = app
# map conn file descriptors to (appContext, reqBuf, resBuf, msgDecoder)
# map conn file descriptors to (app, reqBuf, resBuf, msgDecoder)
self.appMap = {}
self.port = port
@ -60,8 +57,7 @@ class TMSPServer():
self.write_list.append(new_fd)
print 'new connection to', new_addr
appContext = self.app.open()
self.appMap[new_fd] = Connection(new_fd, appContext)
self.appMap[new_fd] = Connection(new_fd, self.app)
def handle_conn_closed(self, r):
self.read_list.remove(r)
@ -70,7 +66,7 @@ class TMSPServer():
print "connection closed"
def handle_recv(self, r):
# appCtx, recBuf, resBuf, conn
# app, recBuf, resBuf, conn
conn = self.appMap[r]
while True:
try:
@ -127,7 +123,7 @@ class TMSPServer():
conn.msgLength = 0
conn.inProgress = False
req_f = getattr(conn.appCtx, req_type)
req_f = getattr(conn.app, req_type)
if req_args is None:
res = req_f()
elif isinstance(req_args, tuple):