Fix more list handling issues.

When a nn_list_item is erased from a list, it is set to nil, so the
item owner can check if the item belong to a list.

This change revealed an error in nn_timeout_rm(), trying to remove a
nil list item. Now nn_timeout_rm check the handle before removing it.

nn_timeout_hndl.list was not initialized - now it is initialized in
nn_timer_init(). It would be cleaner in nn_timeout_hndl_init(), but we
don't have that function yet :-).

When list was cleared, list items were not set to nil. Now they are.

Finally, there is now a new test module for the list module.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Fix list item initialization and removeal in astream.

astream was not initializing its list item and was trying to remove the
item before the item was added to the list.

This fix one type of crash during tcp_shutdown test.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Add the list test module.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Improve list documentation.

Unify terms - list items instead of list elements, fix typos, unify
style.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
More stric list item handling.

This make list item handling more strict, hopefully preventing
unexpected behavior becuase of uninitialized memory, and making it
easier to debug such issues.

List item usage rules:

- A list item must be initialized using new nn_list_item_init(),
  replacing nn_list_item_nil().
- If you ignore the rule above, inserting an uninitialized list item
  assert :-)
- A list item should be terminated using new nn_list_item_term(). This
  function assert that the item is nill and is not part of any list.

Implementation changes:

To support static initalization, NN_LIST_INITIALIZER macro was added.

The special nil list item value was changed to -1 (0xffffffffffffffff).
This make it easier to expose the value for other modules in a safe way,
and to detect nil items while debugging. This also ensure that code
trying to use nil list item will segfault.

All code was modified to initialize and terminate list items properly.
Note that the best place to terminate list item is not always clear, as
some objects not have a termination function (e.g. xxx_term). This part
of the patch needs good review.

The patch reveal possible data race in the tcp_shutdown test - the test
fails now when trying to insert an invalid list item:

    next = 0xffffffffffffffff,
    prev = 0x23ffffffffffff

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
nn_list_clear function removed

The function had O(n) complexity. The list is supposed
to have all operations O(1) complex.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>