def async_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) fu_id = _pyrpc.client_async_call(self.id, rpc_id, req_m.id) if fu_id is None: raise Exception("ENOTCONN: %s" % os.strerror(errno.ENOTCONN)) return Future(id=fu_id, rep_types=rep_types)
def __call__(self, input_marshal_id): input_m = Marshal(id=input_marshal_id, should_release=False) input_values = [] for input_ty in self.input_types: input_values += input_m.read_obj(input_ty), try: output = self.f(*input_values) except: traceback.print_exc() raise if len(self.output_types) == 0: # void rpc return 0 # mark as a NULL reply output_m = Marshal( should_release=False) # C++ code will release the marshal object if len(self.output_types) == 1: # single return value output_m.write_obj(output, self.output_types[0]) else: # multiple return values for i in range(len(self.output_types)): output_m.write_obj(output[i], self.output_types[i]) return output_m.id
def sync_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) error_code, rep_marshal_id = _pyrpc.client_sync_call(self.id, rpc_id, req_m.id) results = [] if rep_marshal_id != 0 and error_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in rep_types: results += rep_m.read_obj(ty), return error_code, results
def __call__(self, input_marshal_id): input_m = Marshal(id=input_marshal_id, should_release=False) input_values = [] for input_ty in self.input_types: input_values += input_m.read_obj(input_ty), try: output = self.f(*input_values) except: traceback.print_exc() raise if len(self.output_types) == 0: # void rpc return 0 # mark as a NULL reply output_m = Marshal(should_release=False) # C++ code will release the marshal object if len(self.output_types) == 1: # single return value output_m.write_obj(output, self.output_types[0]) else: # multiple return values for i in range(len(self.output_types)): output_m.write_obj(output[i], self.output_types[i]) return output_m.id
def wait(self, timeout_sec=None): if self.wait_ok: return if timeout_sec is None: self.err_code, rep_marshal_id = _pyrpc.future_wait(self.id) else: timeout_msec = int(timeout_sec * 1000) self.err_code, rep_marshal_id = _pyrpc.future_timedwait(self.id, timeout_msec) results = [] if rep_marshal_id != 0 and self.err_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in self.rep_types: results += rep_m.read_obj(ty), self.wait_ok = True if len(results) == 0: self.rep = None elif len(results) == 1: self.rep = results[0] else: self.rep = results return self.err_code
def wait(self, timeout_sec=None): if self.wait_ok: return if timeout_sec is None: self.err_code, rep_marshal_id = _pyrpc.future_wait(self.id) else: timeout_msec = int(timeout_sec * 1000) self.err_code, rep_marshal_id = _pyrpc.future_timedwait( self.id, timeout_msec) results = [] if rep_marshal_id != 0 and self.err_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in self.rep_types: results += rep_m.read_obj(ty), self.wait_ok = True if len(results) == 0: self.rep = None elif len(results) == 1: self.rep = results[0] else: self.rep = results return self.err_code
def sync_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) error_code, rep_marshal_id = _pyrpc.client_sync_call( self.id, rpc_id, req_m.id) results = [] if rep_marshal_id != 0 and error_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in rep_types: results += rep_m.read_obj(ty), return error_code, results
import os from simplerpc.marshal import Marshal from simplerpc.future import Future point3 = Marshal.reg_type('point3', [('x', 'double'), ('y', 'double'), ('z', 'double')]) class BenchmarkService(object): FAST_PRIME = 0x5b9365eb FAST_DOT_PROD = 0x4a92c615 FAST_ADD = 0x484806bf FAST_NOP = 0x4f29b7a5 PRIME = 0x1f96b90f DOT_PROD = 0x3a2fd47a ADD = 0x5135fabc NOP = 0x3823ed06 SLEEP = 0x39d768e9 ADD_LATER = 0x64e0a594 LOSSY_NOP = 0x5323ea07 FAST_LOSSY_NOP = 0x6223e760 __input_type_info__ = { 'fast_prime': ['rpc::i32'], 'fast_dot_prod': ['point3', 'point3'], 'fast_add': ['rpc::v32', 'rpc::v32'], 'fast_nop': ['std::string'], 'prime': ['rpc::i32'], 'dot_prod': ['point3', 'point3'], 'add': ['rpc::v32', 'rpc::v32'], 'nop': ['std::string'],
import os from simplerpc.marshal import Marshal from simplerpc.future import Future empty_struct = Marshal.reg_type('empty_struct', []) Person = Marshal.reg_type('Person', [('id', 'rpc::i32'), ('name', 'std::string'), ('email', 'std::string')]) complex_struct = Marshal.reg_type('complex_struct', [( 'd', 'std::map<std::pair<std::string, std::string>, std::vector<std::vector<std::pair<std::string, std::string>>>>' ), ('s', 'std::set<std::string>'), ('e', 'empty_struct')]) class EmptyService(object): __input_type_info__ = {} __output_type_info__ = {} def __bind_helper__(self, func): def f(*args): return getattr(self, func.__name__)(*args) return f def __reg_to__(self, server): pass
import os from simplerpc.marshal import Marshal from simplerpc.future import Future empty_struct = Marshal.reg_type('empty_struct', []) Person = Marshal.reg_type('Person', [('id', 'rpc::i32'), ('name', 'std::string'), ('email', 'std::string')]) complex_struct = Marshal.reg_type('complex_struct', [('d', 'std::map<std::pair<std::string, std::string>, std::vector<std::vector<std::pair<std::string, std::string>>>>'), ('s', 'std::set<std::string>'), ('e', 'empty_struct')]) class EmptyService(object): __input_type_info__ = { } __output_type_info__ = { } def __bind_helper__(self, func): def f(*args): return getattr(self, func.__name__)(*args) return f def __reg_to__(self, server): pass class EmptyProxy(object): def __init__(self, clnt): self.__clnt__ = clnt class MathService(object):
def udp_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) return _pyrpc.client_udp_call(self.id, rpc_id, req_m.id)
import os from simplerpc.marshal import Marshal from simplerpc.future import Future empty_struct = Marshal.reg_type('empty_struct', []) complex_struct = Marshal.reg_type('complex_struct', [('d', 'std::map<std::pair<std::string, std::string>, std::vector<std::vector<std::pair<std::string, std::string>>>>'), ('s', 'std::set<std::string>'), ('e', 'empty_struct')]) class EmptyService(object): __input_type_info__ = { } __output_type_info__ = { } def __bind_helper__(self, func): def f(*args): return getattr(self, func.__name__)(*args) return f def __reg_to__(self, server): pass class EmptyProxy(object): def __init__(self, clnt): self.__clnt__ = clnt class MathService(object): GCD = 0x67d710ba
import os from simplerpc.marshal import Marshal from simplerpc.future import Future point3 = Marshal.reg_type('point3', [('x', 'double'), ('y', 'double'), ('z', 'double')]) class BenchmarkService(object): FAST_PRIME = 0x5b9365eb FAST_DOT_PROD = 0x4a92c615 FAST_ADD = 0x484806bf FAST_NOP = 0x4f29b7a5 PRIME = 0x1f96b90f DOT_PROD = 0x3a2fd47a ADD = 0x5135fabc NOP = 0x3823ed06 SLEEP = 0x39d768e9 ADD_LATER = 0x64e0a594 LOSSY_NOP = 0x5323ea07 FAST_LOSSY_NOP = 0x6223e760 __input_type_info__ = { 'fast_prime': ['rpc::i32'], 'fast_dot_prod': ['point3','point3'], 'fast_add': ['rpc::v32','rpc::v32'], 'fast_nop': ['std::string'], 'prime': ['rpc::i32'], 'dot_prod': ['point3','point3'], 'add': ['rpc::v32','rpc::v32'], 'nop': ['std::string'], 'sleep': ['double'], 'add_later': ['rpc::i32','rpc::i32'],