Code Monkey home page Code Monkey logo

ioucontext's Introduction

ioucontext

ioucontext is a coöperative multitasking framework built on top of liburing, libucontext, c-ares, & rustls. It is the spiritual successor to liboco.

Design

A thread-local reactor manages asynchronous operations submitted by one or more fibers, each with a built-in stack. When invoked via reactor_run, the reactor will run until all fibers terminate. An explicit choice has been made to use C11 threads over pthreads.

A new reactor will be initialized the first time reactor_get is called in a particular thread; the underlying io_uring will attempt to pin itself to one processor for which the thread has affinity. The intention is to have one io_uring running per thread, each pinned to one processor.

Fibers are created via ucontext but context-switching occurs via sigsetjmp/siglongjmp to avoid the sigprocmask system call. It is not wise to modify the process signal mask after any fiber has been created, whether or not it has run yet.

Operations that can not be immediately submitted to the underlying io_uring will be deferred onto a wait-queue. On completion, operations return to the calling fiber directly. Thus, fibers are written procedurally but will coöperatively context-switch during operations. Error codes are typically returned as negative values.

Operations may be invoked outside of a fiber but may return prior to the reactor completing all pending work. In that case, reactor_runnable will be true and an invocation of reactor_run will be required to clear the work.

Reactors can store a user-data cookie and an optional destructor via reactor_cookie_jar. When the reactor is torn down, the cookie will be eaten.

Examples

  • iou_cat --- moves bytes between one or more input streams and stdout
  • iou_dns --- resolve dns forward and reverse lookups asynchronously
  • iou_port7 --- TCP & UDP echo service, à la port7
  • iou_timers --- use multiple timerfds to make some noise
  • iou_tls --- STDIN -> TLS -> STDOUT
  • iou_tlsd --- echo/TLS on 12345

Extra

This project is a toy, created out of a desire to better understand io_uring and to atone for some of liboco's sins.

Thanks to some wonderful resources, including

License: MIT

ioucontext's People

Contributors

pallas avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.