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

.

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