tested unix socket stuff, workaround phobos bug

This commit is contained in:
Adam D. Ruppe 2020-01-28 22:35:54 -05:00
parent 216b1bdcfb
commit fcc8aed896
4 changed files with 68 additions and 41 deletions

7
cgi.d
View File

@ -1590,7 +1590,11 @@ class Cgi {
sendAll(ir.source, d); sendAll(ir.source, d);
} }
this(ir, ir.source.remoteAddress().toString(), 80 /* FIXME */, 0, false, &rdo, null, closeConnection); auto ira = ir.source.remoteAddress();
// that check for UnixAddress is to work around a Phobos bug
// see: https://github.com/dlang/phobos/pull/7383
this(ir, cast(UnixAddress) ira ? "unix:" : ira.toString(), 80 /* FIXME */, 0, false, &rdo, null, closeConnection);
} }
/** /**
@ -4219,6 +4223,7 @@ class ListeningConnectionManager {
version(linux) { version(linux) {
listener = new Socket(AddressFamily.UNIX, SocketType.STREAM); listener = new Socket(AddressFamily.UNIX, SocketType.STREAM);
string filename = "\0" ~ host["abstract:".length .. $]; string filename = "\0" ~ host["abstract:".length .. $];
import std.stdio; stderr.writeln("Listening to abstract unix domain socket: ", host["abstract:".length .. $]);
listener.bind(new UnixAddress(filename)); listener.bind(new UnixAddress(filename));
tcp = false; tcp = false;
} else { } else {

22
http2.d
View File

@ -36,6 +36,11 @@ version(arsd_http_winhttp_implementation) {
pragma(lib, "winhttp") pragma(lib, "winhttp")
import core.sys.windows.winhttp; import core.sys.windows.winhttp;
// FIXME: alter the dub package file too // FIXME: alter the dub package file too
// https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpreaddata
// https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpsendrequest
// https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpopenrequest
// https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpconnect
} }
@ -357,15 +362,19 @@ struct Uri {
} }
private string unixSocketPath = null; private string unixSocketPath = null;
/// Indicates it should be accessed through a unix socket instead of regular tcp /// Indicates it should be accessed through a unix socket instead of regular tcp. Returns new version without modifying this object.
void viaUnixSocket(string path) { Uri viaUnixSocket(string path) const {
unixSocketPath = path; Uri copy = this;
copy.unixSocketPath = path;
return copy;
} }
/// Goes through a unix socket in the abstract namespace (linux only) /// Goes through a unix socket in the abstract namespace (linux only). Returns new version without modifying this object.
version(linux) version(linux)
void viaAbstractSocket(string path) { Uri viaAbstractSocket(string path) const {
unixSocketPath = "\0" ~ path; Uri copy = this;
copy.unixSocketPath = "\0" ~ path;
return copy;
} }
private void reparse(string uri) { private void reparse(string uri) {
@ -860,6 +869,7 @@ class HttpRequest {
socket = new Socket(family(unixSocketPath), SocketType.STREAM); socket = new Socket(family(unixSocketPath), SocketType.STREAM);
if(unixSocketPath) { if(unixSocketPath) {
import std.stdio; writeln(cast(ubyte[]) unixSocketPath);
socket.connect(new UnixAddress(unixSocketPath)); socket.connect(new UnixAddress(unixSocketPath));
} else { } else {
// FIXME: i should prolly do ipv6 if available too. // FIXME: i should prolly do ipv6 if available too.

View File

@ -1977,7 +1977,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
XChangeProperty( XChangeProperty(
display, display,
impl.window, impl.window,
GetAtom!"_NET_WM_ICON"(display), GetAtom!("_NET_WM_ICON", true)(display),
GetAtom!"CARDINAL"(display), GetAtom!"CARDINAL"(display),
32 /* bits */, 32 /* bits */,
0 /*PropModeReplace*/, 0 /*PropModeReplace*/,
@ -9367,7 +9367,15 @@ version(X11) {
if(!xshmQueryCompleted) { if(!xshmQueryCompleted) {
int i1, i2, i3; int i1, i2, i3;
xshmQueryCompleted = true; xshmQueryCompleted = true;
_xshmAvailable = XQueryExtension(XDisplayConnection.get(), "MIT-SHM", &i1, &i2, &i3) != 0;
auto str = XDisplayConnection.get().display_name;
// only if we are actually on the same machine does this
// have any hope, and the query extension only asks if
// the server can in theory, not in practice.
if(str is null || str[0] != ':')
_xshmAvailable = false;
else
_xshmAvailable = XQueryExtension(XDisplayConnection.get(), "MIT-SHM", &i1, &i2, &i3) != 0;
} }
return _xshmAvailable; return _xshmAvailable;
} }
@ -14294,51 +14302,55 @@ void demandAttention(Window window, bool needs = true) {
/// X-specific /// X-specific
TrueColorImage getWindowNetWmIcon(Window window) { TrueColorImage getWindowNetWmIcon(Window window) {
auto display = XDisplayConnection.get; try {
auto display = XDisplayConnection.get;
auto data = getX11PropertyData (window, GetAtom!"_NET_WM_ICON"(display), XA_CARDINAL); auto data = getX11PropertyData (window, GetAtom!"_NET_WM_ICON"(display), XA_CARDINAL);
if (data.length > arch_ulong.sizeof * 2) { if (data.length > arch_ulong.sizeof * 2) {
auto meta = cast(arch_ulong[]) (data[0 .. arch_ulong.sizeof * 2]); auto meta = cast(arch_ulong[]) (data[0 .. arch_ulong.sizeof * 2]);
// these are an array of rgba images that we have to convert into pixmaps ourself // these are an array of rgba images that we have to convert into pixmaps ourself
int width = cast(int) meta[0]; int width = cast(int) meta[0];
int height = cast(int) meta[1]; int height = cast(int) meta[1];
auto bytes = cast(ubyte[]) (data[arch_ulong.sizeof * 2 .. $]); auto bytes = cast(ubyte[]) (data[arch_ulong.sizeof * 2 .. $]);
static if(arch_ulong.sizeof == 4) { static if(arch_ulong.sizeof == 4) {
bytes = bytes[0 .. width * height * 4]; bytes = bytes[0 .. width * height * 4];
alias imageData = bytes; alias imageData = bytes;
} else static if(arch_ulong.sizeof == 8) { } else static if(arch_ulong.sizeof == 8) {
bytes = bytes[0 .. width * height * 8]; bytes = bytes[0 .. width * height * 8];
auto imageData = new ubyte[](4 * width * height); auto imageData = new ubyte[](4 * width * height);
} else static assert(0); } else static assert(0);
// this returns ARGB. Remember it is little-endian so // this returns ARGB. Remember it is little-endian so
// we have BGRA // we have BGRA
// our thing uses RGBA, which in little endian, is ABGR // our thing uses RGBA, which in little endian, is ABGR
for(int idx = 0, idx2 = 0; idx < bytes.length; idx += arch_ulong.sizeof, idx2 += 4) { for(int idx = 0, idx2 = 0; idx < bytes.length; idx += arch_ulong.sizeof, idx2 += 4) {
auto r = bytes[idx + 2]; auto r = bytes[idx + 2];
auto g = bytes[idx + 1]; auto g = bytes[idx + 1];
auto b = bytes[idx + 0]; auto b = bytes[idx + 0];
auto a = bytes[idx + 3]; auto a = bytes[idx + 3];
imageData[idx2 + 0] = r; imageData[idx2 + 0] = r;
imageData[idx2 + 1] = g; imageData[idx2 + 1] = g;
imageData[idx2 + 2] = b; imageData[idx2 + 2] = b;
imageData[idx2 + 3] = a; imageData[idx2 + 3] = a;
}
return new TrueColorImage(width, height, imageData);
} }
return new TrueColorImage(width, height, imageData); return null;
} catch(Exception e) {
return null;
} }
return null;
} }
} } /* UsingSimpledisplayX11 */
void loadBinNameToWindowClassName () { void loadBinNameToWindowClassName () {

View File

@ -63,7 +63,7 @@
module arsd.terminal; module arsd.terminal;
// FIXME: needs to support VT output on Windows too in certain situations // FIXME: needs to support VT output on Windows too in certain situations
// FIXME: paste on Windows and alt+NNNN codes in getline function // detect VT on windows by trying to set the flag. if this succeeds, ask it for caps. if this replies with my code we good to do extended output.
/++ /++
$(H3 Get Line) $(H3 Get Line)