roc-toolkit icon indicating copy to clipboard operation
roc-toolkit copied to clipboard

TCP support

Open gavv opened this issue 6 years ago • 3 comments

Add TCP support to roc_netio. It can be used for RTSP, SIP, and RTP over TCP.

The most import thing to consider before implementing this is communication between the netio and control threads.

gavv avatar May 31 '19 19:05 gavv

Implementation

  • [ ] Add netio::IConnAcceptor

    Implemented by netio user (roc_ctl). TCPServer calls IConnAcceptor::accept() for every new incoming connection. accept() gets the TCPConn object that can be used to read and write data and returns IConnNotifier implementation that will be associated with the given TCPConn and will be notified when it becomes readable or writable. Invoked on libuv thread.

    class IConnAcceptor {
    public:
      virtual IConnNotifier* accept(TCPConn&) = 0;
    };
    
  • [ ] Add netio::IConnNotifier

    Implemented by netio user (roc_ctl). Associated with TCPConn object. Is notified when TCPConn becomes readable or writable. Invoked on libuv thread.

    class IConnNotifier {
    public:
      virtual void notify_connected() = 0;
      virtual void notify_readable() = 0;
      virtual void notify_writable() = 0;
    };
    
  • [ ] Add netio::TCPServer

    Runs in background (on libuv thread) and listens and accepts clients. Creates a new TCPConn object for each new client connection and passes it to IConnAcceptor.

  • [ ] Add netio::TCPClient

    Runs in background (on libuv thread) and asynchronously connects to given server address. When connection is established, IConnNotifier is notified and the TCPConn object becomes usable.

  • [ ] Add netio::TCPConn

    class TCPConn {
    public:
      Address source();
      Address destination();
      bool connected();
      write(...);
      read(...);
    };
    

    Represents a single bidirectional TCP connection. Contains: libuv tcp handle; libuv async handle; a mutex; a pointer to IConnNotifier; libuv callbacks invoked when tcp socket becomes readable/writable; libuv callback for async handle. The user may call write() and read() from any thread; TCPConn will wakeup the libuv thread using its async handle and block the user until the write or read is finished. When the socket becomes readable/writable, TCPConn invokes corresponding IConnNotifier methods on the libuv thread.

  • [ ] Add netio::Transceiver methods

    // creates TCPClient that starts asynchronous connect to the
    // given address; when the connection is established,
    // IConnNotifier is notified
    TCPConn* add_tcp_client(Address, stream::IConnNotifier&);
    
    // creates TCPServer that starts listening on the given address;
    // every time a new incoming connection is accepted,
    // IConnAcceptor is called
    bool add_tcp_server(Address, stream::IConnAcceptor&);
    

gavv avatar Jun 06 '19 12:06 gavv

High-level overview of TCPServer component:

TCPServer

High-level overview of TCPClient component:

TCPClient

dshil avatar Sep 02 '19 13:09 dshil

After finishing this, please also add diagrams to the sphinx docs. I think we should add a page about roc_netio to "Internals" section. I think it's not necessary to document the entire module right now, it would be enough to start with documenting the TCP part. Later I'll also add a page about roc_sndio.

gavv avatar Oct 07 '19 20:10 gavv