Skip to content

Commit 553ed93

Browse files
- ajuste no server FPHttp para o max de conexoes permitidas pelo operacional
- ajuste no server indy e sagui colocando as procedures para o protected - ajuste no server indy nas propriedades ListenQueue e MaxConnections acessando diretamente no motor
1 parent e5d2b1b commit 553ed93

3 files changed

Lines changed: 56 additions & 35 deletions

File tree

src/engine/fpHTTP/RALfpHTTPServer.pas

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
unit RALfpHTTPServer;
22

3+
{$I ..\..\base\PascalRAL.inc}
4+
35
interface
46

57
uses
@@ -50,8 +52,8 @@ TRALfpHttpServerThread = class(TThread)
5052
function GetActive: boolean;
5153
procedure SetActive(AValue: boolean);
5254

53-
function GetQueueSize: IntegerRAL;
54-
procedure SetQueueSize(const AValue: IntegerRAL);
55+
function GetQueueSize: Word;
56+
procedure SetQueueSize(const AValue: Word);
5557

5658
function GetURLServer: StringRAL;
5759

@@ -75,7 +77,7 @@ TRALfpHttpServerThread = class(TThread)
7577
property Active: boolean read GetActive write SetActive;
7678
property Port: IntegerRAL read GetPort write SetPort;
7779
property SessionTimeout: IntegerRAL read GetSessionTimeout write SetSessionTimeout;
78-
property QueueSize: IntegerRAL read GetQueueSize write SetQueueSize;
80+
property QueueSize: Word read GetQueueSize write SetQueueSize;
7981
end;
8082

8183
TRALfpHttpServer = class(TRALServer)
@@ -88,21 +90,29 @@ TRALfpHttpServer = class(TRALServer)
8890
function GetSSL: TRALfpHTTPSSL;
8991
procedure SetSSL(const AValue: TRALfpHTTPSSL);
9092

91-
function GetQueueSize: IntegerRAL;
92-
procedure SetQueueSize(const AValue: IntegerRAL);
93+
function GetQueueSize: Word;
94+
procedure SetQueueSize(const AValue: Word);
9395

9496
procedure SetSessionTimeout(const AValue: IntegerRAL); override;
9597
function CreateRALSSL: TRALSSL; override;
9698
public
9799
constructor Create(AOwner: TComponent); override;
98100
destructor Destroy; override;
99101
published
100-
property QueueSize : IntegerRAL read GetQueueSize write SetQueueSize;
102+
property QueueSize : Word read GetQueueSize write SetQueueSize;
101103
property SSL: TRALfpHTTPSSL read GetSSL write SetSSL;
102104
end;
103105

104106
implementation
105107

108+
uses
109+
// units usadas para capturar a constante SOMAXCONN
110+
{$IFDEF RALWINDOWS}
111+
WinSock2;
112+
{$ELSE}
113+
sockets;
114+
{$ENDIF}
115+
106116
{ TRALfpHTTPCertData }
107117

108118
function TRALfpHTTPCertData.GetFileName(AIndex: Integer): string;
@@ -134,7 +144,7 @@ function TRALfpHttpServerThread.GetPort: IntegerRAL;
134144
Result := FParent.Port;
135145
end;
136146

137-
function TRALfpHttpServerThread.GetQueueSize: IntegerRAL;
147+
function TRALfpHttpServerThread.GetQueueSize: Word;
138148
begin
139149
Result := FHttp.QueueSize;
140150
end;
@@ -151,9 +161,12 @@ procedure TRALfpHttpServerThread.SetPort(AValue: IntegerRAL);
151161
Active := vActive;
152162
end;
153163

154-
procedure TRALfpHttpServerThread.SetQueueSize(const AValue: IntegerRAL);
164+
procedure TRALfpHttpServerThread.SetQueueSize(const AValue: Word);
155165
begin
156-
FHttp.QueueSize := AValue;
166+
if (AValue <= 0) or (AValue > SOMAXCONN) then
167+
FHttp.QueueSize := SOMAXCONN
168+
else
169+
FHttp.QueueSize := AValue;
157170
end;
158171

159172
procedure TRALfpHttpServerThread.SetSessionTimeout(const AValue: IntegerRAL);
@@ -413,7 +426,7 @@ constructor TRALfpHttpServerThread.Create(AOwner: TRALfpHttpServer);
413426
FreeOnTerminate := False;
414427

415428
FHttp := TFPHttpServer.Create(AOwner);
416-
QueueSize := -1;
429+
FHttp.QueueSize := SOMAXCONN;
417430
FHttp.Threaded := True;
418431
FHttp.OnRequest := @OnCommandProcess;
419432

@@ -447,7 +460,7 @@ destructor TRALfpHTTPSSL.Destroy;
447460
constructor TRALfpHttpServer.Create(AOwner: TComponent);
448461
begin
449462
inherited;
450-
SetEngine('fpHTTP');
463+
SetEngine('fpHTTP ' + {$I %FPCVERSION%});
451464
FHttpThread := TRALfpHttpServerThread.Create(Self);
452465
FHttpThread.Port := Port;
453466
end;
@@ -468,7 +481,7 @@ destructor TRALfpHttpServer.Destroy;
468481
inherited;
469482
end;
470483

471-
function TRALfpHttpServer.GetQueueSize: IntegerRAL;
484+
function TRALfpHttpServer.GetQueueSize: Word;
472485
begin
473486
Result := FHttpThread.QueueSize;
474487
end;
@@ -504,7 +517,7 @@ procedure TRALfpHttpServer.SetPort(const AValue: IntegerRAL);
504517
inherited;
505518
end;
506519

507-
procedure TRALfpHttpServer.SetQueueSize(const AValue: IntegerRAL);
520+
procedure TRALfpHttpServer.SetQueueSize(const AValue: Word);
508521
begin
509522
FHttpThread.QueueSize := AValue;
510523
end;

src/engine/indy/RALIndyServer.pas

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ TRALIndyServer = class(TRALServer)
3636
private
3737
FHttp: TIdHTTPServer;
3838
FHandlerSSL: TIdServerIOHandlerSSLOpenSSL;
39-
FMaxConnections: IntegerRAL;
40-
FListenQueue: IntegerRAL;
41-
procedure SetListenQueue(const Value: IntegerRAL);
42-
procedure SetMaxConnections(const Value: IntegerRAL);
4339
protected
4440
function CreateRALSSL: TRALSSL; override;
4541
function IPv6IsImplemented: Boolean; override;
42+
function GetListenQueue: IntegerRAL;
43+
function GetMaxConnections: IntegerRAL;
4644
function GetSSL: TRALIndySSL;
4745
procedure QuerySSLPort(APort: TIdPort; var VUseSSL: Boolean);
4846
procedure SetActive(const AValue: Boolean); override;
47+
procedure SetListenQueue(const AValue: IntegerRAL);
48+
procedure SetMaxConnections(const AValue: IntegerRAL);
4949
procedure SetPort(const AValue: IntegerRAL); override;
5050
procedure SetSessionTimeout(const AValue: IntegerRAL); override;
5151
procedure SetSSL(const AValue: TRALIndySSL);
@@ -59,8 +59,8 @@ TRALIndyServer = class(TRALServer)
5959
constructor Create(AOwner: TComponent); override;
6060
destructor Destroy; override;
6161
published
62-
property ListenQueue: IntegerRAL read FListenQueue write SetListenQueue;
63-
property MaxConnections: IntegerRAL read FMaxConnections write SetMaxConnections;
62+
property ListenQueue: IntegerRAL read GetListenQueue write SetListenQueue;
63+
property MaxConnections: IntegerRAL read GetMaxConnections write SetMaxConnections;
6464
property SSL: TRALIndySSL read GetSSL write SetSSL;
6565
end;
6666

@@ -109,6 +109,16 @@ destructor TRALIndyServer.Destroy;
109109
inherited;
110110
end;
111111

112+
function TRALIndyServer.GetListenQueue: IntegerRAL;
113+
begin
114+
Result := FHttp.ListenQueue
115+
end;
116+
117+
function TRALIndyServer.GetMaxConnections: IntegerRAL;
118+
begin
119+
Result := FHttp.MaxConnections;
120+
end;
121+
112122
function TRALIndyServer.GetSSL: TRALIndySSL;
113123
begin
114124
Result := TRALIndySSL(GetDefaultSSL);
@@ -341,16 +351,14 @@ procedure TRALIndyServer.SetActive(const AValue: Boolean);
341351
FHttp.Active := AValue;
342352
end;
343353

344-
procedure TRALIndyServer.SetListenQueue(const Value: IntegerRAL);
354+
procedure TRALIndyServer.SetListenQueue(const AValue: IntegerRAL);
345355
begin
346-
FListenQueue := Value;
347-
FHttp.ListenQueue := Value;
356+
FHttp.ListenQueue := AValue;
348357
end;
349358

350-
procedure TRALIndyServer.SetMaxConnections(const Value: IntegerRAL);
359+
procedure TRALIndyServer.SetMaxConnections(const AValue: IntegerRAL);
351360
begin
352-
FMaxConnections := Value;
353-
FHttp.MaxConnections := Value;
361+
FHttp.MaxConnections := AValue;
354362
end;
355363

356364
procedure TRALIndyServer.SetSessionTimeout(const AValue: IntegerRAL);

src/engine/sagui/RALSaguiServer.pas

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ TRALSaguiServer = class(TRALServer)
6161
Asize: csize_t): cssize_t; cdecl; static;
6262
class procedure DoStreamFree(Acls: Pcvoid); cdecl; static;
6363
class function GetSaguiIP(AReq: Psg_httpreq): StringRAL;
64-
procedure SetConnectionLimit(const Value: Int64RAL);
65-
procedure SetPoolCount(const Value: IntegerRAL);
66-
function GetPoolCount: IntegerRAL;
67-
function GetConnectionLimit: Int64RAL;
6864
protected
6965
function CreateRALSSL: TRALSSL; override;
7066
procedure CreateServerHandle;
7167
procedure FreeServerHandle;
7268
function InitializeServer: boolean;
7369
function IPv6IsImplemented: boolean; override;
7470

71+
function GetConnectionLimit: Int64RAL;
72+
function GetPoolCount: IntegerRAL;
7573
function GetSSL: TRALSaguiSSL;
7674
procedure SetActive(const AValue: boolean); override;
75+
procedure SetConnectionLimit(const AValue: Int64RAL);
7776
procedure SetLibPath(const AValue: TFileName);
77+
procedure SetPoolCount(const AValue: IntegerRAL);
7878
procedure SetPort(const AValue: IntegerRAL); override;
7979
procedure SetSessionTimeout(const AValue: IntegerRAL); override;
8080
procedure SetSSL(const AValue: TRALSaguiSSL);
@@ -511,11 +511,11 @@ procedure TRALSaguiServer.SetActive(const AValue: boolean);
511511
end;
512512
end;
513513

514-
procedure TRALSaguiServer.SetConnectionLimit(const Value: Int64RAL);
514+
procedure TRALSaguiServer.SetConnectionLimit(const AValue: Int64RAL);
515515
begin
516-
FConnectionLimit := Value;
516+
FConnectionLimit := AValue;
517517
if FHandle <> nil then
518-
sg_httpsrv_set_con_limit(FHandle, Value);
518+
sg_httpsrv_set_con_limit(FHandle, AValue);
519519
end;
520520

521521
procedure TRALSaguiServer.SetLibPath(const AValue: TFileName);
@@ -543,11 +543,11 @@ procedure TRALSaguiServer.ShutdownServerHandle;
543543
sg_httpsrv_shutdown(FHandle);
544544
end;
545545

546-
procedure TRALSaguiServer.SetPoolCount(const Value: IntegerRAL);
546+
procedure TRALSaguiServer.SetPoolCount(const AValue: IntegerRAL);
547547
begin
548-
FPoolCount := Value;
548+
FPoolCount := AValue;
549549
if FHandle <> nil then
550-
sg_httpsrv_set_thr_pool_size(FHandle, Value);
550+
sg_httpsrv_set_thr_pool_size(FHandle, AValue);
551551
end;
552552

553553
procedure TRALSaguiServer.SetPort(const AValue: IntegerRAL);

0 commit comments

Comments
 (0)