#1 2017-04-12 11:16:51

CarlosM
Member
Registered: 2017-03-23
Posts: 7

SynPDF over ISAPI

Hello,

When try to use SynPDF + FastReport on ISAPI, it does not work.

Any suggerence ?

regards

Offline

#2 2017-04-13 10:30:35

CarlosM
Member
Registered: 2017-03-23
Posts: 7

Re: SynPDF over ISAPI

Solved by undefine SYNZIP library {$undef USE_SYNZIP}

If not it raises an error on stream compress under ISAPI.

Offline

#3 2017-05-22 16:01:27

MtwStark
Member
From: Italy
Registered: 2016-01-05
Posts: 27

Re: SynPDF over ISAPI

I have same issue..

The error generates in the TPdfStream.InternalWriteTo() when calling the CompressionStream function (Stack Overflow)

If compiled in normal Forms.TApplication instead of WebBroker.TWebApplication then USE_SYNZIP works just fine.

Anyone knows if it is possible to use SynZIP within an ISAPI? or the reason why it doesn't in ISAPI?

Offline

#4 2017-05-25 09:07:32

MtwStark
Member
From: Italy
Registered: 2016-01-05
Posts: 27

Re: SynPDF over ISAPI

CarlosM wrote:

Hello,

When try to use SynPDF + FastReport on ISAPI, it does not work.

Any suggerence ?

regards


Hi CarlosM,
I have finally understood and solved the problem of SynPDF inside ISAPI using {$DEFINE USE_SYNZIP}

The problem is that the internal SynZip.CompressStream() function allocates 256Kb on the stack and inside an ISAPI this throws a StackOverflow exception, because your thread is not using your delphi defined stack size but the host worker default stack size, and (at least in IIS) it is probably 256Kb overall.

It is not an easy task to overwrite default stack size used by your threads but it is possible!

I have used a Detours Library to intercept the BeginThread and then inside the derouted function overwritten the stacksize.

Here it is my solution in my WebModule:

var
  TrampolineBeginThread: function(SecurityAttributes: Pointer; StackSize: LongWord;
    ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord; var ThreadId: TThreadID): THandle = nil;

function InterceptBeginThread(SecurityAttributes: Pointer; StackSize: LongWord;
  ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord;
  var ThreadId: TThreadID): THandle;
const
  STACK_SIZE_PARAM_IS_A_RESERVATION = $00010000; // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453(v=vs.85).aspx
begin
    CreationFlags := CreationFlags or STACK_SIZE_PARAM_IS_A_RESERVATION;
    StackSize := $100000; // 1Mb Stack size
    result := TrampolineBeginThread(SecurityAttributes, StackSize, ThreadFunc, Parameter, CreationFlags, ThreadId);
end;

initialization

  TrampolineBeginThread := InterceptCreate(@BeginThread, @InterceptBeginThread);

finalization

  InterceptRemove(@TrampolineBeginThread);

I have used old version (v1) of Delphi Detours Library

I hope this helps

bye

Offline

#5 2017-05-29 07:09:40

CarlosM
Member
Registered: 2017-03-23
Posts: 7

Re: SynPDF over ISAPI

Thank you!

Offline

#6 2017-05-29 07:58:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynPDF over ISAPI

Yes, there is a weird limitation of IIS threads.
See https://support.microsoft.com/en-us/help/932909
The stack size is limited to 256KB, so it was not possible to allocate more than that!

I've modified the source code to use 128KB for stream compression.
See https://synopse.info/fossil/info/f2fbefb9bf

Now SynZip should work directly over ISAPI.

Offline

Board footer

Powered by FluxBB