Commit b738fdbf authored by Sergey Lyubka's avatar Sergey Lyubka

updated net skeleton

parent b5704850
...@@ -713,6 +713,15 @@ int ns_hexdump(const void *buf, int len, char *dst, int dst_len) { ...@@ -713,6 +713,15 @@ int ns_hexdump(const void *buf, int len, char *dst, int dst_len) {
return n; return n;
} }
#ifdef NS_ENABLE_SSL
static int ns_ssl_err(struct ns_connection *conn, int res) {
int ssl_err = SSL_get_error(conn->ssl, res);
if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
return ssl_err;
}
#endif
static void ns_read_from_socket(struct ns_connection *conn) { static void ns_read_from_socket(struct ns_connection *conn) {
char buf[2048]; char buf[2048];
int n = 0; int n = 0;
...@@ -726,10 +735,7 @@ static void ns_read_from_socket(struct ns_connection *conn) { ...@@ -726,10 +735,7 @@ static void ns_read_from_socket(struct ns_connection *conn) {
#ifdef NS_ENABLE_SSL #ifdef NS_ENABLE_SSL
if (ret == 0 && ok == 0 && conn->ssl != NULL) { if (ret == 0 && ok == 0 && conn->ssl != NULL) {
int res = SSL_connect(conn->ssl); int res = SSL_connect(conn->ssl);
int ssl_err = SSL_get_error(conn->ssl, res); int ssl_err = ns_ssl_err(conn, res);
DBG(("%p %d wres %d %d", conn, conn->flags, res, ssl_err));
if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
if (res == 1) { if (res == 1) {
conn->flags |= NSF_SSL_HANDSHAKE_DONE; conn->flags |= NSF_SSL_HANDSHAKE_DONE;
} else if (ssl_err == SSL_ERROR_WANT_READ || } else if (ssl_err == SSL_ERROR_WANT_READ ||
...@@ -760,12 +766,10 @@ static void ns_read_from_socket(struct ns_connection *conn) { ...@@ -760,12 +766,10 @@ static void ns_read_from_socket(struct ns_connection *conn) {
iobuf_append(&conn->recv_iobuf, buf, n); iobuf_append(&conn->recv_iobuf, buf, n);
ns_call(conn, NS_RECV, &n); ns_call(conn, NS_RECV, &n);
} }
ns_ssl_err(conn, n);
} else { } else {
int res = SSL_accept(conn->ssl); int res = SSL_accept(conn->ssl);
int ssl_err = SSL_get_error(conn->ssl, res); int ssl_err = ns_ssl_err(conn, res);
DBG(("%p %d rres %d %d", conn, conn->flags, res, ssl_err));
if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
if (res == 1) { if (res == 1) {
conn->flags |= NSF_SSL_HANDSHAKE_DONE; conn->flags |= NSF_SSL_HANDSHAKE_DONE;
} else if (ssl_err == SSL_ERROR_WANT_READ || } else if (ssl_err == SSL_ERROR_WANT_READ ||
...@@ -798,10 +802,9 @@ static void ns_write_to_socket(struct ns_connection *conn) { ...@@ -798,10 +802,9 @@ static void ns_write_to_socket(struct ns_connection *conn) {
#ifdef NS_ENABLE_SSL #ifdef NS_ENABLE_SSL
if (conn->ssl != NULL) { if (conn->ssl != NULL) {
n = SSL_write(conn->ssl, io->buf, io->len); n = SSL_write(conn->ssl, io->buf, io->len);
if (n < 0) { if (n <= 0) {
int ssl_err = SSL_get_error(conn->ssl, n); int ssl_err = ns_ssl_err(conn, n);
DBG(("%p %d %d", conn, n, ssl_err)); if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
if (ssl_err == 2 || ssl_err == 3) {
return; // Call us again return; // Call us again
} else { } else {
conn->flags |= NSF_CLOSE_IMMEDIATELY; conn->flags |= NSF_CLOSE_IMMEDIATELY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment