Feature to enable asynchronous event driven network event handling

Implemented asynchronous event driven network handling.

The current network code works well, but relies on what amounts to polling behaviour where one sets up non-blocking sockets, but then have to rely on periodically calling from a timed loop such as emscripten_set_main_loop because select/poll can't have blocking behaviour in an asynchronous environment like JavaScript.

This pull request provides a mechanism to register callbacks for the key network events from both C code and native JavaScript code. The callbacks are linked to the underlying WebSocket callbacks, but they trigger after the emscripten library calls have done their magic. This means that when the message callback triggers for example there will be data in the socket buffer ready to be read.

The various callbacks are passed the file descriptor of the triggering socket, so it is possible to avoid the use of select/poll as the fd is already known, but equally it's possible to use largely unmodified select/poll based code and just use the async callbacks in place of emscripten_set_main_loop. The test case submitted with this pull request uses that approach.

I've also implemented getsockopt with support for SOL_SOCKET/SO_ERROR, which should hopefully resolve https://github.com/kripken/emscripten/issues/2211

The primary use case for this work is to avoid the need for polling network activity, which will improve efficiency and latency for applications that make use of it. It should also make it easier to incorporate emscripten compiled code in other event loops.
Yeah I implemented it this way exactly because I wanted to provide a mechanism where it was just as easy to register network callbacks from native JavaScript as it was from compiled code.

In actual fact calling it from JavaScript is pretty much the main way I use it. The application I'm working on is really a compiled C library and I'm putting a JavaScript "binding" round it so that it behaves like idiomatic JavaScript - it's a lot more complicated than it sounds :-) but one of the fun bits was abstracting the network handling.

You are correct that it only allows a single callback to be registered and the previous one is replaced. I think that's fine (and I've never needed more) and I *think* that it's consistent with the behaviour of the various html5 things - I can only see "emscripten_set_*" for those and looking at registerOrRemoveHandler there's a test "if (eventHandler.callbackfunc)" which if false calls the JSEvents._removeHandler.

You are absolutely right though that I should document that. What I think I'll do is add a bit in this file and also add some documentation in the emscripten.h to cover the calls from native JavaScript as well as from compiled code.