Commit 1b4bee0e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3a755a42
......@@ -39,7 +39,7 @@ cdef extern from *:
from libc.stdint cimport int64_t, uint64_t
from ZODB.utils import p64
from ZODB.utils import p64, u64
# XXX -> pygolang
cdef extern from "wcfs_misc.h" namespace "io" nogil:
......@@ -90,6 +90,7 @@ cdef extern from "wcfs.h" nogil:
string mountpoint
pair[WatchLink, error] _openwatch() # XXX pair instead of tuple
pair[Conn, error] connect(Tid at)
cppclass _Conn:
# XXX
......@@ -109,7 +110,27 @@ cdef class PyWCFS:
def __set__(PyWCFS pywc, string v):
pywc.wc.mountpoint = v
# XXX connect
def connect(PyWCFS pywc, pyat): # -> PyConn
cdef Tid at = u64(pyat)
with nogil:
_ = pywc.wc.connect(at)
wconn = _.first
err = _.second
if err != nil:
raise pyerr(err)
cdef PyConn pywconn = PyConn.__new__(PyConn)
pywconn.wconn = wconn
return pywconn
cdef class PyConn:
cdef Conn wconn
def __dealloc__(PyConn pywconn):
pywconn.wconn = nil
cdef class PyWatchLink:
cdef WatchLink wlink
......@@ -121,7 +142,7 @@ cdef class PyWatchLink:
err = _.second
if err != nil:
raise RuntimeError(err.Error()) # XXX exc class?
raise pyerr(err)
def __dealloc__(PyWatchLink pywlink):
pywlink.wlink = nil
......@@ -131,13 +152,13 @@ cdef class PyWatchLink:
with nogil:
err = wlink_close_pyexc(pywlink.wlink)
if err != nil:
raise RuntimeError(err.Error()) # XXX exc class?
raise pyerr(err)
def closeWrite(PyWatchLink pywlink):
with nogil:
err = wlink_closeWrite_pyexc(pywlink.wlink)
if err != nil:
raise RuntimeError(err.Error()) # XXX exc class?
raise pyerr(err)
def sendReq(PyWatchLink pywlink, context.PyContext pyctx, string req): # -> reply(string)
......@@ -147,13 +168,7 @@ cdef class PyWatchLink:
err = _.second
if err != nil:
# XXX -> common place? support for other errors? is it good idea?
if err.eq(context.canceled):
raise pycontext.canceled
if err.eq(context.deadlineExceeded):
raise pycontext.deadlineExceeded
raise RuntimeError(err.Error()) # XXX -> Xpy(err) ? pyraiseIf(err) ?
raise pyerr(err)
return reply
......@@ -164,15 +179,8 @@ cdef class PyWatchLink:
if err.eq(EOF):
return None
if err != nil:
# XXX -> common place? support for other errors? is it good idea?
if err.eq(context.canceled):
raise pycontext.canceled
if err.eq(context.deadlineExceeded):
raise pycontext.deadlineExceeded
raise RuntimeError(err.Error()) # XXX exc class?
raise pyerr(err)
return pyreq
......@@ -181,13 +189,7 @@ cdef class PyWatchLink:
err = wlink_replyReq_pyexc(pywlink.wlink, pyctx.ctx, &pyreq.pinreq, reply)
if err != nil:
# XXX -> common place? support for other errors? is it good idea?
if err.eq(context.canceled):
raise pycontext.canceled
if err.eq(context.deadlineExceeded):
raise pycontext.deadlineExceeded
raise RuntimeError(err.Error()) # XXX -> Xpy(err) ? pyraiseIf(err) ?
raise pyerr(err)
return
......@@ -230,10 +232,24 @@ def _tpywlinkwrite(PyWatchLink pywlink, bytes pypkt):
with nogil:
err = _twlinkwrite_pyexc(pywlink.wlink, pkt)
if err != nil:
raise RuntimeError(err.Error()) # XXX exc class?
raise pyerr(err)
# ---- misc ----
# pyerr converts error into python error.
cdef object pyerr(error err):
if err == nil:
return None
# XXX support for other errors? is it good idea?
if err.eq(context.canceled):
return pycontext.canceled
if err.eq(context.deadlineExceeded):
return pycontext.deadlineExceeded
return RuntimeError(err.Error()) # XXX exc class ok?
from golang cimport topyexc
cdef nogil:
......
......@@ -51,7 +51,7 @@ typedef refptr<class _WatchLink> WatchLink;
struct WCFS {
string mountpoint;
tuple<Conn, error> connect(zodb::Tid at);
pair<Conn, error> connect(zodb::Tid at);
string _path(const string &obj);
tuple<os::File, error> _open(const string &path, int flags=O_RDONLY);
pair<WatchLink, error> _openwatch();
......@@ -85,7 +85,7 @@ struct _Conn : object {
private:
_Conn();
~_Conn();
friend tuple<Conn, error> WCFS::connect(zodb::Tid at);
friend pair<Conn, error> WCFS::connect(zodb::Tid at);
public:
void decref();
......
......@@ -88,7 +88,7 @@ struct _Mapping {
// connect creates new Conn viewing WCFS state as of @at.
tuple<Conn, error> WCFS::connect(zodb::Tid at) {
pair<Conn, error> WCFS::connect(zodb::Tid at) {
WCFS *wc = this;
// XXX err ctx
......@@ -98,7 +98,7 @@ tuple<Conn, error> WCFS::connect(zodb::Tid at) {
error err;
tie(wlink, err) = wc->_openwatch();
if (err != nil)
return make_tuple(nil, err);
return make_pair(nil, err);
Conn wconn = adoptref(new _Conn());
wconn->_wc = wc;
......@@ -113,7 +113,7 @@ tuple<Conn, error> WCFS::connect(zodb::Tid at) {
return wconn->_pinner(ctx);
});
return make_tuple(wconn, nil);
return make_pair(wconn, nil);
}
// close releases resources associated with wconn.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment