Merge pull request #84 from vibe-d/fix_watchers_ucs2
Fix watchers UCS-2 to UTF-8 conversion merged-on-behalf-of: Leonid Kramer <l-kramer@users.noreply.github.com>
This commit is contained in:
commit
de96942501
|
@ -243,6 +243,8 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
slot.read.wsabuf[0].len = buffer.length;
|
slot.read.wsabuf[0].len = buffer.length;
|
||||||
slot.read.wsabuf[0].buf = () @trusted { return buffer.ptr; } ();
|
slot.read.wsabuf[0].buf = () @trusted { return buffer.ptr; } ();
|
||||||
|
|
||||||
|
void resetBuffers() { slot.read.buffer = null; slot.read.wsabuf[0] = WSABUF.init; }
|
||||||
|
|
||||||
auto ovl = mode == IOMode.immediate ? null : &slot.read.overlapped.overlapped;
|
auto ovl = mode == IOMode.immediate ? null : &slot.read.overlapped.overlapped;
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
auto handler = &overlappedIOHandler!(onIOReadCompleted, DWORD);
|
auto handler = &overlappedIOHandler!(onIOReadCompleted, DWORD);
|
||||||
|
@ -251,10 +253,12 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
auto err = WSAGetLastError();
|
auto err = WSAGetLastError();
|
||||||
if (err == WSA_IO_PENDING) {
|
if (err == WSA_IO_PENDING) {
|
||||||
if (mode == IOMode.immediate) {
|
if (mode == IOMode.immediate) {
|
||||||
|
resetBuffers();
|
||||||
on_read_finish(socket, IOStatus.wouldBlock, 0);
|
on_read_finish(socket, IOStatus.wouldBlock, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
resetBuffers();
|
||||||
on_read_finish(socket, IOStatus.error, 0);
|
on_read_finish(socket, IOStatus.error, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -277,6 +281,8 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
slot.common.core.removeWaiter();
|
slot.common.core.removeWaiter();
|
||||||
auto cb = slot.streamSocket.read.callback;
|
auto cb = slot.streamSocket.read.callback;
|
||||||
slot.streamSocket.read.callback = null;
|
slot.streamSocket.read.callback = null;
|
||||||
|
slot.streamSocket.read.buffer = null;
|
||||||
|
slot.streamSocket.read.wsabuf[0] = WSABUF.init;
|
||||||
if (slot.common.driver.releaseRef(cast(StreamSocketFD)slot.common.fd))
|
if (slot.common.driver.releaseRef(cast(StreamSocketFD)slot.common.fd))
|
||||||
cb(cast(StreamSocketFD)slot.common.fd, status, nsent);
|
cb(cast(StreamSocketFD)slot.common.fd, status, nsent);
|
||||||
}
|
}
|
||||||
|
@ -562,6 +568,8 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
slot.common.core.removeWaiter();
|
slot.common.core.removeWaiter();
|
||||||
auto cb = slot.datagramSocket.read.callback;
|
auto cb = slot.datagramSocket.read.callback;
|
||||||
slot.datagramSocket.read.callback = null;
|
slot.datagramSocket.read.callback = null;
|
||||||
|
slot.datagramSocket.read.buffer = null;
|
||||||
|
slot.datagramSocket.read.wsabuf = WSABUF.init;
|
||||||
scope addr = new RefAddress(cast(sockaddr*)&slot.datagramSocket.sourceAddr, slot.datagramSocket.sourceAddrLen);
|
scope addr = new RefAddress(cast(sockaddr*)&slot.datagramSocket.sourceAddr, slot.datagramSocket.sourceAddrLen);
|
||||||
if (slot.common.driver.releaseRef(cast(DatagramSocketFD)slot.common.fd))
|
if (slot.common.driver.releaseRef(cast(DatagramSocketFD)slot.common.fd))
|
||||||
cb(cast(DatagramSocketFD)slot.common.fd, status, nsent, status == IOStatus.ok ? addr : null);
|
cb(cast(DatagramSocketFD)slot.common.fd, status, nsent, status == IOStatus.ok ? addr : null);
|
||||||
|
@ -919,6 +927,8 @@ static struct StreamDirection(bool RO) {
|
||||||
size_t bytesTransferred;
|
size_t bytesTransferred;
|
||||||
IOMode mode;
|
IOMode mode;
|
||||||
IOCallback callback;
|
IOCallback callback;
|
||||||
|
|
||||||
|
void reset() { buffer = null; wsabuf[0] = WSABUF.init; callback = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct StreamListenSocketSlot {
|
private struct StreamListenSocketSlot {
|
||||||
|
@ -943,4 +953,6 @@ static struct DgramDirection(bool RO) {
|
||||||
size_t bytesTransferred;
|
size_t bytesTransferred;
|
||||||
IOMode mode;
|
IOMode mode;
|
||||||
DatagramIOCallback callback;
|
DatagramIOCallback callback;
|
||||||
|
|
||||||
|
void reset() { buffer = null; wsabuf[0] = WSABUF.init; callback = null; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
|
||||||
private static nothrow
|
private static nothrow
|
||||||
void onIOCompleted(DWORD dwError, DWORD cbTransferred, OVERLAPPED_CORE* overlapped)
|
void onIOCompleted(DWORD dwError, DWORD cbTransferred, OVERLAPPED_CORE* overlapped)
|
||||||
{
|
{
|
||||||
|
import std.algorithm.iteration : map;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.file : isDir;
|
import std.file : isDir;
|
||||||
import std.path : dirName, baseName, buildPath;
|
import std.path : dirName, baseName, buildPath;
|
||||||
|
@ -155,7 +156,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.baseDirectory = slot.directory;
|
ch.baseDirectory = slot.directory;
|
||||||
auto path = () @trusted { scope (failure) assert(false); return to!string(fni.FileName[0 .. fni.FileNameLength/2]); } ();
|
auto path = () @trusted { try return fni.FileName[0 .. fni.FileNameLength/2].map!(ch => dchar(ch)).to!string; catch (Exception e) assert(false, e.msg); } ();
|
||||||
auto fullpath = buildPath(slot.directory, path);
|
auto fullpath = buildPath(slot.directory, path);
|
||||||
ch.directory = dirName(path);
|
ch.directory = dirName(path);
|
||||||
if (ch.directory == ".") ch.directory = "";
|
if (ch.directory == ".") ch.directory = "";
|
||||||
|
|
Loading…
Reference in a new issue