Fix up examples
This commit is contained in:
@@ -61,6 +61,7 @@ void check_py_error() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: need to decref error_func as well on successful run
|
||||||
PyObject * wrapPyFunc(PyObject * func, PyObject * arg) {
|
PyObject * wrapPyFunc(PyObject * func, PyObject * arg) {
|
||||||
PyObject * result = PyObject_CallFunctionObjArgs(func, arg, NULL);
|
PyObject * result = PyObject_CallFunctionObjArgs(func, arg, NULL);
|
||||||
Py_DECREF(func);
|
Py_DECREF(func);
|
||||||
|
|||||||
@@ -1581,6 +1581,10 @@ cdef class RpcServer:
|
|||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
del self.thisptr
|
del self.thisptr
|
||||||
|
|
||||||
|
def run_forever(self):
|
||||||
|
p = PromiseFulfillerPair()
|
||||||
|
self.loop.wait(p)
|
||||||
|
|
||||||
# TODO: add restore functionality here?
|
# TODO: add restore functionality here?
|
||||||
|
|
||||||
cdef class FdAsyncIoStream:
|
cdef class FdAsyncIoStream:
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class Server:
|
|||||||
def __init__(self, val=1):
|
def __init__(self, val=1):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
def foo(self, context):
|
def foo(self, i, **kwargs):
|
||||||
context.results.x = str(context.params.i * 5 + self.val)
|
return str(i * 5 + self.val)
|
||||||
|
|
||||||
def example_simple_rpc():
|
def example_simple_rpc():
|
||||||
def _restore(ref_id):
|
def _restore(ref_id):
|
||||||
@@ -17,10 +17,9 @@ def example_simple_rpc():
|
|||||||
|
|
||||||
loop = capnp.EventLoop()
|
loop = capnp.EventLoop()
|
||||||
|
|
||||||
import os
|
read, write = socket.socketpair(socket.AF_UNIX)
|
||||||
read, write = os.pipe()
|
read_stream = capnp.FdAsyncIoStream(read.fileno())
|
||||||
read_stream = capnp.FdAsyncIoStream(write)
|
write_stream = capnp.FdAsyncIoStream(write.fileno())
|
||||||
write_stream = capnp.FdAsyncIoStream(read)
|
|
||||||
|
|
||||||
restorer = capnp.Restorer(capability.TestSturdyRefObjectId, _restore)
|
restorer = capnp.Restorer(capability.TestSturdyRefObjectId, _restore)
|
||||||
server = capnp.RpcServer(loop, write_stream, restorer)
|
server = capnp.RpcServer(loop, write_stream, restorer)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class Server:
|
|||||||
def __init__(self, val=1):
|
def __init__(self, val=1):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
def foo(self, context):
|
def foo(self, i, **kwargs):
|
||||||
context.results.x = str(context.params.i * 5 + self.val)
|
return str(i * 5 + self.val)
|
||||||
|
|
||||||
def restore(ref_id):
|
def restore(ref_id):
|
||||||
return test_capnp.TestInterface.new_server(Server(100))
|
return test_capnp.TestInterface.new_server(Server(100))
|
||||||
@@ -29,8 +29,7 @@ def example_server(host='localhost', port=49999):
|
|||||||
restorer = capnp.Restorer(test_capnp.TestSturdyRefObjectId, restore)
|
restorer = capnp.Restorer(test_capnp.TestSturdyRefObjectId, restore)
|
||||||
server = capnp.RpcServer(loop, stream, restorer)
|
server = capnp.RpcServer(loop, stream, restorer)
|
||||||
|
|
||||||
waiter = capnp.PromiseFulfillerPair()
|
server.run_forever()
|
||||||
loop.wait(waiter)
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user