Fix FreeBSD build

This commit is contained in:
Eugen Wissner 2016-12-24 22:25:34 +01:00
parent 200fff3714
commit c966b42ac3
6 changed files with 129 additions and 106 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
# D
.dub
__test__*__
__test__*__.core

View File

@ -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.

View File

@ -6,103 +6,10 @@
* 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;
}
else version (iOS)
{
version = MissingKevent;
}
else version (TVOS)
{
version = MissingKevent;
}
else version (WatchOS)
{
version = MissingKevent;
}
else version (OpenBSD)
{
version = MissingKevent;
}
else version (DragonFlyBSD)
{
version = MissingKevent;
}
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 */
}
int kqueue();
int kevent(int kq, const kevent_t *changelist, int nchanges,
kevent_t *eventlist, int nevents,
const timespec *timeout);
}
version (OSX)
{
version = MacBSD;
@ -111,10 +18,17 @@ else version (iOS)
{
version = MacBSD;
}
else version (TVOS)
{
version = MacBSD;
}
else version (WatchOS)
{
version = MacBSD;
}
else version (FreeBSD)
{
version = MacBSD;
public import core.sys.freebsd.sys.event;
}
else version (OpenBSD)
{
@ -127,6 +41,67 @@ else version (DragonFlyBSD)
version (MacBSD):
import core.stdc.stdint; // intptr_t, uintptr_t
import core.sys.posix.time; // timespec
void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args) pure nothrow @nogc
{
*kevp = kevent_t(args);
}
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
}
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 */
}
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;
import tanya.async.transport;
@ -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;
}

View File

@ -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

View File

@ -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
* {
* }
* }

View File

@ -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;