首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >释放模式的EIdSocketError

释放模式的EIdSocketError
EN

Stack Overflow用户
提问于 2011-12-05 15:24:18
回答 1查看 5.2K关注 0票数 3

我正在维护一个THTTPSoapDispatcherTHTTPSoapPascalInvoker SOAP服务器(在delphi-XE2中包含EIDSocketErrorTWSDLHTMLPublish)的TWebModule ),而且我无法找到处理EIDSocketError的方法(而不是在调试模式下!)。

我甚至不知道它是从哪里升起的..。我知道,当用户在等待来自服务器的响应(请求超时或客户端丢失的网络)时,会在用户断开连接后引发该问题。

当然,它是由IdHTTPWebBrokerBridge组件引发的,所以我尝试从myIdHTTPWebBrokerBridge.OnException中处理它,但没有成功。我到处读到,它在调试模式下是可以避免的,但却找不到在发布模式下如何处理它的线索,甚至无法阻止它的出现……

如果需要的话,我可以为我的应用程序的请求部分提供代码。

代码语言:javascript
运行
复制
MyService.exe

program MyService;
{$APPTYPE GUI}


{$R 'documents.res' 'documents.rc'}

uses
  Forms,
  Sysutils,
  WebReq,
  IdHTTPWebBrokerBridge,
  UFMyService in 'Unit\UFMyService.pas' {FMyService},
  UWMMyService in 'Unit\UWMMyService.pas' {WMMyService: TWebModule},
  UDMMyService in 'Unit\UDMMyService.pas' {DMMyService: TDataModule},
  UIMyService in 'Unit\UIMyService.pas',
  UCMyService in 'Unit\UCMyService.pas',
  superobject in 'Unit\superobject.pas',
  superxmlparser in 'Unit\superxmlparser.pas',


{$R *.res}
const
  se = '/';
begin
  if WebRequestHandler <> nil then
    WebRequestHandler.WebModuleClass := WebModuleClass;
  Application.Initialize;
  Application.Title := 'My Service';
  try
    Application.CreateForm(TFMyService, FMyService);
    Application.Run;
  Except on E:Exception do
    begin
      Log('!! Exception au lancement : '+E.Message);
      Application.Terminate;
    end;
  end;
end.

然后进去

代码语言:javascript
运行
复制
UFMyService.pas

unit UFMyService;

interface

uses (...)

type
  TFMyService = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
    procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
(...)
  private
    FServer: TIdHTTPWebBrokerBridge;
    procedure handleException(AContext: TIdContext; AException: Exception);
(...)
  end;

var
  FMyService: TFMyService;

implementation

{$R *.dfm}

uses
  UWMMyService, UDMMyService, (...);

procedure TFMyService.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
  if not(E is EIdConnClosedGracefully) and not (E is EIdConnClosedGracefully) then
  begin
    Log(e.Message);
  end;
end;

procedure TFMyService.FormCreate(Sender: TObject);
begin
  (...)
  FServer := TIdHTTPWebBrokerBridge.Create(Self);
  FServer.OnException := handleException;
  (...)
end;

procedure TFMyService.handleException(AContext: TIdContext; AException: Exception);
begin
  if not(AException is EIdSilentException) and not(AException is EIdConnClosedGracefully) then
  begin
    Log(AException.Message);
  end;
end;

[edit]

“老生常谈。

原来显示弹出窗口的是德尔福和它的TWebRequestHandler:

代码语言:javascript
运行
复制
procedure TWebRequestHandler.HandleException(Sender: TObject);
var
  Handled: Boolean;
  Intf: IWebExceptionHandler;
begin
  Handled := False;
  if ExceptObject is Exception and
    Supports(Sender, IWebExceptionHandler, Intf) then
    try
      Intf.HandleException(Exception(ExceptObject), Handled);
    except
      Handled := True;
      System.SysUtils.ShowException(ExceptObject, ExceptAddr);
    end;
  if (not Handled) then
    System.SysUtils.ShowException(ExceptObject, ExceptAddr);
end;

我只是不知道如何处理这个例外.

如果我声明我的OnException的WebModule,我可以记录异常,但无论我如何处理/释放它,它仍然显示弹出:

代码语言:javascript
运行
复制
procedure TWMMyService.WebModuleException(Sender: TObject; E: Exception;
  var Handled: Boolean);
var
  AnError : TObject;
begin
  Log('!! WebModule Error ('+Sender.ClassName+')');
  Log('!! Type : '+E.ClassName);
  Log('!! Message : '+E.Message);
  Handled:=True;
// later add-on
  if( E is EIdSilentException) then
  begin
    //Socket 10054 Connection reset by peer.
    //etc...
    AnError := AcquireExceptionObject;
    if (AnError <> nil) then
    begin
      Log('!! Ignore Exception');
      ReleaseExceptionObject;
    end;
  end; // then the popup appears...
end;

Log('!! Ignore Exception');已经到达,但是ReleaseExceptionObject没有作用;可能太迟了。

我将WebRequestHandler.MaxConnections改为100,以防止客户端被这些套接字异常太快地执行特技,但是想象一下必须验证100弹出才能继续工作。我不能就这样离开^^

谢谢所有的建议/建议/解决方案:)

[edit]

几个月后还想找个解决办法,没人知道?我厌倦了德尔福的侵扰和累人的错误,因为它不能比这更少!

EN

Stack Overflow用户

发布于 2011-12-05 19:21:43

为什么需要处理异常?EIdSocketError表示发生了套接字错误。连接可能丢失或关闭不正确。Indy服务器端连接是多线程的.套接字错误意味着套接字可能处于不稳定状态,需要关闭。让Indy在内部处理异常将停止连接的拥有线程,并为您关闭套接字。

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8387604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档