implementation of callback functions

each state of the connection is accessible trough a callback, each of
them thread safe. to allow two thread calling another callback, each
one is protected by a separated mutex.