From 515f59dde15e1c9f51908b74bc7f7adda2ab88c6 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 17 Apr 2017 16:10:46 +0300 Subject: [PATCH] fixes for new ncrpc --- mono/injed.d | 20 ++++-- mono/monox.d | 10 +-- mono/sockchan.d | 1 - ncproto.d | 14 ++-- nya.d | 4 +- sockchan.d | 199 -------------------------------------------------------- 6 files changed, 26 insertions(+), 222 deletions(-) delete mode 120000 mono/sockchan.d delete mode 100644 sockchan.d diff --git a/mono/injed.d b/mono/injed.d index 9ab37c0..5afe23a 100644 --- a/mono/injed.d +++ b/mono/injed.d @@ -8,9 +8,9 @@ import std.algorithm; import iv.olly.assembler; import iv.vfs.io; -import iv.ncserial; +import iv.ncrpc; -import sockchan; +//import sockchan; import ncproto; import monox; @@ -26,11 +26,9 @@ void gcCollect () { // ////////////////////////////////////////////////////////////////////////// // -@NCRPCEP { - @NCRPCEPName("listEndpoints") string[] eplist () { - return rpcEndpointNames; - } -} +__gshared string[] delegate () listEndpoints; + +string[] listEndpointsEP () { return rpcEndpointNames; } // ////////////////////////////////////////////////////////////////////////// // @@ -44,9 +42,17 @@ void sendHello () { // ////////////////////////////////////////////////////////////////////////// // void commThread () { + import std.functional : toDelegate; + /* rpcRegisterModuleEndpoints!monox("mono."); //rpcRegisterEndpoint!listEndpoints; rpcRegisterModuleEndpoints!(mixin(__MODULE__)); + */ + rpcRegisterEndpoint!getAssemblyName(toDelegate(&getAssemblyNameEP)); + rpcRegisterEndpoint!enumAssemblies(toDelegate(&enumAssembliesEP)); + rpcRegisterEndpoint!getClassList(toDelegate(&getClassListEP)); + rpcRegisterEndpoint!getClassFields(toDelegate(&getClassFieldsEP)); + rpcRegisterEndpoint!listEndpoints(toDelegate(&listEndpointsEP)); try { writeln("D: communication thread started."); loadWineAPI(); diff --git a/mono/monox.d b/mono/monox.d index d4fd796..7c6f8ba 100644 --- a/mono/monox.d +++ b/mono/monox.d @@ -4,7 +4,7 @@ private: import std.string : fromStringz; import iv.vfs.io; -import iv.ncserial; +//import iv.ncserial; import ncproto; @@ -481,7 +481,7 @@ public @property bool isMonoAPILoaded () nothrow @trusted @nogc { return (attach // ////////////////////////////////////////////////////////////////////////// // -@NCRPCEP public string getAssemblyName (uint asmid) { +public string getAssemblyNameEP (uint asmid) { auto image = mono_assembly_get_image(cast(void*)asmid); if (image is null) return ""; auto imgname = mono_image_get_name(image); @@ -504,7 +504,7 @@ extern(C) void assemblyEnumerator (void* assembly, void* userptr) nothrow { } catch (Exception) {} } -@NCRPCEP public AssemblyInfo[] enumAssemblies () { +public AssemblyInfo[] enumAssembliesEP () { AssemblyInfo[] arr; mono_assembly_foreach(cast(GFunc)&assemblyEnumerator, &arr); return arr; @@ -542,7 +542,7 @@ extern(C) void assemblyEnumeratorForClassList (void* assembly, void* userptr) no } catch (Exception) {} } -@NCRPCEP public NCClassInfo[] getClassList (uint asmid=0) { +public NCClassInfo[] getClassListEP (uint asmid=0) { NCClassInfo[] arr; if (asmid == 0) { mono_assembly_foreach(cast(GFunc)&assemblyEnumeratorForClassList, &arr); @@ -554,7 +554,7 @@ extern(C) void assemblyEnumeratorForClassList (void* assembly, void* userptr) no // ////////////////////////////////////////////////////////////////////////// // -@NCRPCEP public FieldInfo[] getClassFields (uint clsid) { +public FieldInfo[] getClassFieldsEP (uint clsid) { void* c = cast(void*)clsid; auto cname = mono_class_get_name(c); if (cname is null) return null; diff --git a/mono/sockchan.d b/mono/sockchan.d deleted file mode 120000 index 0d1be03..0000000 --- a/mono/sockchan.d +++ /dev/null @@ -1 +0,0 @@ -../sockchan.d \ No newline at end of file diff --git a/ncproto.d b/ncproto.d index f52e94c..b5bb97b 100644 --- a/ncproto.d +++ b/ncproto.d @@ -18,9 +18,9 @@ module ncproto is aliced; import iv.vfs.io; -import iv.ncserial; +import iv.ncrpc; -import sockchan; +//import sockchan; // ////////////////////////////////////////////////////////////////////////// // @@ -81,9 +81,7 @@ public struct FieldInfo { // ////////////////////////////////////////////////////////////////////////// // -@NCRPCEP { - string getAssemblyName (uint asmid); - AssemblyInfo[] enumAssemblies (); - NCClassInfo[] getClassList (uint asmid=0); - FieldInfo[] getClassFields (uint clsid); -} +__gshared string delegate (uint asmid) getAssemblyName; +__gshared AssemblyInfo[] delegate () enumAssemblies; +__gshared NCClassInfo[] delegate (uint asmid=0) getClassList; +__gshared FieldInfo[] delegate (uint clsid) getClassFields; diff --git a/nya.d b/nya.d index a66f737..a79327e 100644 --- a/nya.d +++ b/nya.d @@ -21,11 +21,11 @@ import iv.editline; import iv.strex; import iv.vfs; import iv.vfs.io; -import iv.ncserial; +import iv.ncrpc; import addrstore; import procutil; -import sockchan; +//import sockchan; import ncproto; import ncproto; diff --git a/sockchan.d b/sockchan.d deleted file mode 100644 index 4aa2f15..0000000 --- a/sockchan.d +++ /dev/null @@ -1,199 +0,0 @@ -/* Written by Ketmar // Invisible Vector - * Understanding is not required. Only obedience. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -module sockchan is aliced; - -import iv.vfs; - - -// ////////////////////////////////////////////////////////////////////////// // -struct UDSocket { -private: - static struct UDSData { - uint rc; - int fd; - uint bytesSent; - uint bytesReceived; - bool didlisten; - bool dontclose; - @disable this (this); - } - -private: - usize udsp; - - void decRef () nothrow @nogc { - if (!udsp) return; - auto uds = cast(UDSData*)udsp; - if (--uds.rc == 0) { - import core.stdc.stdlib : free; - import core.sys.posix.unistd : close; - if (!uds.dontclose) close(uds.fd); - free(uds); - } - udsp = 0; - } - -public: - this (this) nothrow @nogc { pragma(inline, true); if (udsp) ++(cast(UDSData*)udsp).rc; } - ~this () nothrow @nogc { pragma(inline, true); if (udsp) close(); } - - void opAssign (UDSocket sk) { - pragma(inline, true); - if (sk.udsp) ++(cast(UDSData*)sk.udsp).rc; - close(); - udsp = sk.udsp; - } - - @property bool isOpen () const nothrow @trusted @nogc { pragma(inline, true); return (udsp != 0); } - @property int fd () const nothrow @trusted @nogc { pragma(inline, true); return (udsp != 0 ? (cast(UDSData*)udsp).fd : -1); } - - void close () nothrow @nogc { pragma(inline, true); if (udsp) decRef(); } - void create (const(char)[] name) { doCC!"server"(name); } - void connect (const(char)[] name) { doCC!"client"(name); } - - @property uint bytesSent () const nothrow @trusted @nogc { pragma(inline, true); return (udsp != 0 ? (cast(UDSData*)udsp).bytesSent : 0); } - @property uint bytesReceived () const nothrow @trusted @nogc { pragma(inline, true); return (udsp != 0 ? (cast(UDSData*)udsp).bytesReceived : 0); } - - @property void resetBytesSent () nothrow @trusted @nogc { pragma(inline, true); if (udsp != 0) (cast(UDSData*)udsp).bytesSent = 0; } - @property void resetBytesReceived () nothrow @trusted @nogc { pragma(inline, true); if (udsp != 0) (cast(UDSData*)udsp).bytesReceived = 0; } - - void listen () { - if (!udsp) throw new Exception("can't listen on closed socket"); - auto uds = cast(UDSData*)udsp; - if (!uds.didlisten) { - import core.sys.posix.sys.socket : listen; - if (listen(uds.fd, 1) != 0) throw new Exception("listen failed"); - uds.didlisten = true; - } - } - - UDSocket accept () { - listen(); - auto uds = cast(UDSData*)udsp; - assert(uds.didlisten); - import core.sys.posix.sys.socket : accept; - int cfd = accept(uds.fd, null, null); - if (cfd == -1) throw new Exception("accept failed"); - UDSocket res; - res.assignFD(cfd); - return res; - } - - // detach fd - int detach () { - if (!udsp) throw new Exception("can't detach closed socket"); - auto uds = cast(UDSData*)udsp; - int rfd = uds.fd; - uds.dontclose = true; - close(); - return rfd; - } - - void[] rawRead (void[] buf) { - import core.sys.posix.sys.socket : recv; - if (!udsp) throw new Exception("can't read from closed socket"); - auto uds = cast(UDSData*)udsp; - if (buf.length == 0) return buf[]; - auto rd = recv(uds.fd, buf.ptr, buf.length, 0); - if (rd < 0) throw new Exception("socket read error"); - uds.bytesReceived += rd; - return buf[0..rd]; - } - - void rawWrite (const(void)[] buf) { - import core.sys.posix.sys.socket : send, MSG_NOSIGNAL; - if (!udsp) throw new Exception("can't write to closed socket"); - auto uds = cast(UDSData*)udsp; - auto dp = cast(const(ubyte)*)buf.ptr; - auto left = buf.length; - while (left > 0) { - auto wr = send(uds.fd, dp, left, 0); - if (wr <= 0) throw new Exception("socket write error"); - uds.bytesSent += wr; - dp += wr; - left -= wr; - } - } - -private: - void assignFD (int fd) { - import core.stdc.stdlib : malloc; - import core.stdc.string : memset; - close(); - if (fd >= 0) { - auto uds = cast(UDSData*)malloc(UDSData.sizeof); - if (uds is null) { - import core.sys.posix.unistd : close; - close(fd); - throw new Exception("out of memory"); // let's hope that we can do it - } - memset(uds, 0, (*uds).sizeof); - uds.rc = 1; - uds.fd = fd; - udsp = cast(usize)uds; - } - } - - void doCC(string mode) (const(char)[] name) { - static assert(mode == "client" || mode == "server", "invalid mode"); - import core.stdc.stdlib : malloc; - import core.stdc.string : memset; - close(); - int fd = makeUADS!mode(name); - auto uds = cast(UDSData*)malloc(UDSData.sizeof); - if (uds is null) { - import core.sys.posix.unistd : close; - close(fd); - throw new Exception("out of memory"); // let's hope that we can do it - } - memset(uds, 0, (*uds).sizeof); - uds.rc = 1; - uds.fd = fd; - udsp = cast(usize)uds; - } - - static int makeUADS(string mode) (const(char)[] name) { - static assert(mode == "client" || mode == "server", "invalid mode"); - import core.stdc.string : memset; - import core.sys.posix.sys.socket; - import core.sys.posix.sys.un : sockaddr_un; - import core.sys.posix.unistd : close; - // max name length is 108, so be safe here - if (name.length == 0 || name.length > 100) throw new Exception("invalid name"); - sockaddr_un sun = void; - memset(&sun, 0, sun.sizeof); - sun.sun_family = AF_UNIX; - // create domain socket without FS inode (first byte of name buffer should be zero) - sun.sun_path[1..1+name.length] = cast(byte[])name[]; - int fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) throw new Exception("can't create unix domain socket"); - static if (mode == "server") { - import core.sys.posix.sys.socket : bind; - if (bind(fd, cast(sockaddr*)&sun, sun.sizeof) != 0) { close(fd); throw new Exception("can't bind unix domain socket"); } - } else { - import core.sys.posix.sys.socket : connect; - if (connect(fd, cast(sockaddr*)&sun, sun.sizeof) != 0) { - import core.stdc.errno; - auto err = errno; - close(fd); - //{ import std.stdio; writeln("ERRNO: ", err); } - throw new Exception("can't connect to unix domain socket"); - } - } - return fd; - } -} -- 2.11.4.GIT