add error and connected flags

In some cases it may not be convenient to check the return values
of send/recv and these flags can simplify error handling.