diff --git a/lib/client-parser.c b/lib/client-parser.c
index bb96e9b8..3131f501 100644
--- a/lib/client-parser.c
+++ b/lib/client-parser.c
@@ -21,10 +21,6 @@
 
 #include "private-libwebsockets.h"
 
-#ifdef WIN32
-#include <io.h>
-#endif
-
 int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
 {
 	int n;
diff --git a/lib/client.c b/lib/client.c
index c92bc49f..ef17ca82 100644
--- a/lib/client.c
+++ b/lib/client.c
@@ -288,7 +288,10 @@ int lws_client_socket_service(struct libwebsocket_context *context, struct libwe
 			if (len < 0)
 				goto bail3;
 
-			libwebsocket_parse(wsi, c);
+			if (libwebsocket_parse(wsi, c)) {
+				/* problems */
+				goto bail3;
+			}
 		}
 
 		/*
diff --git a/lib/handshake.c b/lib/handshake.c
index 7cb2799e..763aa4d7 100644
--- a/lib/handshake.c
+++ b/lib/handshake.c
@@ -88,8 +88,10 @@ libwebsocket_read(struct libwebsocket_context *context,
 		case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
 		case LWS_CONNMODE_WS_CLIENT:
 			for (n = 0; n < len; n++)
-				libwebsocket_client_rx_sm(wsi, *buf++);
-
+				if (libwebsocket_client_rx_sm(wsi, *buf++)) {
+					lwsl_info("libwebsocket_client_rx_sm failed\n");
+					goto bail;
+				}
 			return 0;
 		default:
 			break;
@@ -99,13 +101,14 @@ libwebsocket_read(struct libwebsocket_context *context,
 		/* LWS_CONNMODE_WS_SERVING */
 
 		for (n = 0; n < len; n++)
-			libwebsocket_parse(wsi, *buf++);
+			if (libwebsocket_parse(wsi, *buf++)) {
+				lwsl_info("libwebsocket_parse failed\n");
+				goto bail;
+			}
 
 		if (wsi->u.hdr.parser_state != WSI_PARSING_COMPLETE)
 			break;
 
-		lwsl_parser("seem to be serving, mode is %d\n", wsi->mode);
-
 		lwsl_parser("libwebsocket_parse sees parsing complete\n");
 
 		/* is this websocket protocol or normal http 1.0? */
@@ -115,9 +118,10 @@ libwebsocket_read(struct libwebsocket_context *context,
 			wsi->state = WSI_STATE_HTTP;
 			if (wsi->protocol->callback)
 				if (wsi->protocol->callback(context, wsi,
-								LWS_CALLBACK_HTTP, wsi->user_space,
-								wsi->utf8_token[WSI_TOKEN_GET_URI].token,
-								wsi->utf8_token[WSI_TOKEN_GET_URI].token_len)) {
+						LWS_CALLBACK_HTTP,
+						wsi->user_space,
+						wsi->utf8_token[WSI_TOKEN_GET_URI].token,
+						wsi->utf8_token[WSI_TOKEN_GET_URI].token_len)) {
 					lwsl_info("LWS_CALLBACK_HTTP wanted to close\n");
 					goto bail;
 				}