Skip to content
Snippets Groups Projects
Commit d541b82c authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Call shutdown() when errors are detected...

Should force other threads to pay attention even if they're stuck
in select or something.
parent 269875be
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ rlogin_input_thread(void *args) ...@@ -44,6 +44,7 @@ rlogin_input_thread(void *args)
break; break;
} }
conn_api.terminate = true; conn_api.terminate = true;
shutdown(rlogin_sock, SHUT_RDWR);
conn_api.input_thread_running = 2; conn_api.input_thread_running = 2;
} }
...@@ -86,6 +87,7 @@ rlogin_output_thread(void *args) ...@@ -86,6 +87,7 @@ rlogin_output_thread(void *args)
break; break;
} }
conn_api.terminate = true; conn_api.terminate = true;
shutdown(rlogin_sock, SHUT_RDWR);
conn_api.output_thread_running = 2; conn_api.output_thread_running = 2;
} }
......
...@@ -60,8 +60,10 @@ static int ...@@ -60,8 +60,10 @@ static int
FlushData(CRYPT_SESSION sess) FlushData(CRYPT_SESSION sess)
{ {
int ret = cryptFlushData(sess); int ret = cryptFlushData(sess);
if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(ssh_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -71,8 +73,10 @@ PopData(CRYPT_HANDLE e, void *buf, int len, int *copied) ...@@ -71,8 +73,10 @@ PopData(CRYPT_HANDLE e, void *buf, int len, int *copied)
cryptSetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 0); cryptSetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 0);
int ret = cryptPopData(e, buf, len, copied); int ret = cryptPopData(e, buf, len, copied);
cryptSetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 30); cryptSetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 30);
if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(ssh_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -80,8 +84,10 @@ static int ...@@ -80,8 +84,10 @@ static int
PushData(CRYPT_HANDLE e, void *buf, int len, int *copied) PushData(CRYPT_HANDLE e, void *buf, int len, int *copied)
{ {
int ret = cryptPushData(e, buf, len, copied); int ret = cryptPushData(e, buf, len, copied);
if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_WRITE) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_WRITE) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(ssh_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -327,6 +333,7 @@ ssh_input_thread(void *args) ...@@ -327,6 +333,7 @@ ssh_input_thread(void *args)
pthread_mutex_unlock(&ssh_mutex); pthread_mutex_unlock(&ssh_mutex);
} }
conn_api.terminate = true; conn_api.terminate = true;
shutdown(ssh_sock, SHUT_RDWR);
conn_api.input_thread_running = 2; conn_api.input_thread_running = 2;
} }
...@@ -382,6 +389,7 @@ ssh_output_thread(void *args) ...@@ -382,6 +389,7 @@ ssh_output_thread(void *args)
} }
} }
conn_api.terminate = true; conn_api.terminate = true;
shutdown(ssh_sock, SHUT_RDWR);
conn_api.output_thread_running = 2; conn_api.output_thread_running = 2;
} }
...@@ -680,6 +688,10 @@ add_public_key(void *vpriv) ...@@ -680,6 +688,10 @@ add_public_key(void *vpriv)
static void static void
error_popup(struct bbslist *bbs, const char *blurb, int status) error_popup(struct bbslist *bbs, const char *blurb, int status)
{ {
if (ssh_sock != INVALID_SOCKET) {
closesocket(ssh_sock);
ssh_sock = INVALID_SOCKET;
}
if (!bbs->hidepopups) if (!bbs->hidepopups)
cryptlib_error_message(status, blurb); cryptlib_error_message(status, blurb);
conn_api.terminate = true; conn_api.terminate = true;
...@@ -711,6 +723,7 @@ ssh_connect(struct bbslist *bbs) ...@@ -711,6 +723,7 @@ ssh_connect(struct bbslist *bbs)
pthread_mutex_lock(&ssh_mutex); pthread_mutex_lock(&ssh_mutex);
ssh_channel = -1; ssh_channel = -1;
sftp_channel = -1; sftp_channel = -1;
ssh_socket = INVALID_SOCKET;
pthread_mutex_unlock(&ssh_mutex); pthread_mutex_unlock(&ssh_mutex);
pthread_mutex_init(&ssh_tx_mutex, NULL); pthread_mutex_init(&ssh_tx_mutex, NULL);
......
...@@ -24,8 +24,10 @@ static int ...@@ -24,8 +24,10 @@ static int
FlushData(CRYPT_SESSION sess) FlushData(CRYPT_SESSION sess)
{ {
int ret = cryptFlushData(sess); int ret = cryptFlushData(sess);
if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(telnets_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -33,8 +35,10 @@ static int ...@@ -33,8 +35,10 @@ static int
PopData(CRYPT_HANDLE e, void *buf, int len, int *copied) PopData(CRYPT_HANDLE e, void *buf, int len, int *copied)
{ {
int ret = cryptPopData(e, buf, len, copied); int ret = cryptPopData(e, buf, len, copied);
if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_READ) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(telnets_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -42,8 +46,10 @@ static int ...@@ -42,8 +46,10 @@ static int
PushData(CRYPT_HANDLE e, void *buf, int len, int *copied) PushData(CRYPT_HANDLE e, void *buf, int len, int *copied)
{ {
int ret = cryptPushData(e, buf, len, copied); int ret = cryptPushData(e, buf, len, copied);
if (ret == CRYPT_ERROR_COMPLETE) if (ret == CRYPT_ERROR_COMPLETE || ret == CRYPT_ERROR_WRITE) {
conn_api.terminate = true; conn_api.terminate = true;
shutdown(telnets_sock, SHUT_RDWR);
}
return ret; return ret;
} }
...@@ -88,6 +94,7 @@ telnets_input_thread(void *args) ...@@ -88,6 +94,7 @@ telnets_input_thread(void *args)
} }
} }
} }
shutdown(telnets_sock, SHUT_RDWR);
conn_api.input_thread_running = 2; conn_api.input_thread_running = 2;
} }
void void
...@@ -131,6 +138,7 @@ telnets_output_thread(void *args) ...@@ -131,6 +138,7 @@ telnets_output_thread(void *args)
pthread_mutex_unlock(&(conn_outbuf.mutex)); pthread_mutex_unlock(&(conn_outbuf.mutex));
} }
} }
shutdown(telnets_sock, SHUT_RDWR);
conn_api.output_thread_running = 2; conn_api.output_thread_running = 2;
} }
......
...@@ -4224,6 +4224,7 @@ doterm(struct bbslist *bbs) ...@@ -4224,6 +4224,7 @@ doterm(struct bbslist *bbs)
scrollback_lines = cterm->backpos; scrollback_lines = cterm->backpos;
cterm_end(cterm, 0); cterm_end(cterm, 0);
cterm = NULL; cterm = NULL;
// TODO: Do this before the popup to avoid being rude...
conn_close(); conn_close();
hidemouse(); hidemouse();
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment