Skip to content
clarus edited this page Oct 12, 2014 · 23 revisions

It seems hard and even impossible to have fully asynchronous system API on widespread operating systems such as Linux. Asynchronous calls can be emulated using one thread per call, but threads are expensive.

Waiting for this problem to be properly solved, we will design an asynchronous and OS independent API, interacting with the OS through a proxy. The proxy communicates with the application using a pipe, and tries to be as less blocking as possible.

Simple API

We describe here a simple API which will be used to start with. There is no error handling, and read/write operations are of unbounded size.

Output messages

  • Log.Write message
  • File.Read file_name
  • TCPClientSocket.Write id message
  • TCPClientSocket.Close id
  • TCPServerSocket.Bind port
  • TCPServerSocket.Close id

Input messages

  • File.Read file_name content
  • TCPClientSocket.Accepted id
  • TCPClientSocket.Read id counter content
  • TCPClientSocket.Written id
  • TCPServerSocket.Bound id

Request / answer API

It is often necessary to know if a command finished, made an error or is just pending. For example, when you want to close a socket, you want to be sure all operations are terminated. For that, we need to add for each system call a systematic answer, upon termination or error. To associate answer to requests, an integer has to be attached to each request and is given back with the corresponding answer.

Message name Output type Input type
Log
FileRead
ServerSocketBind
ClientSocketRead
ClientSocketWrite
ClientSocketClose

Output messages

  • Log of string
  • FileRead of string
  • ServerSocketBind of N
  • ClientSocketRead of ClientSocketId.t
  • ClientSocketWrite of ClientSocketId.t * string
  • ClientSocketClose of ClientSocketId.t

Input messages

  • Log of bool
  • FileRead of option string
  • ServerSocketBind of option ClientSocketId.t
  • ClientSocketRead of option string
  • ClientSocketWrite of bool
  • ClientSocketClose of bool

References

Clone this wiki locally