Ignore:
Timestamp:
Dec 18, 2009, 1:42:22 PM (15 years ago)
Author:
george
Message:
  • Opraveno: Chybné vytváření pojmenovaných objektů TEvent.
  • Opraveno: Chybné přidělování a uvolňování zásobníků vláken a databázových spojení.
  • Opraveno: Chybná inicializace parametrů databázových spojení.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DirectWeb/UWebServer.pas

    r88 r89  
    1010  UCommon, syncobjs,
    1111  UMemoryStreamEx,
    12   UMIMEType, Synautil,
     12  UMIMEType, Synautil, UPool,
    1313  USqlDatabase, DOM, XMLRead, UHTMLControls;
    1414
     
    2020  { TDatabasePool }
    2121
    22   TDatabasePool = class(TObjectList)
     22  TDatabasePool = class(TThreadedPool)
    2323  private
    24     Lock: TCriticalSection;
     24    FActive: Boolean;
     25    procedure SetActive(const AValue: Boolean);
    2526  public
    26     PoolSize: Integer;
     27    property Active: Boolean read FActive write SetActive;
     28  public
    2729    HostName: string;
    2830    Schema: string;
    2931    UserName: string;
    3032    Password: string;
    31     procedure Allocate;
    32     function Acquire: TSqlDatabase;
    33     procedure Release(Database: TSqlDatabase);
    3433    constructor Create;
    3534    destructor Destroy; override;
     
    103102  Command: string;
    104103begin
     104  LoadConfiguration;
     105  DatabasePool.Active := True;
    105106  WriteLn('WoW hosting web server');
    106   LoadConfiguration;
    107107  with HTTPServer do begin
    108108    Socket.Active := True;
     
    127127  PageList: TPageList;
    128128begin
    129   SqlDatabase := DatabasePool.Acquire;
     129  SqlDatabase := TSqlDatabase(DatabasePool.Acquire);
    130130  with HandlerData, Response, Stream, SqlDatabase do
    131131  begin
     
    191191
    192192    DbRows.Destroy;
    193     Destroy;
    194193    WriteFooter(Stream);
    195194  end;
    196195  PageList.Destroy;
     196  DatabasePool.Release(SqlDatabase);
    197197end;
    198198
     
    207207  LinkQuery: TQueryParameterList;
    208208begin
    209   SqlDatabase := TSqlDatabase.Create;
     209  SqlDatabase := TSqlDatabase(DatabasePool.Acquire);
    210210  with HandlerData, Response, Stream, SqlDatabase do
    211211  begin
     
    223223    WriteString('</table>');
    224224    DbRows.Destroy;
    225     Destroy;
    226225    WriteFooter(Stream);
    227226  end;
     227  DatabasePool.Release(SqlDatabase);
    228228end;
    229229
     
    269269  begin
    270270    WriteHeader(Stream);
    271 
    272 
     271    WriteString('Index');
    273272    WriteFooter(Stream);
    274273  end;
     
    310309  inherited Create;
    311310  DatabasePool := TDatabasePool.Create;
    312   DatabasePool.Capacity := 20;
    313   DatabasePool.Allocate;
     311  DatabasePool.TotalCount := 20;
    314312
    315313  SessionStorage := TFileHTTPSessionStorage.Create;
     
    341339{ TDatabasePool }
    342340
    343 procedure TDatabasePool.Allocate;
     341procedure TDatabasePool.SetActive(const AValue: Boolean);
    344342var
    345343  I: Integer;
    346344begin
    347   for I := 0 to PoolSize - 1 do
    348     with TSqlDatabase(Items[Add(TSqlDatabase.Create)]) do begin
    349       HostName := Self.HostName;
    350       UserName := Self.UserName;
    351       Password := Self.Password;
    352       Database := Self.Schema;
    353       Connect;
    354     end;
    355 end;
    356 
    357 function TDatabasePool.Acquire: TSqlDatabase;
    358 begin
    359 
    360 end;
    361 
    362 procedure TDatabasePool.Release(Database: TSqlDatabase);
    363 begin
    364   try
    365     Lock.Acquire;
    366 
    367   finally
    368     Lock.Release;
    369   end;
     345  if not FActive and AValue then begin
     346    for I := 0 to TotalCount - 1 do
     347    with TThreadedPoolItem(Items[I]) do begin
     348      Item := TSqlDatabase.Create;
     349      with TSqlDatabase(Item) do begin
     350        HostName := Self.HostName;
     351        UserName := Self.UserName;
     352        Password := Self.Password;
     353        Database := Self.Schema;
     354        Connect;
     355      end;
     356    end;
     357  end else
     358  if FActive and not AValue then begin
     359
     360  end;
     361  FActive := AValue;
    370362end;
    371363
    372364constructor TDatabasePool.Create;
    373365begin
    374   Lock := TCriticalSection.Create;
     366  inherited;
    375367end;
    376368
    377369destructor TDatabasePool.Destroy;
    378370begin
    379   Lock.Destroy;
    380371  inherited Destroy;
    381372end;
Note: See TracChangeset for help on using the changeset viewer.