updated net skeleton

This commit is contained in:
Sergey Lyubka 2014-07-08 11:28:03 +01:00
parent b5704850db
commit b738fdbffa

View File

@ -713,6 +713,15 @@ int ns_hexdump(const void *buf, int len, char *dst, int dst_len) {
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) {
char buf[2048];
int n = 0;
@ -726,10 +735,7 @@ static void ns_read_from_socket(struct ns_connection *conn) {
#ifdef NS_ENABLE_SSL
if (ret == 0 && ok == 0 && conn->ssl != NULL) {
int res = SSL_connect(conn->ssl);
int ssl_err = SSL_get_error(conn->ssl, 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;
int ssl_err = ns_ssl_err(conn, res);
if (res == 1) {
conn->flags |= NSF_SSL_HANDSHAKE_DONE;
} else if (ssl_err == SSL_ERROR_WANT_READ ||
@ -760,12 +766,10 @@ static void ns_read_from_socket(struct ns_connection *conn) {
iobuf_append(&conn->recv_iobuf, buf, n);
ns_call(conn, NS_RECV, &n);
}
ns_ssl_err(conn, n);
} else {
int res = SSL_accept(conn->ssl);
int ssl_err = SSL_get_error(conn->ssl, 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;
int ssl_err = ns_ssl_err(conn, res);
if (res == 1) {
conn->flags |= NSF_SSL_HANDSHAKE_DONE;
} else if (ssl_err == SSL_ERROR_WANT_READ ||
@ -798,10 +802,9 @@ static void ns_write_to_socket(struct ns_connection *conn) {
#ifdef NS_ENABLE_SSL
if (conn->ssl != NULL) {
n = SSL_write(conn->ssl, io->buf, io->len);
if (n < 0) {
int ssl_err = SSL_get_error(conn->ssl, n);
DBG(("%p %d %d", conn, n, ssl_err));
if (ssl_err == 2 || ssl_err == 3) {
if (n <= 0) {
int ssl_err = ns_ssl_err(conn, n);
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
return; // Call us again
} else {
conn->flags |= NSF_CLOSE_IMMEDIATELY;