Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Enabling tcp

SaeHie Park edited this page Sep 25, 2015 · 4 revisions

TCP structure uv_tcp_t inherits uv_stream_t

struct uv_tcp_s {
  UV_HANDLE_FIELDS
  UV_STREAM_FIELDS
  UV_TCP_PRIVATE_FIELDS
};

typical TCP connect Sequence

  1. uv_tcp_init()
  • calls uv__stream_init()
  1. uv__stream_init()
  • calls uv__handle_init()
  • initialises structure members
  • calls uv__io_init() with stream->io_watcher and callback uv__stream_io()
  1. uv__io_init()

  2. uv_tcp_open()

  • calls uv__stream_open()
  1. uv__stream_open()
  • sets stream->io_watcher.fd to socket
  1. uv_tcp_connect()
  • calls uv__tcp_connect()
  1. uv__tcp_connect()
  • calls uv__socket() to get socket
  • calls uv__stream_open() with socket
  • calls connect() with stream.fd which is socket
  • calls uv__req_init() with uv_connect_t type connection request req
  • sets connection callback to req
  • calls uv__io_start() with UV__POLLOUT
  1. uv__io_start()
  • adds watcher to loop->watcher_queue
  1. uv_run()
  • in uv__stream_io(), calls uv__stream_connect() if stream->connect_req exist
  • in uv__stream_connect(), req callback is called

listen in server

  1. uv_tcp_init()

  2. uv_tcp_bind()

  3. uv_listen()

  • calls uv_tcp_listen()
  1. uv_tcp_listen()
  • calls maybe_new_socket()
  • calls listen()
  • calls uv__io_start with uv__server_io
    • adds to loop watchers
  • uv__handle_start()
  1. uv__server_io()
  • calls uv__io_start() with UV__POLLIN
Clone this wiki locally