Make the emulated modem recognise dropped connection and act accordingly
This commit is contained in:
parent
f8b27b8465
commit
30759524bb
54
emulator.pas
54
emulator.pas
|
@ -11,7 +11,7 @@ program Emulator;
|
||||||
{$define status}
|
{$define status}
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
uses SysUtils, Crt{$ifdef modem}, Sockets{$endif}{$ifdef status}, BaseUnix{$endif};
|
uses SysUtils, Crt{$ifdef modem}, BaseUnix, Sockets{$endif}{$ifdef status}{$ifndef modem}, BaseUnix{$endif}{$endif};
|
||||||
|
|
||||||
type
|
type
|
||||||
{$ifdef tape}
|
{$ifdef tape}
|
||||||
|
@ -80,11 +80,17 @@ var
|
||||||
ModemState: file of Connection; //File storing the state of the modem
|
ModemState: file of Connection; //File storing the state of the modem
|
||||||
ServerSocket, ListenSocket, ClientSocket, ClientAddrSize: longint; //Server socket
|
ServerSocket, ListenSocket, ClientSocket, ClientAddrSize: longint; //Server socket
|
||||||
ServerAddr, ClientAddr: TInetSockAddr; //Server address
|
ServerAddr, ClientAddr: TInetSockAddr; //Server address
|
||||||
|
SigPipeHandler: pSigActionRec; //SIGPIPE handler
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef status}
|
{$ifdef status}
|
||||||
FileDescs: TFDset; //File descriptor set
|
FileDescs: TFDset; //File descriptor set
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
//Ignore signal
|
||||||
|
procedure DoSig (Sig: cint); cdecl;
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
//Terminal output
|
//Terminal output
|
||||||
procedure Output;
|
procedure Output;
|
||||||
begin
|
begin
|
||||||
|
@ -314,8 +320,21 @@ begin
|
||||||
//Connect
|
//Connect
|
||||||
CallServer;
|
CallServer;
|
||||||
//Recieve
|
//Recieve
|
||||||
if Calling then fpRecv (ServerSocket, @B, 1, 0)
|
if Calling then begin
|
||||||
else if Answering then fpRecv (ClientSocket, @B, 1, 0)
|
if fpRecv (ServerSocket, @B, 1, 0) <> 1 then begin
|
||||||
|
B := 0;
|
||||||
|
CloseSocket (ServerSocket);
|
||||||
|
Calling := false;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else if Answering then begin
|
||||||
|
if fpRecv (ClientSocket, @B, 1, 0) <> 1 then begin
|
||||||
|
B := 0;
|
||||||
|
CloseSocket (ClientSocket);
|
||||||
|
CloseSocket (ListenSocket);
|
||||||
|
Answering := false;
|
||||||
|
end;
|
||||||
|
end
|
||||||
else B := 0;
|
else B := 0;
|
||||||
end
|
end
|
||||||
{$endif}
|
{$endif}
|
||||||
|
@ -341,9 +360,6 @@ begin
|
||||||
B := B or $10;
|
B := B or $10;
|
||||||
//FFFA: Modem or no input
|
//FFFA: Modem or no input
|
||||||
{$ifdef modem}
|
{$ifdef modem}
|
||||||
//Connect
|
|
||||||
CallServer;
|
|
||||||
//Check the connection
|
|
||||||
if Calling then begin
|
if Calling then begin
|
||||||
fpfd_zero (FileDescs);
|
fpfd_zero (FileDescs);
|
||||||
fpfd_set (ServerSocket, FileDescs);
|
fpfd_set (ServerSocket, FileDescs);
|
||||||
|
@ -710,8 +726,19 @@ begin
|
||||||
//Connect
|
//Connect
|
||||||
CallServer;
|
CallServer;
|
||||||
//Send
|
//Send
|
||||||
if Calling then fpSend (ServerSocket, @B, 1, 0)
|
if Calling then begin
|
||||||
else if Answering then fpSend (ClientSocket, @B, 1, 0);
|
if fpSend (ServerSocket, @B, 1, 0) <> 1 then begin
|
||||||
|
CloseSocket (ServerSocket);
|
||||||
|
Calling := false;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else if Answering then begin
|
||||||
|
if fpSend (ClientSocket, @B, 1, 0) <> 1 then begin
|
||||||
|
CloseSocket (ClientSocket);
|
||||||
|
CloseSocket (ListenSocket);
|
||||||
|
Answering := false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
{$endif}
|
{$endif}
|
||||||
//Regular store
|
//Regular store
|
||||||
|
@ -767,6 +794,17 @@ begin
|
||||||
{$ifdef modem}
|
{$ifdef modem}
|
||||||
//Initialise the modem
|
//Initialise the modem
|
||||||
Calling := false;
|
Calling := false;
|
||||||
|
Answering := false;
|
||||||
|
//Initialise the SIGPIPE handler
|
||||||
|
new (SigPipeHandler);
|
||||||
|
SigPipeHandler^.sa_Handler := SigActionHandler (@DoSig);
|
||||||
|
fillchar (SigPipeHandler^.Sa_Mask, sizeof (SigPipeHandler^.sa_mask), #0);
|
||||||
|
SigPipeHandler^.Sa_Flags := 0;
|
||||||
|
SigPipeHandler^.Sa_Restorer := nil;
|
||||||
|
try
|
||||||
|
fpSigAction (SigPipe, SigPipeHandler, nil);
|
||||||
|
except
|
||||||
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
//Check the arguments
|
//Check the arguments
|
||||||
|
|
Loading…
Reference in New Issue