Fixed build on OSX.

- For some reason the "extern int pid_daemon" usage in libwebsockets.c would cause an "undefined symbols" linker error for the test-apps. This only happens with the CMake project, not the normal Makefiles. I have no clue why this is. Fixed it by getting the pid via a function instead.

- Added test-server-extpoll

- Renamed the library from libwebsocket -> libwebsockets
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4dee826..deaeca4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@
 option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
 option(WITHOUT_CLIENT "Don't build the client part of the library" OFF)
 option(WITHOUT_SERVER "Don't build the server part of the library" OFF)
+option(WITHOUT_SERVER_EXTPOLL "Don't build a server version that uses external poll" OFF)
 option(WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON)
 option(WITHOUT_PING "Don't build the ping test application" OFF)
 option(WITHOUT_DEBUG "Don't compile debug related code" OFF)
@@ -237,7 +238,7 @@
 #
 # Create the lib.
 #
-add_library(websocket STATIC
+add_library(websockets STATIC
 			${HDR_PRIVATE}
 			${HDR_PUBLIC}
 			${SOURCES})
@@ -287,7 +288,7 @@
 message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
 message("ZLib libraries: ${ZLIB_LIBRARIES}")
 include_directories(${ZLIB_INCLUDE_DIRS})
-target_link_libraries(websocket ${ZLIB_LIBRARIES})
+target_link_libraries(websockets ${ZLIB_LIBRARIES})
 
 #
 # OpenSSL
@@ -310,18 +311,18 @@
 	message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
 	message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
 	include_directories(${OPENSSL_INCLUDE_DIR})
-	target_link_libraries(websocket ${OPENSSL_LIBRARIES})
+	target_link_libraries(websockets ${OPENSSL_LIBRARIES})
 endif(WITH_SSL)
 
 #
 # Platform specific libs.
 #
 if (WIN32)
-	target_link_libraries(websocket ws2_32.lib)
+	target_link_libraries(websockets ws2_32.lib)
 endif()
 
 if (UNIX)
-	target_link_libraries(websocket m)
+	target_link_libraries(websockets m)
 endif()
 
 #
@@ -352,7 +353,7 @@
 		source_group("Headers"   FILES ${TEST_HDR})
 		source_group("Sources"   FILES ${TEST_SRCS})
 		add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
-		target_link_libraries(${TEST_NAME} websocket)
+		target_link_libraries(${TEST_NAME} websockets)
 
 		set_property(
 					TARGET ${TEST_NAME}
@@ -383,6 +384,22 @@
 	endif(NOT WITHOUT_SERVER)
 
 	#
+	# test-server-extpoll
+	#
+	if (NOT WITHOUT_SERVER_EXTPOLL)
+		create_test_app(test-server-extpoll
+			"test-server/test-server.c"
+			""
+			"${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
+			
+			# Set defines for this executable only.
+			set_property(
+				TARGET test-server-extpoll
+				PROPERTY COMPILE_DEFINITIONS EXTERNAL_POLL INSTALL_DATADIR="${SSL_CERT_DIR}"
+				)
+	endif(NOT WITHOUT_SERVER_EXTPOLL)
+
+	#
 	# test-fraggle
 	#
 	if (NOT WITHOUT_FRAGGLE)
diff --git a/lib/daemonize.c b/lib/daemonize.c
index c56ad7f..ab537a0 100644
--- a/lib/daemonize.c
+++ b/lib/daemonize.c
@@ -24,6 +24,11 @@
 int pid_daemon;
 static char *lock_path;
 
+int get_daemonize_pid()
+{
+	return pid_daemon;
+}
+
 static void
 child_handler(int signum)
 {
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index 17fd7ef..d747166 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -1513,7 +1513,8 @@
 #endif
 
 #ifndef LWS_NO_DAEMONIZE
-	extern int pid_daemon;
+	extern int get_daemonize_pid();
+	int pid_daemon = get_daemonize_pid();
 #endif
 
 	lwsl_notice("Initial logging level %d\n", log_level);
@@ -1561,6 +1562,7 @@
 		if (wsdll)
 			poll = (PFNWSAPOLL)GetProcAddress(wsdll, "WSAPoll");
 
+		/* Finally fall back to emulated poll if all else fails */
 		if (!poll)
 			poll = emulated_poll;
 	}
diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
index 769f2a7..5d618ae 100644
--- a/lib/private-libwebsockets.h
+++ b/lib/private-libwebsockets.h
@@ -47,6 +47,14 @@
 
 #include <sys/stat.h>
 
+#ifndef inline
+ #ifdef __inline
+  #define inline __inline
+ #elif defined(__inline__)
+  #define inline __inline__
+ #endif
+#endif
+
 #ifdef WIN32
 #define LWS_NO_DAEMONIZE
 
@@ -390,8 +398,8 @@
 };
 
 #ifndef LWS_LATENCY
-#define lws_latency(context, wsi, action, ret, completion)
-#define lws_latency_pre(context, wsi)
+static void lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi, const char *action, int ret, int completion) { while (0); }
+static void lws_latency_pre(struct libwebsocket_context *context, struct libwebsocket *wsi) { while (0); }
 #else
 #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
 extern void