sync ws code

This commit is contained in:
Anthony Minessale 2015-01-06 20:12:09 -06:00
parent b170e9e9f5
commit 6c1bc0e2f6
2 changed files with 15 additions and 4 deletions

View File

@ -309,7 +309,7 @@ int ws_handshake(wsh_t *wsh)
"%s\r\n",
b64,
proto_buf);
respond[511] = 0;
ws_raw_write(wsh, respond, strlen(respond));
wsh->handshake = 1;
@ -322,6 +322,7 @@ int ws_handshake(wsh_t *wsh)
snprintf(respond, sizeof(respond), "HTTP/1.1 400 Bad Request\r\n"
"Sec-WebSocket-Version: 13\r\n\r\n");
respond[511] = 0;
ws_raw_write(wsh, respond, strlen(respond));
@ -399,7 +400,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block)
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
{
size_t r;
ssize_t r;
int sanity = 2000;
int ssl_err = 0;
@ -656,7 +657,11 @@ ssize_t ws_close(wsh_t *wsh, int16_t reason)
restore_socket(wsh->sock);
if (wsh->close_sock && wsh->sock != ws_sock_invalid) {
#ifndef WIN32
close(wsh->sock);
#else
closesocket(wsh->sock);
#endif
}
wsh->sock = ws_sock_invalid;

View File

@ -11,11 +11,11 @@
#include <arpa/inet.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <unistd.h>
#else
#pragma warning(disable:4996)
#endif
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
@ -26,7 +26,9 @@
#include <openssl/ssl.h>
#ifdef _MSC_VER
#ifndef strncasecmp
#define strncasecmp _strnicmp
#endif
#define snprintf _snprintf
#ifdef _WIN64
#define WS_SSIZE_T __int64
@ -48,8 +50,12 @@ struct ws_globals_s {
extern struct ws_globals_s ws_globals;
#ifndef WIN32
typedef int ws_socket_t;
#define ws_sock_invalid -1
#else
typedef SOCKET ws_socket_t;
#endif
#define ws_sock_invalid (ws_socket_t)-1
typedef enum {