async 0.1.14

A cross-platform event loop library of asynchroneous network sockets.


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

A cross-platform event loop library of asynchroneous network sockets.

This is a simple wrapper of network library, D language implementation. Its encapsulation is simple and clear, and is very suitable for reading and reference. Though very small, its performance is pretty good, It's a real full duplex mode.

Support platform:

Platforms FreeBSD Windows OSX Linux NetBSD OpenBSD

Support for kernel loop (while supporting IN and OUT event listener):

Epoll Kqueue IOCP

Quick Start:


// Echo server:

import std.stdio;
import std.conv;
import std.socket;
import std.exception;

import async;

void main()
{
    TcpListener listener = new TcpListener();
    listener.bind(new InternetAddress("0.0.0.0", 12290));
    listener.listen(10);

    EventLoop loop = new EventLoop(listener, null, null, &onReceive, null, null);
    loop.run();
}

void onReceive(TcpClient client, in ubyte[] data) nothrow @trusted
{
    collectException({
        writefln("Receive from %s: %d", client.remoteAddress().toString(), data.length);
        client.send(cast(ubyte[])data);
    }());
}


// Echo client:

import std.stdio;
import std.conv;
import std.socket;

void main(string[] argv)
{
    TcpSocket socket = new TcpSocket();
    socket.blocking = true;
    socket.connect(new InternetAddress("127.0.0.1", 12290));

    string data = "hello, server.";
    writeln("Client say: ", data);
    socket.send(data);

    ubyte[] buffer = new ubyte[1024];
    size_t len = socket.receive(buffer);
    writeln("Server reply: ", cast(string)buffer[0..len]);

    socket.shutdown(SocketShutdown.BOTH);
    socket.close();
}

Todo:

You can add, repair and submit after fork, and improve it together. Thank you.

Note:

IOCP has not been completed and submitted.

Authors:
  • Shove
Dependencies:
none
Versions:
0.1.14 2018-Sep-18
0.1.13 2018-Sep-03
0.1.12 2018-Jun-11
0.1.11 2018-Jun-08
0.1.10 2018-Jun-08
Show all 34 versions
Download Stats:
  • 0 downloads today

  • 181 downloads this week

  • 1407 downloads this month

  • 7769 downloads total

Score:
4.3
Short URL:
async.dub.pm