Commit 13648112 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Don't close externally opened/passed socket descriptors

Set sbbs_hungup event state correctly based on initial online state (i.e. FALSE if already connected/online).

Allow BusyNotice (string) to be configurable via .ini file.
parent 8dbbe0a3
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define TITLE "Synchronet Virtual DOS Modem for Windows" #define TITLE "Synchronet Virtual DOS Modem for Windows"
#define VERSION "0.0" #define VERSION "0.0"
bool external_socket;
SOCKET sock = INVALID_SOCKET; SOCKET sock = INVALID_SOCKET;
SOCKET listening_sock = INVALID_SOCKET; SOCKET listening_sock = INVALID_SOCKET;
HANDLE hangup_event = INVALID_HANDLE_VALUE; // e.g. program drops DTR HANDLE hangup_event = INVALID_HANDLE_VALUE; // e.g. program drops DTR
...@@ -71,6 +72,7 @@ struct { ...@@ -71,6 +72,7 @@ struct {
bool terminate_on_disconnect; bool terminate_on_disconnect;
ulong data_rate; ulong data_rate;
bool server_echo; bool server_echo;
char busy_notice[INI_MAX_VALUE_LEN];
enum { enum {
ADDRESS_FAMILY_UNSPEC ADDRESS_FAMILY_UNSPEC
,ADDRESS_FAMILY_INET ,ADDRESS_FAMILY_INET
...@@ -242,8 +244,10 @@ char* connected(struct modem* modem) ...@@ -242,8 +244,10 @@ char* connected(struct modem* modem)
void disconnect(struct modem* modem) void disconnect(struct modem* modem)
{ {
modem->online = false; modem->online = false;
shutdown(sock, SD_SEND); if(!external_socket) {
closesocket(sock); shutdown(sock, SD_SEND);
closesocket(sock);
}
sock = INVALID_SOCKET; sock = INVALID_SOCKET;
SetEvent(hungup_event); SetEvent(hungup_event);
SetEvent(carrier_event); SetEvent(carrier_event);
...@@ -946,8 +950,7 @@ void listen_thread(void* arg) ...@@ -946,8 +950,7 @@ void listen_thread(void* arg)
socklen_t addrlen = sizeof(addr); socklen_t addrlen = sizeof(addr);
SOCKET newsock = accept(listening_sock, (SOCKADDR*)&addr, &addrlen); SOCKET newsock = accept(listening_sock, (SOCKADDR*)&addr, &addrlen);
if(newsock != INVALID_SOCKET) { if(newsock != INVALID_SOCKET) {
char* busy_notice = "\r\nSorry, not available right now\r\n"; send(newsock, cfg.busy_notice, strlen(cfg.busy_notice), /* flags: */0);
send(newsock, busy_notice, strlen(busy_notice), /* flags: */0);
shutdown(newsock, SD_SEND); shutdown(newsock, SD_SEND);
closesocket(newsock); closesocket(newsock);
} }
...@@ -976,6 +979,10 @@ bool read_ini(const char* ini_fname) ...@@ -976,6 +979,10 @@ bool read_ini(const char* ini_fname)
cfg.server_echo = iniGetBool(ini, ROOT_SECTION, "ServerEcho", cfg.server_echo); cfg.server_echo = iniGetBool(ini, ROOT_SECTION, "ServerEcho", cfg.server_echo);
cfg.data_rate = iniGetLongInt(ini, ROOT_SECTION, "Rate", cfg.data_rate); cfg.data_rate = iniGetLongInt(ini, ROOT_SECTION, "Rate", cfg.data_rate);
cfg.address_family = iniGetEnum(ini, ROOT_SECTION, "AddressFamily", addrFamilyNames, cfg.address_family); cfg.address_family = iniGetEnum(ini, ROOT_SECTION, "AddressFamily", addrFamilyNames, cfg.address_family);
char value[INI_MAX_VALUE_LEN];
const char* p = iniGetString(ini, ROOT_SECTION, "BusyNotice", NULL, value);
if(p != NULL)
SAFECOPY(cfg.busy_notice, p);
return true; return true;
} }
...@@ -1004,6 +1011,7 @@ int main(int argc, char** argv) ...@@ -1004,6 +1011,7 @@ int main(int argc, char** argv)
cfg.server_echo = TRUE; cfg.server_echo = TRUE;
cfg.port = IPPORT_TELNET; cfg.port = IPPORT_TELNET;
cfg.address_family = ADDRESS_FAMILY_INET; cfg.address_family = ADDRESS_FAMILY_INET;
SAFECOPY(cfg.busy_notice, "\r\nSorry, not available right now\r\n");
ini = strListInit(); ini = strListInit();
GetModuleFileName(NULL, ini_fname, sizeof(ini_fname) - 1); GetModuleFileName(NULL, ini_fname, sizeof(ini_fname) - 1);
...@@ -1060,6 +1068,7 @@ int main(int argc, char** argv) ...@@ -1060,6 +1068,7 @@ int main(int argc, char** argv)
break; break;
case 'h': case 'h':
sock = strtoul(arg + 1, NULL, 10); sock = strtoul(arg + 1, NULL, 10);
external_socket = true;
break; break;
case 'r': case 'r':
cfg.data_rate = strtoul(arg + 1, NULL, 10); cfg.data_rate = strtoul(arg + 1, NULL, 10);
...@@ -1169,7 +1178,7 @@ int main(int argc, char** argv) ...@@ -1169,7 +1178,7 @@ int main(int argc, char** argv)
hungup_event = CreateEvent( hungup_event = CreateEvent(
NULL // pointer to security attributes NULL // pointer to security attributes
,TRUE // flag for manual-reset event ,TRUE // flag for manual-reset event
,TRUE // flag for initial state (DCD = low) ,!modem.online // flag for initial state
,path // pointer to event-object name ,path // pointer to event-object name
); );
if(hungup_event == NULL) { if(hungup_event == NULL) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment