提交 61e22e8b authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-6476 --resolve

上级 25c9b619
...@@ -318,17 +318,26 @@ int ws_handshake(wsh_t *wsh) ...@@ -318,17 +318,26 @@ int ws_handshake(wsh_t *wsh)
ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes) ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
{ {
ssize_t r; ssize_t r;
int x = 0; int err = 0;
if (wsh->ssl) { if (wsh->ssl) {
do { do {
r = SSL_read(wsh->ssl, data, bytes); r = SSL_read(wsh->ssl, data, bytes);
#ifndef _MSC_VER #ifndef _MSC_VER
if (x++) usleep(10000); if (wsh->x++) usleep(10000);
#else #else
if (x++) Sleep(10); if (wsh->x++) Sleep(10);
#endif #endif
} while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ && x < 100); if (r == -1) {
err = SSL_get_error(wsh->ssl, r);
if (wsh->handshake && err == SSL_ERROR_WANT_READ) {
r = -2;
goto end;
}
}
} while (r == -1 && err == SSL_ERROR_WANT_READ && wsh->x < 100);
goto end; goto end;
} }
...@@ -336,13 +345,13 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes) ...@@ -336,13 +345,13 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
do { do {
r = recv(wsh->sock, data, bytes, 0); r = recv(wsh->sock, data, bytes, 0);
#ifndef _MSC_VER #ifndef _MSC_VER
if (x++) usleep(10000); if (wsh->x++) usleep(10000);
#else #else
if (x++) Sleep(10); if (wsh->x++) Sleep(10);
#endif #endif
} while (r == -1 && xp_is_blocking(xp_errno()) && x < 100); } while (r == -1 && xp_is_blocking(xp_errno()) && wsh->x < 100);
if (x >= 100) { if (wsh->x >= 100) {
r = -1; r = -1;
} }
...@@ -352,6 +361,10 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes) ...@@ -352,6 +361,10 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
*((char *)data + r) = '\0'; *((char *)data + r) = '\0';
} }
if (r >= 0) {
wsh->x = 0;
}
return r; return r;
} }
...@@ -621,6 +634,9 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data) ...@@ -621,6 +634,9 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
} }
if ((wsh->datalen = ws_raw_read(wsh, wsh->buffer, 9)) < 0) { if ((wsh->datalen = ws_raw_read(wsh, wsh->buffer, 9)) < 0) {
if (wsh->datalen == -2) {
return -2;
}
return ws_close(wsh, WS_PROTO_ERR); return ws_close(wsh, WS_PROTO_ERR);
} }
......
...@@ -88,6 +88,7 @@ typedef struct wsh_s { ...@@ -88,6 +88,7 @@ typedef struct wsh_s {
int sanity; int sanity;
int secure_established; int secure_established;
int logical_established; int logical_established;
int x;
} wsh_t; } wsh_t;
ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc); ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
......
...@@ -13,30 +13,40 @@ ...@@ -13,30 +13,40 @@
#include <sys/socket.h> #include <sys/socket.h>
#else #else
#pragma warning(disable:4996) #pragma warning(disable:4996)
#define snprintf _snprintf
#endif #endif
#include <string.h> #include <string.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
//#include "sha1.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <../lib/abyss/src/session.h>
#include <../lib/abyss/src/conn.h>
typedef TSession ws_tsession_t; #ifdef _MSC_VER
typedef int issize_t; #define strncasecmp _strnicmp
#define snprintf _snprintf
#ifdef _WIN64
#define WS_SSIZE_T __int64
#elif _MSC_VER >= 1400
#define WS_SSIZE_T __int32 __w64
#else
#define WS_SSIZE_T __int32
#endif
typedef WS_SSIZE_T ssize_t;
#endif
struct globals_s { struct ws_globals_s {
const SSL_METHOD *ssl_method; const SSL_METHOD *ssl_method;
SSL_CTX *ssl_ctx; SSL_CTX *ssl_ctx;
char cert[512]; char cert[512];
char key[512]; char key[512];
}; };
// extern struct globals_s globals; extern struct ws_globals_s ws_globals;
typedef int ws_socket_t; typedef int ws_socket_t;
#define ws_sock_invalid -1 #define ws_sock_invalid -1
...@@ -59,36 +69,44 @@ typedef enum { ...@@ -59,36 +69,44 @@ typedef enum {
} ws_opcode_t; } ws_opcode_t;
typedef struct wsh_s { typedef struct wsh_s {
ws_tsession_t *tsession; ws_socket_t sock;
char buffer[65536]; char buffer[65536];
char wbuffer[65536]; char wbuffer[65536];
size_t buflen; size_t buflen;
issize_t datalen; ssize_t datalen;
issize_t wdatalen; ssize_t wdatalen;
char *payload; char *payload;
issize_t plen; ssize_t plen;
issize_t rplen; ssize_t rplen;
SSL *ssl; SSL *ssl;
int handshake; int handshake;
uint8_t down; uint8_t down;
int secure; int secure;
uint8_t close_sock; uint8_t close_sock;
SSL_CTX *ssl_ctx;
int block;
int sanity;
int secure_established;
int logical_established;
int x;
} wsh_t; } wsh_t;
issize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc); ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
issize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes); ssize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes);
issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes); ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes);
issize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes); ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data); ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
issize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes); ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
wsh_t * ws_init(ws_tsession_t *tsession); int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block);
issize_t ws_close(wsh_t *wsh, int16_t reason); ssize_t ws_close(wsh_t *wsh, int16_t reason);
void ws_destroy(wsh_t *wsh); void ws_destroy(wsh_t *wsh);
void init_ssl(void); void init_ssl(void);
void deinit_ssl(void); void deinit_ssl(void);
int ws_handshake_kvp(wsh_t *wsh, char *key, char *version, char *proto); int xp_errno(void);
int xp_is_blocking(int errcode);
#ifndef _MSC_VER #ifndef _MSC_VER
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论