Added connection timeout mechanism and a `close` API