[fix] first part of improvements towards better error handling

* tasks now contain their own coroutine states so they can be used in qos 1 and 2
* fixed the qos subscribe level should be at least once
[feature] because the resolution of the event dispatcher is one second

we can use this as a timeout of our application when we wait for an event.
[feat] reconnection upon disconnection or connection error

there is one problem whenever the connection has been broken while sending keepalive
will be fixed with the next commit
[fix] fixed removal of a heap element

Error was caused by late element removal
[fix] fixed problem  with the task infinite loop

next problem apperead with some outdated tasks it seems that the heap is broken for some reason
[fix] fixed problem with pending tasks and events
[tidy] cleaning the code from leftovers
[fix] fixed memory leak and an invalid access
[fix] added buffer memory cleaning in case of failure
[fix] added the error handling for getsockopt
[fix] error handling while connection failed
[feat] added gathering messages to sent within the queue
Merge pull request #118 from xively/feat_improve_error_handling

[feature][fix] improves error handling