Skip to content
Snippets Groups Projects
Commit 424dfe10 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Create/use sbbs_t::flush_output(timeout)

If client socket is connected, wait up to the specified timeout period (in ms)
for the output buffer to be emptied.

This is much preferred over blindly calling mswait() after sending some data
(e.g. a file) and possibly waiting much longer than necessary.
parent 221507a8
Branches
Tags
1 merge request!455Update branch with changes from master
Pipeline #6330 passed
...@@ -4132,7 +4132,7 @@ int sbbs_t::outcom(uchar ch) ...@@ -4132,7 +4132,7 @@ int sbbs_t::outcom(uchar ch)
break; break;
i++; i++;
if(i >= outcom_max_attempts) { /* timeout - beep flush outbuf */ if(i >= outcom_max_attempts) { /* timeout - beep flush outbuf */
lprintf(LOG_NOTICE, "%04d %s TIMEOUT after %d attempts with %d bytes in transmit buffer (flushing)" lprintf(LOG_NOTICE, "%04d %s TIMEOUT after %d attempts with %d bytes in transmit buffer (purging)"
,client_socket, __FUNCTION__, i, RingBufFull(&outbuf)); ,client_socket, __FUNCTION__, i, RingBufFull(&outbuf));
RingBufReInit(&outbuf); RingBufReInit(&outbuf);
_outcom(BEL); _outcom(BEL);
...@@ -4141,7 +4141,7 @@ int sbbs_t::outcom(uchar ch) ...@@ -4141,7 +4141,7 @@ int sbbs_t::outcom(uchar ch)
if(sys_status&SS_SYSPAGE) if(sys_status&SS_SYSPAGE)
sbbs_beep(i, OUTCOM_RETRY_DELAY); sbbs_beep(i, OUTCOM_RETRY_DELAY);
else else
mswait(OUTCOM_RETRY_DELAY); flush_output(OUTCOM_RETRY_DELAY);
} }
return 0; // Success return 0; // Success
} }
...@@ -5632,11 +5632,11 @@ NO_SSH: ...@@ -5632,11 +5632,11 @@ NO_SSH:
} }
if(sbbs->trashcan(host_name,"host", &trash)) { if(sbbs->trashcan(host_name,"host", &trash)) {
SSH_END(client_socket);
close_socket(client_socket);
char details[128]; char details[128];
lprintf(LOG_NOTICE,"%04d %s [%s] !CLIENT BLOCKED in host.can: %s %s" lprintf(LOG_NOTICE,"%04d %s [%s] !CLIENT BLOCKED in host.can: %s %s"
,client_socket, client.protocol, host_ip, host_name, trash_details(&trash, details, sizeof details)); ,client_socket, client.protocol, host_ip, host_name, trash_details(&trash, details, sizeof details));
SSH_END(client_socket);
close_socket(client_socket);
continue; continue;
} }
...@@ -5704,7 +5704,7 @@ NO_SSH: ...@@ -5704,7 +5704,7 @@ NO_SSH:
sbbs->putcom("\r\nSorry, all terminal nodes are in use or otherwise unavailable.\r\n"); sbbs->putcom("\r\nSorry, all terminal nodes are in use or otherwise unavailable.\r\n");
sbbs->putcom("Please try again later.\r\n"); sbbs->putcom("Please try again later.\r\n");
} }
mswait(3000); sbbs->flush_output(3000);
client_off(client_socket); client_off(client_socket);
SSH_END(client_socket); SSH_END(client_socket);
close_socket(client_socket); close_socket(client_socket);
...@@ -5777,7 +5777,7 @@ NO_SSH: ...@@ -5777,7 +5777,7 @@ NO_SSH:
sbbs->printfile(str,P_NOABORT); sbbs->printfile(str,P_NOABORT);
else else
sbbs->putcom("\r\nSorry, initialization failed. Try again later.\r\n"); sbbs->putcom("\r\nSorry, initialization failed. Try again later.\r\n");
mswait(3000); sbbs->flush_output(3000);
sbbs->getnodedat(new_node->cfg.node_num,&node,1); sbbs->getnodedat(new_node->cfg.node_num,&node,1);
node.status=NODE_WFC; node.status=NODE_WFC;
sbbs->putnodedat(new_node->cfg.node_num,&node); sbbs->putnodedat(new_node->cfg.node_num,&node);
......
...@@ -501,6 +501,7 @@ public: ...@@ -501,6 +501,7 @@ public:
RingBuf inbuf{}; RingBuf inbuf{};
RingBuf outbuf{}; RingBuf outbuf{};
bool WaitForOutbufEmpty(int timeout) { return WaitForEvent(outbuf.empty_event, timeout) == WAIT_OBJECT_0; } bool WaitForOutbufEmpty(int timeout) { return WaitForEvent(outbuf.empty_event, timeout) == WAIT_OBJECT_0; }
bool flush_output(int timeout) { return online && WaitForOutbufEmpty(timeout); }
HANDLE input_thread=nullptr; HANDLE input_thread=nullptr;
pthread_mutex_t input_thread_mutex; pthread_mutex_t input_thread_mutex;
bool input_thread_mutex_created = false; bool input_thread_mutex_created = false;
......
...@@ -965,7 +965,7 @@ bool sbbs_t::trashcan(const char *insearchof, const char *name, struct trash* tr ...@@ -965,7 +965,7 @@ bool sbbs_t::trashcan(const char *insearchof, const char *name, struct trash* tr
sprintf(str,"%sbad%s.msg",cfg.text_dir,name); sprintf(str,"%sbad%s.msg",cfg.text_dir,name);
if(fexistcase(str)) { if(fexistcase(str)) {
printfile(str,0); printfile(str,0);
mswait(500); // give time for tx buffer to clear before disconnect flush_output(500); // give time for tx buffer to clear before disconnect
} }
} }
return(result); return(result);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment