mirror of
https://github.com/rejetto/hfs2.git
synced 2025-12-19 18:13:46 +01:00
fix: connections broken
This commit is contained in:
parent
f1f5446b0d
commit
d2675b9028
29
hslib.pas
29
hslib.pas
@ -29,7 +29,7 @@ unit HSlib;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
OverbyteIcsWSocket, OverbyteIcsWSockets, classes, messages, winprocs, forms, extctrls, sysutils, system.contnrs, strUtils, winsock, inifiles, types;
|
OverbyteIcsWSocket, classes, messages, winprocs, forms, extctrls, sysutils, system.contnrs, strUtils, winsock, inifiles, types;
|
||||||
|
|
||||||
const
|
const
|
||||||
VERSION = '2.11.0';
|
VERSION = '2.11.0';
|
||||||
@ -204,7 +204,7 @@ type
|
|||||||
eventData: ansistring;
|
eventData: ansistring;
|
||||||
ignoreSpeedLimit: boolean;
|
ignoreSpeedLimit: boolean;
|
||||||
limiters: TobjectList; // every connection can be bound to a number of TspeedLimiter
|
limiters: TobjectList; // every connection can be bound to a number of TspeedLimiter
|
||||||
constructor create(server:ThttpSrv);
|
constructor create(server:ThttpSrv; acceptingSock:Twsocket);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure disconnect();
|
procedure disconnect();
|
||||||
procedure addHeader(s:ansistring; overwrite:boolean=TRUE); // set an additional header line. If overwrite=false will always append.
|
procedure addHeader(s:ansistring; overwrite:boolean=TRUE); // set an additional header line. If overwrite=false will always append.
|
||||||
@ -261,7 +261,7 @@ type
|
|||||||
procedure calculateSpeed();
|
procedure calculateSpeed();
|
||||||
procedure processDisconnecting();
|
procedure processDisconnecting();
|
||||||
public
|
public
|
||||||
sock: TwsocketServer; // listening socket
|
sock, sock6: Twsocket; // listening socket
|
||||||
conns, // full list of connected clients
|
conns, // full list of connected clients
|
||||||
disconnecting, // list of pending disconnections
|
disconnecting, // list of pending disconnections
|
||||||
offlines, // disconnected clients to be freed
|
offlines, // disconnected clients to be freed
|
||||||
@ -673,16 +673,12 @@ try
|
|||||||
result:=TRUE;
|
result:=TRUE;
|
||||||
|
|
||||||
if onAddress = '*' then
|
if onAddress = '*' then
|
||||||
try
|
with sock6 do
|
||||||
sock.MultiListenSockets.Clear();
|
|
||||||
with sock.MultiListenSockets.Add do
|
|
||||||
begin
|
begin
|
||||||
addr:='::';
|
addr:='::';
|
||||||
Port := sock.port
|
Port:=sock.port;
|
||||||
|
listen();
|
||||||
end;
|
end;
|
||||||
sock.MultiListen();
|
|
||||||
except end;
|
|
||||||
|
|
||||||
notify(HE_OPEN, NIL);
|
notify(HE_OPEN, NIL);
|
||||||
except
|
except
|
||||||
end;
|
end;
|
||||||
@ -692,21 +688,24 @@ procedure ThttpSrv.stop();
|
|||||||
begin
|
begin
|
||||||
if sock = NIL then exit;
|
if sock = NIL then exit;
|
||||||
try sock.Close() except end;
|
try sock.Close() except end;
|
||||||
try sock.multiListenSockets.clear() except end;
|
try sock6.Close() except end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ThttpSrv.connected(Sender: TObject; Error: Word);
|
procedure ThttpSrv.connected(Sender: TObject; Error: Word);
|
||||||
begin if error=0 then ThttpConn.create(self) end;
|
begin if error=0 then ThttpConn.create(self, sender as Twsocket) end;
|
||||||
|
|
||||||
procedure ThttpSrv.disconnected(Sender: TObject; Error: Word);
|
procedure ThttpSrv.disconnected(Sender: TObject; Error: Word);
|
||||||
begin notify(HE_CLOSE, NIL) end;
|
begin notify(HE_CLOSE, NIL) end;
|
||||||
|
|
||||||
constructor ThttpSrv.create();
|
constructor ThttpSrv.create();
|
||||||
begin
|
begin
|
||||||
sock:=TWSocketServer.create(NIL);
|
sock:=TWSocket.create(NIL);
|
||||||
sock.OnSessionAvailable:=connected;
|
sock.OnSessionAvailable:=connected;
|
||||||
sock.OnSessionClosed:=disconnected;
|
sock.OnSessionClosed:=disconnected;
|
||||||
sock.OnBgException:=bgexception;
|
sock.OnBgException:=bgexception;
|
||||||
|
sock6:=TWSocket.create(NIL);
|
||||||
|
sock6.OnSessionAvailable:=connected;
|
||||||
|
sock6.OnBgException:=bgexception;
|
||||||
|
|
||||||
conns:=TobjectList.create;
|
conns:=TobjectList.create;
|
||||||
conns.OwnsObjects:=FALSE;
|
conns.OwnsObjects:=FALSE;
|
||||||
@ -938,13 +937,13 @@ begin canClose:=FALSE end;
|
|||||||
|
|
||||||
////////// CLIENT
|
////////// CLIENT
|
||||||
|
|
||||||
constructor ThttpConn.create(server:ThttpSrv);
|
constructor ThttpConn.create(server:ThttpSrv; acceptingSock:Twsocket);
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
// init socket
|
// init socket
|
||||||
sock:=Twsocket.create(NIL);
|
sock:=Twsocket.create(NIL);
|
||||||
sock.Dup(server.sock.Accept);
|
sock.Dup(acceptingSock.accept());
|
||||||
sock.OnDataAvailable:=dataavailable;
|
sock.OnDataAvailable:=dataavailable;
|
||||||
sock.OnSessionClosed:=disconnected;
|
sock.OnSessionClosed:=disconnected;
|
||||||
sock.onSendData:=senddata;
|
sock.onSendData:=senddata;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user