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

The sem_wait() call was just a bad idea after-all

The sem_wait() call from vdd_read() that was fixed in the previous commit to this file was a bad idea to begin with:
There is (often) not a 1:1 ratio of bytes in the receive ring buffer and the semaphore count, so we'd often halt here waiting for the semaphore to be signaled even though there were still characters in the receive buffer. This caused (new) stalls/hangs in keyboard input in DOS door games. We didn't see this previously because the sem_wait() call just didn't work (wrong semaphore pointer value).

Now, call sem_trywait_block() in vdd_read(), but only if the RingBufRead() returned 0 (no bytes read) and even then, only block/wait for a maximum of 30 seconds (same as X00 FOSSIL driver). This blocking behavior is specified for FOSSIL function 02h (Get received character with wait) and would not have worked previous to the previous "fix", so now we have that corrected behavior too. The FTSC spec says the wait is indefinite, but I think a 30 second timeout (ala X00) is more reasonable.

Log the git brach/hash instead of the old CVS revision.

GetMailSlotInfo() apparently always fails on Windows 7 with error 87 (even using Microsoft's own sample code), so lower the log message severity of that failure from ERR to DEBUG. Apparently this is pretty harmless anyway as nothing really needs the write-mailslot status. <shrug>
parent d8cbf926
No related branches found
No related tags found
No related merge requests found
/* sbbsexec.c */
/* Synchronet Windows NT/2000 VDD for FOSSIL and DOS I/O Interrupts */
/* $Id: sbbsexec.c,v 1.41 2018/07/24 01:11:08 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -45,11 +41,14 @@
#include "dirwrap.h"
#include "threadwrap.h"
#include "ini_file.h"
#include "git_branch.h"
#include "git_hash.h"
#define INI_FILENAME "sbbsexec.ini"
#define RINGBUF_SIZE_IN 10000
#define DEFAULT_MAX_MSG_SIZE 4000
#define LINEAR_RX_BUFLEN 10000
#define READ_TIMEOUT (30 * 1000) // X00REF.DOC "the timeout value is set to 30 seconds"
/* UART Parameters and virtual registers */
WORD uart_io_base = UART_COM1_IO_BASE; /* COM1 */
......@@ -80,7 +79,6 @@ HANDLE wrslot=INVALID_HANDLE_VALUE;
RingBuf rdbuf;
str_list_t ini;
char ini_fname[MAX_PATH+1];
char revision[16];
void lputs(int level, char* msg)
{
......@@ -255,10 +253,14 @@ void _cdecl input_thread(void* arg)
unsigned vdd_read(BYTE* p, unsigned count)
{
sem_wait(&rdbuf.sem);
count=RingBufRead(&rdbuf,p,count);
if(count==0)
lprintf(LOG_ERR,"!VDD_READ: RingBufRead read 0");
if(count==0) {
lprintf(LOG_ERR,"!VDD_READ: RingBufRead read 0, waiting");
if(sem_trywait_block(&rdbuf.sem, READ_TIMEOUT) != 0)
lprintf(LOG_ERR,"!VDD_READ: rdbuf sem timeout");
count = RingBufRead(&rdbuf,p,count);
lprintf(LOG_ERR,"!VDD_READ: RingBufRead read 0 (after wait)");
}
return(count);
}
......@@ -481,10 +483,8 @@ __declspec(dllexport) void __cdecl VDDDispatch(void)
case VDD_OPEN:
sscanf("$Revision: 1.41 $", "%*s %s", revision);
lprintf(LOG_INFO,"Synchronet Virtual Device Driver, rev %s %s %s"
,revision, __DATE__, __TIME__);
lprintf(LOG_INFO,"Synchronet Virtual Device Driver, %s/%s %s %s"
,GIT_BRANCH, GIT_HASH, __DATE__, __TIME__);
#if 0
sprintf(str,"sbbsexec%d.log",node_num);
fp=fopen(str,"wb");
......@@ -668,7 +668,8 @@ __declspec(dllexport) void __cdecl VDDDispatch(void)
&msgs, /* address of number of messages */
NULL /* address of read time-out */
)) {
lprintf(LOG_ERR,"!VDD_STATUS: GetMailSlotInfo(%p) failed, error %u (msgs=%u, inbuf_full=%u, inbuf_size=%u)"
// Known to fail with error 87 (The Parameter is Incorrect) on Windows 7 <shrug>
lprintf(LOG_DEBUG,"!VDD_STATUS: GetMailSlotInfo(%p) failed, error %u (msgs=%u, inbuf_full=%u, inbuf_size=%u)"
,wrslot
,GetLastError(), msgs, status->inbuf_full, status->inbuf_size);
status->outbuf_full=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment