提交 a26ab6e3 authored 作者: Anthony Minessale's avatar Anthony Minessale

fix ssl connect race

上级 5fefae03
Wed Jun 26 12:43:51 EDT 2013 Wed Jun 26 23:10:11 EDT 2013
...@@ -379,7 +379,8 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c ...@@ -379,7 +379,8 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c
if (wsh->secure) { if (wsh->secure) {
int code; int code;
int sanity = 500;
wsh->ssl = SSL_new(ssl_ctx); wsh->ssl = SSL_new(ssl_ctx);
assert(wsh->ssl); assert(wsh->ssl);
...@@ -387,8 +388,32 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c ...@@ -387,8 +388,32 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c
do { do {
code = SSL_accept(wsh->ssl); code = SSL_accept(wsh->ssl);
} while (code == -1 && SSL_get_error(wsh->ssl, code) == SSL_ERROR_WANT_READ);
if (code == 1) {
break;
}
if (code == 0) {
return -1;
}
if (code < 0) {
if (code == -1 && SSL_get_error(wsh->ssl, code) != SSL_ERROR_WANT_READ) {
return -1;
}
}
#ifndef _MSC_VER
usleep(10000);
#else
Sleep(10);
#endif
} while (--sanity > 0);
if (!sanity) {
return -1;
}
} }
while (!wsh->down && !wsh->handshake) { while (!wsh->down && !wsh->handshake) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论