Skip to content
Snippets Groups Projects
  • Andy Green's avatar
    d702b83d
    uv: allocate watcher · d702b83d
    Andy Green authored
    Until now the uv watcher has been composed in the wsi.
    
    This works fine except in the case of a client wsi that
    meets a redirect when the event loop is libuv with its
    requirement for handle close via the event loop.
    
    We want to reuse the wsi, since the originator of it has
    a copy of the wsi pointer, and we want to conceal the
    redirect.  Since the redirect is commonly to a different
    IP, we want to keep the wsi alive while closing its
    socket cleanly.  That's not too difficult, unless you are
    using uv.
    
    With UV the comoposed watcher is a disaster, since after
    the close is requested the wsi will start to reconnect.
    We tried to deal with that by copying the uv handle and
    freeing it when the handle close finalizes.  But it turns
    out the handle is in a linked-list scheme in uv.
    
    This patch hopefully finally solves it by giving the uv
    handle its own allocation from the start.  When we want
    to close the socket and reuse the wsi, we simply take
    responsibility for freeing the handle and set the wsi
    watcher pointer to NULL.
    d702b83d
    History
    uv: allocate watcher
    Andy Green authored
    Until now the uv watcher has been composed in the wsi.
    
    This works fine except in the case of a client wsi that
    meets a redirect when the event loop is libuv with its
    requirement for handle close via the event loop.
    
    We want to reuse the wsi, since the originator of it has
    a copy of the wsi pointer, and we want to conceal the
    redirect.  Since the redirect is commonly to a different
    IP, we want to keep the wsi alive while closing its
    socket cleanly.  That's not too difficult, unless you are
    using uv.
    
    With UV the comoposed watcher is a disaster, since after
    the close is requested the wsi will start to reconnect.
    We tried to deal with that by copying the uv handle and
    freeing it when the handle close finalizes.  But it turns
    out the handle is in a linked-list scheme in uv.
    
    This patch hopefully finally solves it by giving the uv
    handle its own allocation from the start.  When we want
    to close the socket and reuse the wsi, we simply take
    responsibility for freeing the handle and set the wsi
    watcher pointer to NULL.
private.h 2.53 KiB