unix: handle POLLERR and POLLHUP in uv__stream_io

Fixes a busy loop when the file descriptor emits POLLHUP but not POLLIN
or POLLOUT, e.g. when polling the read end of a pipe and the write end
is closed.

Fixes joyent/node#4923.
win/tty: fix case where uv_read_start incorrectly reports failure

In very rare circumstances a uv_read_start() call on a uv_tty_t handle
in raw mode would return -1 but there was no actual failure. This patch
fixes that.
win/tty: don't touch insert mode or quick edit mode

Hopefully this fixes joyent/node#4809.
win/tty: fix typo in color attributes enumeration
unix: honor UV_THREADPOOL_SIZE environment var

Make the size of the thread pool configurable through an environment
variable. For sanity reasons, the size is clamped to the range 1-128.
unix: fix strict aliasing warnings, macro-ify functions

Replace a few internal functions in uv-common.h with macros to avoid
strict aliasing warnings with older versions of gcc.

It's not smart enough to figure out that e.g. a uv_tcp_t is an instance
of uv_handle_t with similar alignment requirements and therefore no
aliasing happens. More recent versions of gcc don't suffer from this.

I'm not normally in the habit of catering to compiler defects but the
aliasing warnings drown out legitimate warnings, hence the change.
unix: add STATIC_ASSERT macro
unix: add uv_buf_t static asserts to core.c

Verify that our uv_buf_t type is ABI-compatible with struct iovec.
unix: fix strict aliasing warning in udp.c
unix: replace volatile cast with ACCESS_ONCE macro
unix: please valgrind, free memory in threadpool.c
win: Map ERROR_INVALID_FUNCTION to EISDIR

This error is raised when calling read() or write() on a directory.

A bit of googling turns up some cases where this error can be raised
that are not properly mapped to EISDIR, but are also cases that libuv
doesn't really care about, like the Password Manager API,
GetFirmwareEnvironmentVariable, or CreateTapePartition.

If libuv ever needs to handle these cases, then I suppose that the
ERROR_INVALID_FUNCTION->EISDIR mapping could be done directly in the
fs read() and write() functions, but doing so at this point seems
premature, as it makes the error code mapping a bit more messy.

Fixes joyent/node#4951
win: fix potential HANDLE corruption due to incorrect cast

Closes #738.
win/tcp: don't enable iocp sync bypass when iocp emulation is used

When iocp sync bypass is in use libuv doesn't expect the system to
generate events when an i/o operation completes synchronously. However
when iocp emulation is enabled an event will always be generated because
SetFileCompletionNotificationModes() doesn't stop OVERLAPPED.hEvent from
becoming signaled.

This should fix joyent/node#4959.
test: add tap output for windows
unix: fix uv_tcp_simultaneous_accepts() logic

Inverts the meaning of the 'enable' argument. Before, it actually set
the UV_TCP_SINGLE_ACCEPT flag when enable=1. Now it clears it, which is
what uv-win does and what you would expect it to do.
include: bump UV_VERSION_MINOR

Fixes #740.
unix: improve uv_guess_handle() implementation

Make it understand FIFOs, character devices and sockets.
stream: run try_select only for pipes and ttys

Its not necesary for TCP and other streams, since fd is always working
with kqueue there.
build: rename OS to PLATFORM

Rename the OS make variable to PLATFORM, it conflicts with the OS env
var. That is, running `make` when the OS env var is set, may cause
spurious build breakage.

Fixes #737.