--- sbbs/sbbs3/sbbsexec.c 2018/04/24 16:39:34 1.1.1.1 +++ sbbs/sbbs3/sbbsexec.c 2018/04/24 16:40:41 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet Windows NT/2000 VDD for FOSSIL and DOS I/O Interrupts */ -/* $Id: sbbsexec.c,v 1.1.1.1 2018/04/24 16:39:34 root Exp $ */ +/* $Id: sbbsexec.c,v 1.1.1.2 2018/04/24 16:40:41 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -41,34 +41,45 @@ #include "vdd_func.h" #include "ringbuf.h" -#define RINGBUF_SIZE_IN 10000 - +#define RINGBUF_SIZE_IN 10000 +#define DEFAULT_MAX_MSG_SIZE 4000 __declspec(dllexport) void __cdecl VDDDispatch(void) { char str[512]; char buf[5000]; DWORD count; + DWORD msgs; int retval; int node_num; BYTE* p; vdd_status_t* status; + static DWORD writes; + static DWORD bytes_written; + static DWORD reads; + static DWORD bytes_read; static DWORD inbuf_poll; static DWORD online_poll; static DWORD status_poll; - static HANDLE hungup_event; + static DWORD yields; + static HANDLE hungup_event=NULL; static HANDLE rdslot=INVALID_HANDLE_VALUE; static HANDLE wrslot=INVALID_HANDLE_VALUE; static RingBuf rdbuf; - static FILE* fp; +#if defined(_DEBUG) + static FILE* fp=NULL; +#endif + retval=0; node_num=getBH(); switch(getBL()) { case VDD_OPEN: +#if defined(_DEBUG) sprintf(str,"sbbsexec%d.log",node_num); fp=fopen(str,"wb"); +#endif sprintf(str,"\\\\.\\mailslot\\sbbsexec\\wr%d",node_num); rdslot=CreateMailslot(str @@ -76,9 +87,11 @@ __declspec(dllexport) void __cdecl VDDDi ,MAILSLOT_WAIT_FOREVER // Read timeout ,NULL); if(rdslot==INVALID_HANDLE_VALUE) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n" ,GetLastError(),str); +#endif retval=1; break; } @@ -92,9 +105,11 @@ __declspec(dllexport) void __cdecl VDDDi ,FILE_ATTRIBUTE_NORMAL ,(HANDLE) NULL); if(wrslot==INVALID_HANDLE_VALUE) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n" ,GetLastError(),str); +#endif retval=2; break; } @@ -110,9 +125,11 @@ __declspec(dllexport) void __cdecl VDDDi FALSE, // inherit flag str); // pointer to event-object name if(hungup_event==NULL) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n" ,GetLastError(),str); +#endif retval=4; break; } @@ -120,20 +137,26 @@ __declspec(dllexport) void __cdecl VDDDi status_poll=0; inbuf_poll=0; online_poll=0; + yields=0; retval=0; break; case VDD_CLOSE: +#if defined(_DEBUG) if(fp!=NULL) { - fprintf(fp,"VDD_CLOSE: rdbuf=%d " - "status_poll=%d inbuf_poll=%d online_poll=%d\r\n" - ,RingBufFull(&rdbuf),status_poll,inbuf_poll,online_poll); + fprintf(fp,"VDD_CLOSE: rdbuf=%u " + "status_poll=%u inbuf_poll=%u online_poll=%u yields=%u\r\n" + ,RingBufFull(&rdbuf),status_poll,inbuf_poll,online_poll,yields); + fprintf(fp," read=%u bytes (in %u calls)\r\n",bytes_read,reads); + fprintf(fp," wrote=%u bytes (in %u calls)\r\n",bytes_written,writes); fclose(fp); } +#endif CloseHandle(rdslot); CloseHandle(wrslot); - CloseHandle(hungup_event); + if(hungup_event!=NULL) + CloseHandle(hungup_event); RingBufDispose(&rdbuf); status_poll=0; retval=0; @@ -142,39 +165,54 @@ __declspec(dllexport) void __cdecl VDDDi case VDD_READ: count = getCX(); +#if defined(_DEBUG) if(count != 1 && fp!=NULL) fprintf(fp,"VDD_READ of %d\r\n",count); - +#endif p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI()) ,count,FALSE); if(RingBufFull(&rdbuf)) { retval=RingBufRead(&rdbuf,p,count); +#if defined(_DEBUG) if(retval==0 && fp!=NULL) fprintf(fp,"!VDD_READ: RingBufRead read 0\r\n"); +#endif + reads++; + bytes_read+=retval; break; } if(!ReadFile(rdslot,buf,sizeof(buf),&retval,NULL)) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_READ: ReadFile Error %d (size=%d)\r\n" ,GetLastError(),retval); +#endif retval=0; break; } if(retval==0) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_READ: ReadFile read 0\r\n"); +#endif break; } RingBufWrite(&rdbuf,buf,retval); retval=RingBufRead(&rdbuf,p,count); +#if defined(_DEBUG) if(retval==0 && fp!=NULL) fprintf(fp,"!VDD_READ: RingBufRead read 0 after write\r\n"); +#endif + reads++; + bytes_read+=retval; break; case VDD_PEEK: count = getCX(); +#if defined(_DEBUG) if(count != 1 && fp!=NULL) fprintf(fp,"VDD_PEEK of %d\r\n",count); +#endif p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI()) ,count,FALSE); @@ -183,15 +221,19 @@ __declspec(dllexport) void __cdecl VDDDi break; } if(!ReadFile(rdslot,buf,sizeof(buf),&retval,NULL)) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_PEEK: ReadFile Error %d\r\n" ,GetLastError()); +#endif retval=0; break; } if(retval==0) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_PEEK: ReadFile read 0\r\n"); +#endif break; } RingBufWrite(&rdbuf,buf,retval); @@ -200,17 +242,24 @@ __declspec(dllexport) void __cdecl VDDDi case VDD_WRITE: count = getCX(); +#if defined(_DEBUG) if(count != 1 && fp!=NULL) fprintf(fp,"VDD_WRITE of %d\r\n",count); +#endif p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI()) ,count,FALSE); // if(fp!=NULL) // fwrite(p,count,1,fp); if(!WriteFile(wrslot,p,count,&retval,NULL)) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_WRITE: WriteFile Error %d (size=%d)\r\n" ,GetLastError(),retval); +#endif retval=0; + } else { + writes++; + bytes_written+=retval; } break; @@ -219,8 +268,10 @@ __declspec(dllexport) void __cdecl VDDDi status_poll++; count = getCX(); if(count != sizeof(vdd_status_t)) { +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_STATUS: wrong size (%d!=%d)\r\n",count,sizeof(vdd_status_t)); +#endif retval=sizeof(vdd_status_t); break; } @@ -232,31 +283,32 @@ __declspec(dllexport) void __cdecl VDDDi rdslot, // mailslot handle &status->inbuf_size, // address of maximum message size &status->inbuf_full, // address of size of next message - NULL, // address of number of messages + &msgs, // address of number of messages NULL // address of read time-out )) { status->inbuf_full=0; - status->inbuf_size=4000; + status->inbuf_size=DEFAULT_MAX_MSG_SIZE; } if(status->inbuf_full==MAILSLOT_NO_MESSAGE) status->inbuf_full=0; + status->inbuf_full*=msgs; status->inbuf_full+=RingBufFull(&rdbuf); - /* OUTBUF FULL/SIZZE */ + /* OUTBUF FULL/SIZE */ if(!GetMailslotInfo( wrslot, // mailslot handle &status->outbuf_size, // address of maximum message size &status->outbuf_full, // address of size of next message - NULL, // address of number of messages + &msgs, // address of number of messages NULL // address of read time-out )) { status->outbuf_full=0; - status->outbuf_size=4000; + status->outbuf_size=DEFAULT_MAX_MSG_SIZE; } if(status->outbuf_full==MAILSLOT_NO_MESSAGE) status->outbuf_full=0; - + status->outbuf_full*=msgs; /* ONLINE */ if(WaitForSingleObject(hungup_event,0)==WAIT_OBJECT_0) @@ -269,29 +321,33 @@ __declspec(dllexport) void __cdecl VDDDi case VDD_INBUF_PURGE: +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_INBUF_PURGE: NOT IMPLEMENTED\r\n"); +#endif retval=0; break; case VDD_OUTBUF_PURGE: +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!VDD_OUTBUF_PURGE: NOT IMPLEMENTED\r\n"); +#endif retval=0; break; -#if 1 case VDD_INBUF_FULL: if(!GetMailslotInfo( rdslot, // mailslot handle NULL, // address of maximum message size &retval, // address of size of next message - &count, // address of number of messages + &msgs, // address of number of messages NULL // address of read time-out )) retval=0; if(retval==MAILSLOT_NO_MESSAGE) retval=0; + retval*=msgs; retval+=RingBufFull(&rdbuf); inbuf_poll++; break; @@ -304,7 +360,7 @@ __declspec(dllexport) void __cdecl VDDDi NULL, // address of number of messages NULL // address of read time-out )) - retval=4000; + retval=DEFAULT_MAX_MSG_SIZE; break; case VDD_OUTBUF_FULL: @@ -312,12 +368,13 @@ __declspec(dllexport) void __cdecl VDDDi wrslot, // mailslot handle NULL, // address of maximum message size &retval, // address of size of next message - NULL, // address of number of messages + &msgs, // address of number of messages NULL // address of read time-out )) retval=0; if(retval==MAILSLOT_NO_MESSAGE) retval=0; + retval*=msgs; break; case VDD_OUTBUF_SIZE: @@ -328,7 +385,7 @@ __declspec(dllexport) void __cdecl VDDDi NULL, // address of number of messages NULL // address of read time-out )) - retval=4000; + retval=DEFAULT_MAX_MSG_SIZE; break; case VDD_ONLINE: @@ -338,10 +395,17 @@ __declspec(dllexport) void __cdecl VDDDi retval=1; online_poll++; break; -#endif + + case VDD_YIELD: + Sleep(1); + yields++; + break; + default: +#if defined(_DEBUG) if(fp!=NULL) fprintf(fp,"!UNKNOWN VDD_OP: %d\r\n",getBL()); +#endif break; } setAX((WORD)retval);