diff options
author | pzread <netfirewall@gmail.com> | 2013-06-03 21:40:37 +0800 |
---|---|---|
committer | pzread <netfirewall@gmail.com> | 2013-06-03 21:40:37 +0800 |
commit | 9fa7badc787ec364d58f65b95355c8725ad75a9c (patch) | |
tree | 45c37afd8ec06e093c5fb257259110fe86fd770c /src/py/imc/proxy.py | |
parent | 13445dbeb426347354b61bd46f738f37b25ffd60 (diff) | |
download | taiwan-online-judge-9fa7badc787ec364d58f65b95355c8725ad75a9c.tar.gz taiwan-online-judge-9fa7badc787ec364d58f65b95355c8725ad75a9c.tar.zst taiwan-online-judge-9fa7badc787ec364d58f65b95355c8725ad75a9c.zip |
IMC framework 1.0 Alpha 1
Diffstat (limited to 'src/py/imc/proxy.py')
-rwxr-xr-x | src/py/imc/proxy.py | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/py/imc/proxy.py b/src/py/imc/proxy.py index 9f96a73..8f37b62 100755 --- a/src/py/imc/proxy.py +++ b/src/py/imc/proxy.py @@ -22,9 +22,24 @@ class Connection: def send_msg(self,data): pass + def send_file(self,filekey,filepath,callback): + pass + + def recv_file(self,filekey,filesize,filepath,callback): + pass + + def send_filedata(self,filekey,filesize,callback): + pass + + def recv_filedata(self,filekey,filesize,send_fn): + pass + def start_recv(self,recv_callback): pass + def abort_file(self,filekey): + pass + def add_close_callback(self,callback): self._close_callback.append(tornado.stack_context.wrap(callback)) @@ -153,9 +168,8 @@ class Proxy: 'timer':self._ioloop.add_timeout(datetime.timedelta(days = 1),lambda : self._ret_sendfile('Etimeout')) } - stat,ret = self.call(1000000,self._idendesc,dst_link + 'imc/','pend_recvfile',{'filekey':filekey,'filesize':filesize}) + stat,ret = self.call(65536,self._idendesc,dst_link + 'imc/','pend_recvfile',{'filekey':filekey,'filesize':filesize}) if stat == False: - print('err close ' + ret) raise ConnectionError(ret) return fileresult @@ -200,7 +214,7 @@ class Proxy: return dst_link = ''.join(['/',info['src_linkclass'],'/',info['src_linkid'],'/']) - self.call(1000000,self._idendesc,dst_link + 'imc/','reject_sendfile',{'filekey':filekey}) + self.call(65536,self._idendesc,dst_link + 'imc/','reject_sendfile',{'filekey':filekey}) def _route_call(self,in_conn,caller_retid,timeout,idendesc,dst,func_name,param): def __add_wait_caller(conn_linkid): @@ -249,7 +263,7 @@ class Proxy: self._auth.change_iden(old_iden) except KeyError: - result = (False,'Enoexist1') + result = (False,'Enoexist') __del_wait_caller(self._linkid) @@ -258,7 +272,7 @@ class Proxy: else: conn = self._request_conn(dst_linkid) if conn == None: - return __ret((False,'Enoexist2')) + return __ret((False,'Enoexist')) else: if caller_linkid == self._linkid: @@ -351,9 +365,10 @@ class Proxy: self._send_msg_sendfile(in_conn,src_linkid,filekey,filesize) def _add_wait_filekey(self,conn_linkid,filekey,filesize,callback): + callback = tornado.stack_context.wrap(callback) self._conn_filekeymap[conn_linkid][filekey] = { 'timer':self._ioloop.add_timeout(datetime.timedelta(milliseconds = filesize),lambda : callback('Etimeout')), - 'callback':tornado.stack_context.wrap(callback) + 'callback':callback } def _del_wait_filekey(self,conn_linkid,filekey): @@ -393,7 +408,12 @@ class Proxy: print('connection close') def _recv_dispatch(self,conn,data): - msg = json.loads(data.decode('utf-8')) + try: + msg = json.loads(data.decode('utf-8')) + + except: + return + msg_type = msg['type'] if msg_type == self.MSGTYPE_CALL: @@ -517,7 +537,7 @@ class Proxy: self._ioloop.add_callback(self._ret_sendfile,filekey,'Ereject') def imc_call(idendesc,dst,func_name,param): - return Proxy.instance.call(1000000,idendesc,dst,func_name,param) + return Proxy.instance.call(65536,idendesc,dst,func_name,param) def imc_call_async(idendesc,dst,func_name,param,callback = None): @async.caller |