fix(server.go) fix data race in server.stop
Use setState() function to set state; avoid data race.
fix(peer.go) protect lastActivity with peer lock
fix(server.go) use server.setState everywhere
fix(transporter) set ResponseHeaderTimeout before using it; avoid data race
util: Handle all errors in writeFileSync

Before this patch, errors returned by f.Write would be swallowed and
replaced by io.ErrShortWrite if the number of bytes written was less than the
number of bytes to be written.

etcd was panicking on startup because it had no space to write conf.tmp to its
data directory and the panic string was "short write" which was not very
informative of the real problem.

After applying this patch, we got a nice error message in our panic:
"panic: write /data/etcd/conf.tmp: no space left on device"
Merge pull request #209 from tsenart/master

util: Handle all errors in writeFileSync
fix: wait for all goroutines to finish before Stop

Changes are as follows:

1. Use wait group to wait all goroutines to finish before Stop
2. Remove `stop` channel because its functionality could be
replaced by the wait group
3. Change `stopped` type to `chan bool`, considering it doesn't
need to transfer `stop`
4. Make `send` function also notified by `stopped`, and cancel the request
when stopped
5. Error handling in HTTP handler functions which is caused by
canceling requests
chore(handler): add error message
Merge pull request #205 from xiangli-cmu/fix_data_race

Fix data race
Merge pull request #208 from xiangli-cmu/fix_init

fix(server.go) fix the problem that the server cannot be inited after loading snapshot.
Merge branch 'master' of github.com:goraft/raft

Conflicts:
	server.go
chore(server): avoid blocking on event send
chore(server): improve comment
Merge pull request #211 from unihorn/55

fix: wait for all goroutines to finish before Stop
fix(server.go) fix incorrect stateChangeEvent dispatching
Fix a bug introduced by race fix. The setState function will be called even if there is no actual stateChange. Check the previous state before dispatching the event.