optimize code, modify interface to add connection state.

Signed-off-by: charlown.cai <charlown@163.com>