net: set *fd to -1 if operation failed, check fd value in net_close()
net: set *fd to -1 if operation failed, check fd value in net_close()

Set *fd to -1 in net_connect() and net_bind() if any of
the operations failed and close() was called on *fd. This
ensures that *fd is set to a valid file descriptor only
if all operations succeeded.

Check fd value in net_close(), only perform the shutdown
and close only on non-negative fd values.

theatrus/tropicssl,appunite/tropicssl,theatrus/tropicssl,appunite/tropicssl