Make the emulated modem recognise dropped connection and act accordingly
This commit is contained in:
parent
f8b27b8465
commit
d324e795ed
53
emulator.pas
53
emulator.pas
|
@ -11,7 +11,7 @@ program Emulator;
|
|||
{$define status}
|
||||
{$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
|
||||
{$ifdef tape}
|
||||
|
@ -80,11 +80,17 @@ var
|
|||
ModemState: file of Connection; //File storing the state of the modem
|
||||
ServerSocket, ListenSocket, ClientSocket, ClientAddrSize: longint; //Server socket
|
||||
ServerAddr, ClientAddr: TInetSockAddr; //Server address
|
||||
SigPipeHandler: pSigActionRec; //SIGPIPE handler
|
||||
{$endif}
|
||||
{$ifdef status}
|
||||
FileDescs: TFDset; //File descriptor set
|
||||
{$endif}
|
||||
|
||||
//Ignore signal
|
||||
procedure DoSig (Sig: cint); cdecl;
|
||||
begin
|
||||
end;
|
||||
|
||||
//Terminal output
|
||||
procedure Output;
|
||||
begin
|
||||
|
@ -314,8 +320,21 @@ begin
|
|||
//Connect
|
||||
CallServer;
|
||||
//Recieve
|
||||
if Calling then fpRecv (ServerSocket, @B, 1, 0)
|
||||
else if Answering then fpRecv (ClientSocket, @B, 1, 0)
|
||||
if Calling then begin
|
||||
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;
|
||||
end
|
||||
{$endif}
|
||||
|
@ -343,7 +362,7 @@ begin
|
|||
{$ifdef modem}
|
||||
//Connect
|
||||
CallServer;
|
||||
//Check the connection
|
||||
//Check connection status
|
||||
if Calling then begin
|
||||
fpfd_zero (FileDescs);
|
||||
fpfd_set (ServerSocket, FileDescs);
|
||||
|
@ -710,8 +729,19 @@ begin
|
|||
//Connect
|
||||
CallServer;
|
||||
//Send
|
||||
if Calling then fpSend (ServerSocket, @B, 1, 0)
|
||||
else if Answering then fpSend (ClientSocket, @B, 1, 0);
|
||||
if Calling then begin
|
||||
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
|
||||
{$endif}
|
||||
//Regular store
|
||||
|
@ -767,6 +797,17 @@ begin
|
|||
{$ifdef modem}
|
||||
//Initialise the modem
|
||||
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}
|
||||
|
||||
//Check the arguments
|
||||
|
|
Loading…
Reference in New Issue