OSDN Git Service

IdSLPP20を変更。
authornaru <bottle@mikage.to>
Tue, 16 Mar 2004 12:38:50 +0000 (12:38 +0000)
committernaru <bottle@mikage.to>
Tue, 16 Mar 2004 12:38:50 +0000 (12:38 +0000)
接続時にConnectではなくConnectServerを呼び出すように変え、Connect自体は別スレッドから呼び出されるように変更。
それに伴い、Connectが直接例外を出せなくなったので、OnConnectFailedイベントを追加、実装。
メインフォーム側を、ConnectServer/OnConnectFailedイベントを使って書き換え。
IdAntiFreezeを外した。
まだ異常系のテストはほとんどやっていない状態。

bottleclient/MainForm.dfm
bottleclient/MainForm.pas
sakurasuite/IdSLPP20.pas

index a54e502..e2eb893 100755 (executable)
@@ -970,7 +970,7 @@ object frmSender: TfrmSender
     Left = 8
     Top = 72
     Bitmap = {
-      494C01012F003100040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
+      494C01012F003100040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
       000000000000360000002800000040000000D0000000010020000000000000D0
       0000000000000000000000000000000000000000000000000000000000000000
       0000000000000000000000000000000000000000000000000000000000000000
@@ -2690,7 +2690,8 @@ object frmSender: TfrmSender
       C001FFFFFC018000C001F7FFFC010000C001F7FFFC010000C001F3CF00010000
       C001F18F00010001C001F89F00010003C001F83F00010007C001F87F00030007
       C001F03F00070007C001F11F000F0007C001FF8F00FF0007C003FFC701FF800F
-      C007FFFF03FFF8FFC00FFFFFFFFFFFFF}
+      C007FFFF03FFF8FFC00FFFFFFFFFFFFF00000000000000000000000000000000
+      000000000000}
   end
   object mnPopupConst: TPopupMenu
     Images = imgIcon
@@ -2727,6 +2728,7 @@ object frmSender: TfrmSender
     DebugMode = False
     ProxyMode = False
     OnConnect = IdSLPP20Connect
+    OnConnectFailed = IdSLPP20ConnectFailed
     OnDisconnect = Slpp20Disconnect
     OnSLPPEvent = Slpp20SlppEvent
     Left = 392
@@ -2779,9 +2781,4 @@ object frmSender: TfrmSender
     Left = 424
     Top = 104
   end
-  object AntiFreeze: TIdAntiFreeze
-    OnlyWhenIdle = False
-    Left = 392
-    Top = 104
-  end
 end
index 65448ff..fa736a9 100755 (executable)
@@ -19,7 +19,7 @@ uses
   ScriptConsts, DateUtils, BottleChainRule, BottleChainEvent,
   SakuraSeekerInstance, HEditor, HTSearch, heClasses, heFountain,
   SakuraScriptFountain, SppList, SurfacePreview, XDOM_2_3_J3, SsPlayTime,
-  RegexUtils, StrReplace, StrReplaceDialog, IdAntiFreezeBase, IdAntiFreeze;
+  RegexUtils, StrReplace, StrReplaceDialog, IdAntiFreezeBase;
 
 type
   TSurfacePreviewType = (spHint, spEditor);
@@ -176,7 +176,6 @@ type
     mnUndo: TMenuItem;
     mnRedo: TMenuItem;
     N9: TMenuItem;
-    AntiFreeze: TIdAntiFreeze;
     procedure actConfirmExecute(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
@@ -270,6 +269,7 @@ type
     procedure memScriptSelectionChange(Sender: TObject; Selected: Boolean);
     procedure actUndoExecute(Sender: TObject);
     procedure actRedoExecute(Sender: TObject);
+    procedure IdSLPP20ConnectFailed(Sender: TObject);
   private
     FSleeping: boolean;  // \94z\91\97\83X\83\8a\81[\83v\92\86\82©\82Ç\82¤\82©
     FStatusText: String;
@@ -746,36 +746,17 @@ begin
   end;
   IdSlpp20.LUID := Pref.LUID;
   self.Cursor := crHourGlass;
-  try
-    if IdSlpp20.Connected then IdSlpp20.Disconnect;
-    if Pref.UseHttpProxy then begin
-      IdSlpp20.Host := Pref.ProxyAddress;
-      IdSlpp20.Port := Pref.ProxyPort;
-      IdSlpp20.ProxyMode := true;
-    end else begin
-      IdSlpp20.Host := Pref.BottleServer;
-      IdSlpp20.Port := Pref.BottleServerPort;
-      IdSlpp20.ProxyMode := false;
-    end;
-    IdSlpp20.Connect;
-  except
-    on EIdException do begin
-      Added := false;
-      if FBeginConnectFailCount = 0 then begin
-        Inc(FBeginConnectFailCount);
-        Beep;
-        if Pref.UseHttpProxy then
-          ShowMessage('HTTP Proxy\82ð\92Ê\82\82ÄSSTP Bottle\83T\81[\83o\82É\90Ú\91±\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B'#13#10 +
-                      '\83l\83b\83g\83\8f\81[\83N\82Ì\8fó\91Ô\81EProxy\82Ì\8fó\91Ô\82ð\8am\94F\82µ\82Ä\82­\82¾\82³\82¢\81B'#13#10 +
-                      '\82 \82é\82¢\82Í\83T\81[\83o\82ª\83_\83E\83\93\82µ\82Ä\82¢\82é\89Â\94\\90«\82ª\82 \82è\82Ü\82·\81B')
-        else
-          ShowMessage('SSTP Bottle\83T\81[\83o\82É\90Ú\91±\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B'#13#10 +
-                      '\83l\83b\83g\83\8f\81[\83N\82É\8cq\82ª\82Á\82Ä\82¢\82é\82©\8am\94F\82µ\82Ä\82­\82¾\82³\82¢\81B'#13#10 +
-                      '\82 \82é\82¢\82Í\83T\81[\83o\82ª\83_\83E\83\93\82µ\82Ä\82¢\82é\89Â\94\\90«\82ª\82 \82è\82Ü\82·\81B');
-      end else
-        Inc(FBeginConnectFailCount);
-    end;
+  if IdSlpp20.Connected then IdSlpp20.Disconnect;
+  if Pref.UseHttpProxy then begin
+    IdSlpp20.Host := Pref.ProxyAddress;
+    IdSlpp20.Port := Pref.ProxyPort;
+    IdSlpp20.ProxyMode := true;
+  end else begin
+    IdSlpp20.Host := Pref.BottleServer;
+    IdSlpp20.Port := Pref.BottleServerPort;
+    IdSlpp20.ProxyMode := false;
   end;
+  IdSlpp20.ConnectServer;
   self.Cursor := crDefault;
 end;
 
@@ -3200,4 +3181,22 @@ begin
   inherited;
 end;
 
+procedure TfrmSender.IdSLPP20ConnectFailed(Sender: TObject);
+begin
+  Added := false;
+  if FBeginConnectFailCount = 0 then
+  begin
+    Beep;
+    if Pref.UseHttpProxy then
+      ShowMessage('HTTP Proxy\82ð\92Ê\82\82ÄSSTP Bottle\83T\81[\83o\82É\90Ú\91±\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B'#13#10 +
+                  '\83l\83b\83g\83\8f\81[\83N\82Ì\8fó\91Ô\81EProxy\82Ì\8fó\91Ô\82ð\8am\94F\82µ\82Ä\82­\82¾\82³\82¢\81B'#13#10 +
+                  '\82 \82é\82¢\82Í\83T\81[\83o\82ª\83_\83E\83\93\82µ\82Ä\82¢\82é\89Â\94\\90«\82ª\82 \82è\82Ü\82·\81B')
+    else
+      ShowMessage('SSTP Bottle\83T\81[\83o\82É\90Ú\91±\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B'#13#10 +
+                  '\83l\83b\83g\83\8f\81[\83N\82É\8cq\82ª\82Á\82Ä\82¢\82é\82©\8am\94F\82µ\82Ä\82­\82¾\82³\82¢\81B'#13#10 +
+                  '\82 \82é\82¢\82Í\83T\81[\83o\82ª\83_\83E\83\93\82µ\82Ä\82¢\82é\89Â\94\\90«\82ª\82 \82è\82Ü\82·\81B');
+  end;
+  Inc(FBeginConnectFailCount);
+end;
+
 end.
index 5bf6198..869a0b6 100644 (file)
@@ -50,6 +50,8 @@ type
     FOnConnect: TNotifyEvent;
     FOnDisconnect: TNotifyEvent;
     FLastReadTime: Int64;
+    FTimeout: Integer;
+    FOnConnectFailed: TNotifyEvent;
     procedure SetDebugMode(const Value: boolean);
     procedure SetLUID(const Value: String);
     procedure SetOnSlppEvent(const Value: TIdSlppEvent);
@@ -58,12 +60,16 @@ type
     procedure SetOnDisconnect(const Value: TNotifyEvent);
     function GetLastReadTimeInterval: integer;
     procedure SetLastReadTime(const Value: Int64);
+    procedure SetOnConnectFailed(const Value: TNotifyEvent);
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     procedure Connect(const ATimeout: Integer = IdTimeoutDefault); override;
+    procedure ConnectServer(const ATimeout: Integer = IdTimeoutDefault);
     procedure Disconnect; override;
     procedure DoOnSlppEvent;
+    procedure DoOnConnect;
+    procedure DoOnConnectFailed;
     property SLPP20ReadThread: TIdSLPP20ReadThread read FSLPPThread;
     property LastReadTime: Int64 read FLastReadTime write SetLastReadTime;
     property LastReadTimeInterval: integer read GetLastReadTimeInterval;
@@ -73,6 +79,7 @@ type
     property DebugMode: boolean read FDebugMode write SetDebugMode;
     property ProxyMode: boolean read FProxyMode write SetProxyMode;
     property OnConnect: TNotifyEvent read FOnConnect write SetOnConnect;
+    property OnConnectFailed: TNotifyEvent read FOnConnectFailed write SetOnConnectFailed;
     property OnDisconnect: TNotifyEvent read FOnDisconnect write SetOnDisconnect;
     property OnSLPPEvent: TIdSlppEvent read FOnSlppEvent write SetOnSlppEvent;
     {ProxyMode = true\82Ì\82Æ\82«\82Í\81AHost, Port\82É\83v\83\8d\83L\83V\96¼\82ð}
@@ -95,11 +102,12 @@ end;
 procedure TIdSLPP20.Connect(const ATimeout: Integer);
 begin
   inherited Connect(ATimeout);
+end;
+
+procedure TIdSLPP20.ConnectServer;
+begin
   try
-    if Assigned(FOnConnect) then begin
-      OnConnect(self);
-    end;
-    // create the reading thread and assign the current Telnet object to it
+    FTimeout := ATimeout;
     FSLPPThread := TIdSLPP20ReadThread.Create(self);
   except on E: EIdSocketError do
     raise EIdSlppClientConnectError.Create('Connection Failed');
@@ -124,18 +132,32 @@ begin
   if Assigned(FSLPPThread) then begin
     FSLPPThread.Terminate;
     // FSLPPThread.WaitFor;
+    FSLPPThread := nil;
   end;
   if Assigned(FOnDisconnect) then begin
     OnDisconnect(self);
   end;
 end;
 
+procedure TIdSLPP20.DoOnConnect;
+begin
+  if Assigned(FOnConnect) then
+    FOnConnect(self);
+end;
+
+procedure TIdSLPP20.DoOnConnectFailed;
+begin
+  if Assigned(FOnConnectFailed) then
+    FOnConnectFailed(self);
+end;
+
 procedure TIdSLPP20.DoOnSlppEvent;
 begin
   try
     FOnSlppEvent(self, FSLPPThread.FEvent, FSLPPThread.FParam);
   except
-    ShowMessage('Exception occured in OnSlppEvent');
+    on E: Exception do
+      ShowMessage('Exception occured in OnSlppEvent: '#13#10 + E.Message);
   end;
 end;
 
@@ -165,6 +187,11 @@ begin
   FOnConnect := Value;
 end;
 
+procedure TIdSLPP20.SetOnConnectFailed(const Value: TNotifyEvent);
+begin
+  FOnConnectFailed := Value;
+end;
+
 procedure TIdSLPP20.SetOnDisconnect(const Value: TNotifyEvent);
 begin
   FOnDisconnect := Value;
@@ -184,14 +211,25 @@ end;
 
 constructor TIdSLPP20ReadThread.Create(AClient: TIdSLPP20);
 begin
-  inherited Create(false);
+  inherited Create(true);
   FClient := AClient;
   FreeOnTerminate := true;
+  Resume;
 end;
 
 procedure TIdSLPP20ReadThread.Execute;
 var Line: String;
 begin
+  try
+    FClient.Connect(FClient.FTimeout);
+    if Assigned(FClient.OnConnect) then begin
+      Synchronize(FClient.DoOnConnect);
+    end;
+  except
+    Synchronize(FClient.DoOnConnectFailed);
+    Exit;
+  end;
+
   FRecvData := TStringList.Create;
   FReceivedLog := TStringList.Create;
   if FClient.ProxyMode then begin