www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - tanya event loop v0.1.0

reply Eugene Wissner <belka caraus.de> writes:
A month ago I announced the first pre-alpha release of tanya, a 
general purpose library with an event loop. After a month of 
almost every day work, I think I can make a second announcement.

https://github.com/caraus-ecms/tanya

The bad news is that most probably I'm stopping my development of 
the library. The good news is that almost everything is now 
merged into dlib by Timur Gafarov: 
https://github.com/gecko0307/dlib.

My first contribution to dlib was in May 2016 and I decided that 
I would profit from extending an existing library and I can say 
that I had only positive experience from the work with Timur.

* dlib uses manual memory management aswell.
* there containers I can use without developing my own.
* there are some modules like zlib and huffman algorithm 
implementation I will need later for a web server.

You can find the event loop in dlib.async. The most noticeable 
change since the first release is that I think I can say now that 
the event loop is now cross-platform. dlib.memory.mmappool 
(memory.ullocator before) works now under Windows as well. The 
event loop itself supports epoll (linux), kqueue (developed and 
tested on FreeBSD) and IOCP (Windows). Because I need for Windows 
different sockets, I created own socket implementation. Anyway 
the work with the event loop and the sockets is now much easier 
than in the first version. UDP is still isn't supported.

Basic error handling was added.

dlib has now a "crypto" branch aswell, where I'm working on a 
light weight TLS package.

Another thing is that I changed my mind about  nogc. I still 
don't rely on the GC, but I think now that my understanding of 
 nogc was completely wrong. I thought that the missing  nogc 
means "it uses GC". But it seems to mean only "it can use GC" and 
 nogc means "it never uses GC". So I go now with allocators and 
give the user of the library the chance to decide if he wants to 
use the GC or not.

Please understand that the async package is still very simple. 
But I'm working hard on it in my free time. In the next step I 
want ot adapt it to a web framework I've started before 
(https://github.com/caraus-ecms/caraus).

Echo server example with the new version:
import dlib.async;
import dlib.network.socket;

class EchoProtocol : TransmissionControlProtocol
{
     private DuplexTransport transport;

     void received(ubyte[] data)
     {
         transport.write(data);
     }

     void connected(DuplexTransport transport)
     {
         this.transport = transport;
     }

     void disconnected(SocketException exception = null)
     {
     }
}

void main()
{
     auto address = new InternetAddress("127.0.0.1", cast(ushort) 
8192);
     version (Windows)
     {
         auto sock = new 
OverlappedStreamSocket(AddressFamily.INET);
     }
     else
     {
         auto sock = new StreamSocket(AddressFamily.INET);
         sock.blocking = false;
     }

     sock.bind(address);
     sock.listen(5);

     auto io = new ConnectionWatcher(sock);
     io.setProtocol!EchoProtocol;

     defaultLoop.start(io);
     defaultLoop.run();

     sock.shutdown();
}

There is still no online documentation. But I almost ready to 
begin to test the event loop and publish "self-hosted" 
documentation based on it.
Like always I welcome any feedback ).
Oct 08 2016
parent Karabuta <karabutaworld gmail.com> writes:
On Saturday, 8 October 2016 at 19:43:16 UTC, Eugene Wissner wrote:
 A month ago I announced the first pre-alpha release of tanya, a 
 general purpose library with an event loop. After a month of 
 almost every day work, I think I can make a second announcement.

 [...]
Really clean API design from the look of the above code. +1
Oct 09 2016