Skip to content

Drincann/c-coroutine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

c-coroutine

This is a simple stackless coroutine library for C++.

Example

#include "src/asynclib.h"

int main(int argc, char *argv[]) {
  AsyncServerSocket asyncSocket = AsyncServerSocket();
  if (!asyncSocket.listen("8081"))
    exit(1);

  EventLoop loop;
  loop.init();
  loop.regist(asyncSocket, EventLoop::Event::READ,
              [&](auto buffer, auto len, auto _) { printf(buffer); });
  loop.regist(asyncSocket, EventLoop::Event::WRITE,
              [&](auto buffer, auto len, auto write) {
                const char *buf =
                    "HTTP/1.1 200 OK\n\n<h1 style=\"text-align: center; "
                    "padding-top: 100px;\">Hello Coroutines!</h1>";
                write(buf, strlen(buf));
              });
  loop.run();
  return EXIT_SUCCESS;
}

build:

g++ -std=c++14 -o main main.cc ./src/asynclib.cc 

run:

./main

Open your browser and visit http://localhost:8081.

About

Stackless coroutine library for C++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages