mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-19 19:33:38 +08:00
Update TLS/TLCP shutdown
This commit is contained in:
@@ -70,6 +70,34 @@ static int do_handshake_select(TLS_CONNECT *conn)
|
||||
}
|
||||
}
|
||||
|
||||
static int do_shutdown_select(TLS_CONNECT *conn)
|
||||
{
|
||||
int ret;
|
||||
fd_set rfds;
|
||||
fd_set wfds;
|
||||
|
||||
for (;;) {
|
||||
ret = tls_shutdown(conn);
|
||||
if (ret == 1) {
|
||||
return 1;
|
||||
}
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
if (ret == TLS_ERROR_RECV_AGAIN) {
|
||||
FD_SET(conn->sock, &rfds);
|
||||
} else if (ret == TLS_ERROR_SEND_AGAIN) {
|
||||
FD_SET(conn->sock, &wfds);
|
||||
} else {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (select((int)(conn->sock + 1), &rfds, &wfds, NULL, NULL) < 0) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *http_get =
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"Hostname: aaa\r\n"
|
||||
@@ -725,6 +753,10 @@ bad:
|
||||
if ((ret = tls_recv(&conn, (uint8_t *)buf, sizeof(buf), &len)) != 1) {
|
||||
if (ret == TLS_ERROR_SEND_AGAIN || ret == TLS_ERROR_RECV_AGAIN) {
|
||||
continue;
|
||||
} else if (ret == 0) {
|
||||
do_shutdown_select(&conn);
|
||||
ret = 0;
|
||||
goto end;
|
||||
} else {
|
||||
error_print();
|
||||
goto end;
|
||||
@@ -742,9 +774,9 @@ bad:
|
||||
|
||||
if (!fgets(send_buf, sizeof(send_buf), stdin)) {
|
||||
if (feof(stdin)) {
|
||||
error_print();
|
||||
fprintf(stderr, "client shutdown\n");
|
||||
tls_shutdown(&conn);
|
||||
do_shutdown_select(&conn);
|
||||
ret = 0;
|
||||
goto end;
|
||||
} else {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user