From 8973bdb2affd36aed172ffb4a0211207cfbdc868 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 13 Jan 2017 10:20:11 +0100 Subject: [PATCH] Fix if EPOLLIN and EPOLLOUT come together --- source/tanya/async/event/epoll.d | 6 ++++-- source/tanya/async/loop.d | 4 ++-- source/tanya/async/protocol.d | 4 ++-- source/tanya/container/vector.d | 22 +++++++++++++++++++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/source/tanya/async/event/epoll.d b/source/tanya/async/event/epoll.d index 236e3fa..408a601 100644 --- a/source/tanya/async/event/epoll.d +++ b/source/tanya/async/event/epoll.d @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Copyright: Eugene Wissner 2016. + * Copyright: Eugene Wissner 2016-2017. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) @@ -132,6 +132,7 @@ class EpollLoop : SelectorLoop else if (events[i].events & EPOLLERR) { kill(io, null); + continue; } else if (events[i].events & (EPOLLIN | EPOLLPRI | EPOLLHUP)) { @@ -156,13 +157,14 @@ class EpollLoop : SelectorLoop if (transport.socket.disconnected) { kill(io, exception); + continue; } else if (io.output.length) { pendings.enqueue(io); } } - else if (events[i].events & EPOLLOUT) + if (events[i].events & EPOLLOUT) { auto transport = cast(SelectorStreamTransport) io.transport; assert(transport !is null); diff --git a/source/tanya/async/loop.d b/source/tanya/async/loop.d index 14cceec..13f86ca 100644 --- a/source/tanya/async/loop.d +++ b/source/tanya/async/loop.d @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Copyright: Eugene Wissner 2016. + * Copyright: Eugene Wissner 2016-2017. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) @@ -17,7 +17,7 @@ * { * private DuplexTransport transport; * - * void received(ubyte[] data) @nogc + * void received(in ubyte[] data) @nogc * { * transport.write(data); * } diff --git a/source/tanya/async/protocol.d b/source/tanya/async/protocol.d index 3b62db6..28e90e0 100644 --- a/source/tanya/async/protocol.d +++ b/source/tanya/async/protocol.d @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Copyright: Eugene Wissner 2016. + * Copyright: Eugene Wissner 2016-2017. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) @@ -22,7 +22,7 @@ interface Protocol * Params: * data = Read data. */ - void received(ubyte[] data) @nogc; + void received(in ubyte[] data) @nogc; /** * Called when a connection is made. diff --git a/source/tanya/container/vector.d b/source/tanya/container/vector.d index bbeb2f6..e71d203 100644 --- a/source/tanya/container/vector.d +++ b/source/tanya/container/vector.d @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Copyright: Eugene Wissner 2016. + * Copyright: Eugene Wissner 2016-2017. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) @@ -180,6 +180,11 @@ private struct Range(E) return true; } + @property inout(E[]) data() inout + { + return begin[0 .. length]; + } + static if (isMutable!E) { bool opEquals(Range that) @@ -1408,6 +1413,21 @@ struct Vector(T) return vector[0 .. length]; } + /// + unittest + { + auto v = Vector!int(IL(1, 2, 4)); + + assert(v.data[0] == 1); + assert(v.data[1] == 2); + assert(v.data[2] == 4); + assert(v.data.length == 3); + + auto data = v[1 .. 2].data; + assert(data[0] == 2); + assert(data.length == 1); + } + mixin DefaultAllocator; }