summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2016-12-24 22:25:34 +0100
committerEugen Wissner <belka@caraus.de>2016-12-24 22:25:34 +0100
commitc966b42ac310488cb1c4174e0dbe4013c0af9bf5 (patch)
treecebd0bcda999ef977eea66918ca4d0d80a20ccdc
parent200fff371474adc6b7fe2e9a453e82363c60ad96 (diff)
downloadtanya-c966b42ac310488cb1c4174e0dbe4013c0af9bf5.tar.gz
Fix FreeBSD build
-rw-r--r--.gitignore1
-rw-r--r--README.md52
-rw-r--r--source/tanya/async/event/kqueue.d155
-rw-r--r--source/tanya/async/event/selector.d2
-rw-r--r--source/tanya/async/loop.d6
-rw-r--r--source/tanya/math/random.d3
6 files changed, 121 insertions, 98 deletions
diff --git a/.gitignore b/.gitignore
index 500250f..6cc196c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
# D
.dub
__test__*__
+__test__*__.core
diff --git a/README.md b/README.md
index 63d8886..19206cd 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,17 @@
# Tanya
[![Build Status](https://travis-ci.org/caraus-ecms/tanya.svg?branch=master)](https://travis-ci.org/caraus-ecms/tanya)
-[![License](http://img.shields.io/badge/license-MPL2-blue.svg)](https://raw.githubusercontent.com/caraus-ecms/tanya/master/LICENSE)
+[![Dub Version](https://img.shields.io/dub/v/tanya.svg)](https://code.dlang.org/packages/tanya)
+[![License](https://img.shields.io/badge/license-MPL_2.0-blue.svg)](https://raw.githubusercontent.com/caraus-ecms/tanya/master/LICENSE)
Tanya is a general purpose library for D programming language that doesn't
rely on the Garbage Collector.
-The library is currently in development.
+Its aim is to simplify the manual memory management in D and to provide a
+guarantee with @nogc attribute that there are no hidden allocations on the
+Garbage Collector heap. Everything in the library is usable in @nogc code.
+Tanya extends Phobos functionality and provides alternative implementations for
+data structures and utilities that depend on the Garbage Collector in Phobos.
## Overview
@@ -18,3 +23,46 @@ Tanya consists of the following packages:
* `math`: Multiple precision integer and a set of functions.
* `memory`: Tools for manual memory management (allocator, reference counting, helper functions).
* `network`: URL-Parsing, sockets.
+
+### Current status
+
+The library is currently under development, but some parts of it can already be
+used.
+
+Containers were newly reworked and the API won't change significantly, but will
+be only extended. The same is true for the `memory` package.
+
+`network` and `async` packages should be reviewed in the future and the API may
+change.
+
+`math` package contains an arbitrary precision integer implementation that has
+a stable API (that mostly consists of operator overloads), but still needs
+testing and work on its performance.
+
+I'm currently mostly working on `crypto` that is not a complete cryptographic
+suite, but contains (will contain) algorithm implementations required by TLS.
+
+### Other properties
+
+* Tanya is a native D library (only D and Assembler are tolerated).
+
+* It is important for me to document the code and attach at least a few unit
+tests where possible. So the documentation and usage examples can be found in
+the source code.
+
+* Tanya is mostly tested on a 64-bit Linux and some features are
+platform-dependant, but not because it is a Linux-only library. Therefore any
+help to bring better support for Windows and BSD systems would be accepted.
+
+* The library isn't thread-safe. Thread-safity should be added later.
+
+* I'm working with the latest dmd version, but will be looking to support other
+D compilers and keep compatibility with the elder dmd versions in the future.
+
+## Contributing
+
+Since I'm mostly busy writing new code and implementing new features I would
+appreciate, if anyone uses the library. It would help me to improve the
+codebase and fix issues.
+
+Feel free to contact me if you have any questions.
diff --git a/source/tanya/async/event/kqueue.d b/source/tanya/async/event/kqueue.d
index cf7f3c1..5014b33 100644
--- a/source/tanya/async/event/kqueue.d
+++ b/source/tanya/async/event/kqueue.d
@@ -6,126 +6,101 @@
* Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
- * Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner)
+ * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/
module tanya.async.event.kqueue;
version (OSX)
{
- version = MissingKevent;
+ version = MacBSD;
}
else version (iOS)
{
- version = MissingKevent;
+ version = MacBSD;
}
else version (TVOS)
{
- version = MissingKevent;
+ version = MacBSD;
}
else version (WatchOS)
{
- version = MissingKevent;
+ version = MacBSD;
+}
+else version (FreeBSD)
+{
+ version = MacBSD;
}
else version (OpenBSD)
{
- version = MissingKevent;
+ version = MacBSD;
}
else version (DragonFlyBSD)
{
- version = MissingKevent;
+ version = MacBSD;
}
-version (MissingKevent)
-{
- extern (C):
- nothrow:
- @nogc:
-
- import core.stdc.stdint; // intptr_t, uintptr_t
- import core.sys.posix.time; // timespec
-
- enum : short
- {
- EVFILT_READ = -1,
- EVFILT_WRITE = -2,
- EVFILT_AIO = -3, /* attached to aio requests */
- EVFILT_VNODE = -4, /* attached to vnodes */
- EVFILT_PROC = -5, /* attached to struct proc */
- EVFILT_SIGNAL = -6, /* attached to struct proc */
- EVFILT_TIMER = -7, /* timers */
- EVFILT_MACHPORT = -8, /* Mach portsets */
- EVFILT_FS = -9, /* filesystem events */
- EVFILT_USER = -10, /* User events */
- EVFILT_VM = -12, /* virtual memory events */
- EVFILT_SYSCOUNT = 11
- }
-
- extern(D) void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args)
- {
- *kevp = kevent_t(args);
- }
-
- struct kevent_t
- {
- uintptr_t ident; /* identifier for this event */
- short filter; /* filter for event */
- ushort flags;
- uint fflags;
- intptr_t data;
- void *udata; /* opaque user data identifier */
- }
-
- enum
- {
- /* actions */
- EV_ADD = 0x0001, /* add event to kq (implies enable) */
- EV_DELETE = 0x0002, /* delete event from kq */
- EV_ENABLE = 0x0004, /* enable event */
- EV_DISABLE = 0x0008, /* disable event (not reported) */
-
- /* flags */
- EV_ONESHOT = 0x0010, /* only report one occurrence */
- EV_CLEAR = 0x0020, /* clear event state after reporting */
- EV_RECEIPT = 0x0040, /* force EV_ERROR on success, data=0 */
- EV_DISPATCH = 0x0080, /* disable event after reporting */
-
- EV_SYSFLAGS = 0xF000, /* reserved by system */
- EV_FLAG1 = 0x2000, /* filter-specific flag */
-
- /* returned values */
- EV_EOF = 0x8000, /* EOF detected */
- EV_ERROR = 0x4000, /* error, data contains errno */
- }
+version (MacBSD):
- int kqueue();
- int kevent(int kq, const kevent_t *changelist, int nchanges,
- kevent_t *eventlist, int nevents,
- const timespec *timeout);
-}
+import core.stdc.stdint; // intptr_t, uintptr_t
+import core.sys.posix.time; // timespec
-version (OSX)
-{
- version = MacBSD;
-}
-else version (iOS)
+void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args) pure nothrow @nogc
{
- version = MacBSD;
+ *kevp = kevent_t(args);
}
-else version (FreeBSD)
+
+enum : short
{
- version = MacBSD;
- public import core.sys.freebsd.sys.event;
+ EVFILT_READ = -1,
+ EVFILT_WRITE = -2,
+ EVFILT_AIO = -3, /* attached to aio requests */
+ EVFILT_VNODE = -4, /* attached to vnodes */
+ EVFILT_PROC = -5, /* attached to struct proc */
+ EVFILT_SIGNAL = -6, /* attached to struct proc */
+ EVFILT_TIMER = -7, /* timers */
+ EVFILT_MACHPORT = -8, /* Mach portsets */
+ EVFILT_FS = -9, /* filesystem events */
+ EVFILT_USER = -10, /* User events */
+ EVFILT_VM = -12, /* virtual memory events */
+ EVFILT_SYSCOUNT = 11
}
-else version (OpenBSD)
+
+struct kevent_t
{
- version = MacBSD;
+ uintptr_t ident; /* identifier for this event */
+ short filter; /* filter for event */
+ ushort flags;
+ uint fflags;
+ intptr_t data;
+ void *udata; /* opaque user data identifier */
}
-else version (DragonFlyBSD)
+
+enum
{
- version = MacBSD;
+ /* actions */
+ EV_ADD = 0x0001, /* add event to kq (implies enable) */
+ EV_DELETE = 0x0002, /* delete event from kq */
+ EV_ENABLE = 0x0004, /* enable event */
+ EV_DISABLE = 0x0008, /* disable event (not reported) */
+
+ /* flags */
+ EV_ONESHOT = 0x0010, /* only report one occurrence */
+ EV_CLEAR = 0x0020, /* clear event state after reporting */
+ EV_RECEIPT = 0x0040, /* force EV_ERROR on success, data=0 */
+ EV_DISPATCH = 0x0080, /* disable event after reporting */
+
+ EV_SYSFLAGS = 0xF000, /* reserved by system */
+ EV_FLAG1 = 0x2000, /* filter-specific flag */
+
+ /* returned values */
+ EV_EOF = 0x8000, /* EOF detected */
+ EV_ERROR = 0x4000, /* error, data contains errno */
}
-version (MacBSD):
+extern(C) int kqueue() nothrow @nogc;
+extern(C) int kevent(int kq, const kevent_t *changelist, int nchanges,
+ kevent_t *eventlist, int nevents, const timespec *timeout)
+ nothrow @nogc;
import tanya.async.event.selector;
import tanya.async.loop;
@@ -206,8 +181,8 @@ class KqueueLoop : SelectorLoop
* Returns: $(D_KEYWORD true) if the operation was successful.
*/
override protected bool reify(ConnectionWatcher watcher,
- EventMask oldEvents,
- EventMask events) @nogc
+ EventMask oldEvents,
+ EventMask events) @nogc
{
if (events != oldEvents)
{
@@ -251,7 +226,7 @@ class KqueueLoop : SelectorLoop
{
if (errno != EINTR)
{
- throw defaultAllocatorAllocator.make!BadLoopException();
+ throw defaultAllocator.make!BadLoopException();
}
return;
}
diff --git a/source/tanya/async/event/selector.d b/source/tanya/async/event/selector.d
index 5f42bd2..28dbaee 100644
--- a/source/tanya/async/event/selector.d
+++ b/source/tanya/async/event/selector.d
@@ -239,7 +239,7 @@ abstract class SelectorLoop : Loop
if (io is null)
{
io = MmapPool.instance.make!IOWatcher(transport,
- connection.protocol);
+ connection.protocol);
connections[client.handle] = io;
}
else
diff --git a/source/tanya/async/loop.d b/source/tanya/async/loop.d
index a7859d4..1526251 100644
--- a/source/tanya/async/loop.d
+++ b/source/tanya/async/loop.d
@@ -17,17 +17,17 @@
* {
* private DuplexTransport transport;
*
- * void received(ubyte[] data)
+ * void received(ubyte[] data) @nogc
* {
* transport.write(data);
* }
*
- * void connected(DuplexTransport transport)
+ * void connected(DuplexTransport transport) @nogc
* {
* this.transport = transport;
* }
*
- * void disconnected(SocketException e = null)
+ * void disconnected(SocketException e = null) @nogc
* {
* }
* }
diff --git a/source/tanya/math/random.d b/source/tanya/math/random.d
index 0405bc0..e58d209 100644
--- a/source/tanya/math/random.d
+++ b/source/tanya/math/random.d
@@ -12,7 +12,6 @@
*/
module tanya.math.random;
-import std.experimental.allocator;
import std.digest.sha;
import std.typecons;
import tanya.memory;
@@ -167,7 +166,7 @@ class Entropy
private ubyte sourceCount_;
- private IAllocator allocator;
+ private shared Allocator allocator;
/// Entropy accumulator.
protected SHA!(maxGather * 8, 512) accumulator;