Skip to content
Snippets Groups Projects
  • Simon Tatham's avatar
    f6f8219a
    Replace PktIn reference count with a 'free queue'. · f6f8219a
    Simon Tatham authored
    This is a new idea I've had to make memory-management of PktIn even
    easier. The idea is that a PktIn is essentially _always_ an element of
    some linked-list queue: if it's not one of the queues by which packets
    move through ssh.c, then it's a special 'free queue' which holds
    packets that are unowned and due to be freed.
    
    pq_pop() on a PktInQueue automatically relinks the packet to the free
    queue, and also triggers an idempotent callback which will empty the
    queue and really free all the packets on it. Hence, you can pop a
    packet off a real queue, parse it, handle it, and then just assume
    it'll get tidied up at some point - the only constraint being that you
    have to finish with it before returning to the application's main loop.
    
    The exception is that it's OK to pq_push() the packet back on to some
    other PktInQueue, because a side effect of that will be to _remove_ it
    from the free queue again. (And if _all_ the incoming packets get that
    treatment, then when the free-queue handler eventually runs, it may
    find it has nothing to do - which is harmless.)
    f6f8219a
    History
    Replace PktIn reference count with a 'free queue'.
    Simon Tatham authored
    This is a new idea I've had to make memory-management of PktIn even
    easier. The idea is that a PktIn is essentially _always_ an element of
    some linked-list queue: if it's not one of the queues by which packets
    move through ssh.c, then it's a special 'free queue' which holds
    packets that are unowned and due to be freed.
    
    pq_pop() on a PktInQueue automatically relinks the packet to the free
    queue, and also triggers an idempotent callback which will empty the
    queue and really free all the packets on it. Hence, you can pop a
    packet off a real queue, parse it, handle it, and then just assume
    it'll get tidied up at some point - the only constraint being that you
    have to finish with it before returning to the application's main loop.
    
    The exception is that it's OK to pq_push() the packet back on to some
    other PktInQueue, because a side effect of that will be to _remove_ it
    from the free queue again. (And if _all_ the incoming packets get that
    treatment, then when the free-queue handler eventually runs, it may
    find it has nothing to do - which is harmless.)