diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index 29c306a..2473674 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -13,6 +13,7 @@ import std.format : format; import std.functional : toDelegate; import std.socket : AddressFamily, UnknownAddress; import vibe.core.log; +import vibe.core.stream; import vibe.internal.async; import core.time : Duration; @@ -441,9 +442,10 @@ mixin(tracer); mixin(tracer); } void finalize() {} - void write(InputStream)(InputStream stream, ulong nbytes = 0) { writeDefault(stream, nbytes); } + void write(InputStream)(InputStream stream, ulong nbytes = 0) if (isInputStream!InputStream) { writeDefault(stream, nbytes); } private void writeDefault(InputStream)(InputStream stream, ulong nbytes = 0) + if (isInputStream!InputStream) { import std.algorithm.comparison : min; diff --git a/source/vibe/core/stream.d b/source/vibe/core/stream.d new file mode 100644 index 0000000..86fc122 --- /dev/null +++ b/source/vibe/core/stream.d @@ -0,0 +1,16 @@ +module vibe.core.stream; + +enum isInputStream(T) = __traits(compiles, { + T s; + ubyte[] buf; + if (!s.empty) + s.read(buf); + if (s.leastSize > 0) + s.read(buf); +}); + +enum isOutputStream(T) = __traits(compiles, { + T s; + const(ubyte)[] buf; + s.write(buf); +});