Libuv Internal Architecture

Posted By : Shashwat Gupta | 30-Nov-2017

Libuv

its a cross -plateform async IO libery . its c++ small libery

Features:

  • event loop
  • TCP/UDP sockets
  • file system operations
  • threading utilities

Libuv Architecture

  • Event Loop : uv_loop_t - single threaded event loop
  • handles : uv_handles_t - handler is resouces .its a entity that is able to do certain type of works .
  • timers handler:- call a callback a certtain amount of time
  • tcp handles : handle your connections . reading and writing over the connections
  • Requests: uv_req_t : request are operations(standalone and with handler both ) , uv write a write some data over a string connections , fs open : request for open a file(standalone operation)

other utilities

three main block

Os Dependent

  1. network IO
  2. File IO
  3. other stuff

Os Independent Block

  1. os independent stuff

Os Independent Block

  • uv_TCP_t
  • uv_PIPE_t
  • uv_TTY_t
  • uv_UDP_t
  • uv_POLL_t
  • uv_IOT_t
  • uv_stream_t
  • Operating System

 

Network IO

 

uv_TCP_t , PIPE , TTY , UDP , POLL > handle low level IO
TCP pipes , tty : stream based > stream of data -> tcp.c -> less code even string.c have full code of how handle tcp
uv IOT -> in unix (linuc.court.c)
in mac > darwin.c

The I/O loop


The input and output is the central part of libuv Arc. It implemented the code for all I/O operations, and it’s basically tied to a single thread. if run multiple of event loops then each runs in a different thread. The libuv event loop is not thread-safe The event loop uses usually single threaded asynchronous approach event loop will block waiting for Input and output activity on sockets As part of a loop iteration the loop :

 

File IO

 

 

for uv fs requests

uv_work_t,uv_fs_t,uv_getaddr_info,uv_get_name_info,thread pool
uv_work_t : user supplied funtion to do custom works
uv_getaddr_info,uv_get_name_info : DNS request : like name resolutions

all these run on the thread pool
thread pool : build with our os independently utility
we use thread only for
thread fileio
getAddrinfo
default size is 4

 

 

Others

os_independent
uv_timer_t , idle , prepain , check
os_dependent
uv_singnal_t
uv_process_t

 

 

libuv : event_loop

 

LIBUV CODE FOR EVENT LOOP


About Author

Author Image
Shashwat Gupta

Shashwat is a bright Mean Stack Developer . He has good experience in development of complex UI's of web application and hybrid mobile applications.

Request for Proposal

Name is required

Comment is required

Sending message..