Re: [fpc-pascal] socket timeout

2013-04-17 Thread Xiangrong Fang
Will this be a CPU hog:

t := Now;
while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
  if Now - t > 0.1 * timeout then Break;   // approx.  seconds
end;

Thanks



2013/4/16 Luca Olivetti 

> Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
> >> How can I set the connection and read/write timeout when using socket
> >> in free pascal?
> > I seem to remember that synapse can do this.
>
> Only in svn and it does it this way
>
> if FConnectionTimeout > 0 then
> begin
>   // connect in non-blocking mode
>   b := NonBlockMode;
>   NonBlockMode := true;
>   SockCheck(synsock.Connect(FSocket, Sin));
>   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK) then
> if not CanWrite(FConnectionTimeout) then
>   FLastError := WSAETIMEDOUT;
>   NonBlockMode := b;
> end
> else
>   SockCheck(synsock.Connect(FSocket, Sin));
>
>
> NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
> WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
> CanWrite  does an fpSelect
>
> Bye
> --
> Luca
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] socket timeout

2013-04-17 Thread Rainer Stratmann
 On Wednesday 17 April 2013 09:17:09 you wrote:
> Will this be a CPU hog:
> 
> t := Now;
> while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
>   if Now - t > 0.1 * timeout then Break;   // approx.  seconds
> end;
> 
> Thanks

I did not read the whole thread, but that you favorite blocking mode (which I 
don't use).

For MSG_DONTWAIT as far I know you have to change to the nonblocking mode.

> 
> 
> 2013/4/16 Luca Olivetti 
> 
> > Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> > > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
> > >> How can I set the connection and read/write timeout when using socket
> > >> in free pascal?
> > > 
> > > I seem to remember that synapse can do this.
> > 
> > Only in svn and it does it this way
> > 
> > if FConnectionTimeout > 0 then
> > begin
> > 
> >   // connect in non-blocking mode
> >   b := NonBlockMode;
> >   NonBlockMode := true;
> >   SockCheck(synsock.Connect(FSocket, Sin));
> >   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK) then
> >   
> > if not CanWrite(FConnectionTimeout) then
> > 
> >   FLastError := WSAETIMEDOUT;
> >   
> >   NonBlockMode := b;
> > 
> > end
> > else
> > 
> >   SockCheck(synsock.Connect(FSocket, Sin));
> > 
> > NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
> > WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
> > CanWrite  does an fpSelect
> > 
> > Bye
> > --
> > Luca
> > 
> > ___
> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] socket timeout

2013-04-17 Thread Xiangrong Fang
I thought MSG_DONTWAIT is actually the flag to switch to nonblocking mode,
isn't it?  As a matter of fact, the fprecv() above would get a result of -1
and a sockterror of "Try Again", which is exactly the behavior of
nonblocking read.


2013/4/17 Rainer Stratmann 

>  On Wednesday 17 April 2013 09:17:09 you wrote:
> > Will this be a CPU hog:
> >
> > t := Now;
> > while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
> >   if Now - t > 0.1 * timeout then Break;   // approx. 
> seconds
> > end;
> >
> > Thanks
>
> I did not read the whole thread, but that you favorite blocking mode
> (which I
> don't use).
>
> For MSG_DONTWAIT as far I know you have to change to the nonblocking mode.
>
> >
> >
> > 2013/4/16 Luca Olivetti 
> >
> > > Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> > > > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
> > > >> How can I set the connection and read/write timeout when using
> socket
> > > >> in free pascal?
> > > >
> > > > I seem to remember that synapse can do this.
> > >
> > > Only in svn and it does it this way
> > >
> > > if FConnectionTimeout > 0 then
> > > begin
> > >
> > >   // connect in non-blocking mode
> > >   b := NonBlockMode;
> > >   NonBlockMode := true;
> > >   SockCheck(synsock.Connect(FSocket, Sin));
> > >   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK)
> then
> > >
> > > if not CanWrite(FConnectionTimeout) then
> > >
> > >   FLastError := WSAETIMEDOUT;
> > >
> > >   NonBlockMode := b;
> > >
> > > end
> > > else
> > >
> > >   SockCheck(synsock.Connect(FSocket, Sin));
> > >
> > > NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
> > > WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
> > > CanWrite  does an fpSelect
> > >
> > > Bye
> > > --
> > > Luca
> > >
> > > ___
> > > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Same code from LCL project throw error in console application

2013-04-17 Thread José Mejuto

El 16/04/2013 22:46, Krzysztof escribió:

Thanks! exInvalidOp exception mask solved problem. But I don't
understand. Same error I had in fpGUI project. fpGUI interface doesn't
use GTK, QT etc, it drawing over pure X11 so how it is possible that
application catch GTK errors?



Hello,

Almost any 'C' library mask that errors, so the programmers do not take 
them in account and anyone, like the X11, can raise that exceptions.


--

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Correct way for partial generic specialization

2013-04-17 Thread leledumbo
> You're missing the   again. :)

*self-headcut

> Not currently. It might be a useful extension however. I'll need to test
> what Delphi says about this...

OK, I'll wait



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Correct-way-for-partial-generic-specialization-tp5714160p5714175.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Correct way for partial generic specialization

2013-04-17 Thread Sven Barth

Am 17.04.2013 11:11, schrieb leledumbo:

You're missing the   again. :)

*self-headcut


Can it be that your E-Mail client misinterprets the "<...>" (with only 
one string as "value") as HTML tags? Because I can't see the "" I had 
written to you in your quotation.



Not currently. It might be a useful extension however. I'll need to test
what Delphi says about this...

OK, I'll wait
So... Delphi does not support that, but I still think that this is a 
valid extension of generics and can be used for all generic-able types 
instead of only classes.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Fpcup for FreeBSD: feedback welcome

2013-04-17 Thread Reinier Olislagers
Just uploaded a new version of fpcup (automatic FPC+Lazarus svn
downloader/installer for both stable and trunk) at
https://bitbucket.org/reiniero/fpcup/downloads

I welcome feedback from FreeBSD users - the binary should work on
FreeBSD 9 x64...
For the Lazarus installation part, it picks up newer/ports gdb installs
in /usr/local/bin

Prerequisites:
- none for PC-BSD; probably none for FreeBSD
- optional but recommended: newer gdb, e.g. installed via ports tree
- if running Lazarus: GTK environment

Thanks,
Reinier
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] socket timeout

2013-04-17 Thread Rainer Stratmann
 On Wednesday 17 April 2013 10:22:58 you wrote:
> I thought MSG_DONTWAIT is actually the flag to switch to nonblocking mode,
> isn't it?
May be.
> As a matter of fact, the fprecv() above would get a result of -1
> and a sockterror of "Try Again", which is exactly the behavior of
> nonblocking read.
Yes it seems so.

I do always separately switch to the nonblocking mode before.
> 
> 
> 2013/4/17 Rainer Stratmann 
> 
> >  On Wednesday 17 April 2013 09:17:09 you wrote:
> > > Will this be a CPU hog:
> > > 
> > > t := Now;
> > > while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
> > > 
> > >   if Now - t > 0.1 * timeout then Break;   // approx. 
> > 
> > seconds
> > 
> > > end;
> > > 
> > > Thanks
> > 
> > I did not read the whole thread, but that you favorite blocking mode
> > (which I
> > don't use).
> > 
> > For MSG_DONTWAIT as far I know you have to change to the nonblocking
> > mode.
> > 
> > > 2013/4/16 Luca Olivetti 
> > > 
> > > > Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
> > > > > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
> > > > >> How can I set the connection and read/write timeout when using
> > 
> > socket
> > 
> > > > >> in free pascal?
> > > > > 
> > > > > I seem to remember that synapse can do this.
> > > > 
> > > > Only in svn and it does it this way
> > > > 
> > > > if FConnectionTimeout > 0 then
> > > > begin
> > > > 
> > > >   // connect in non-blocking mode
> > > >   b := NonBlockMode;
> > > >   NonBlockMode := true;
> > > >   SockCheck(synsock.Connect(FSocket, Sin));
> > > >   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK)
> > 
> > then
> > 
> > > > if not CanWrite(FConnectionTimeout) then
> > > > 
> > > >   FLastError := WSAETIMEDOUT;
> > > >   
> > > >   NonBlockMode := b;
> > > > 
> > > > end
> > > > else
> > > > 
> > > >   SockCheck(synsock.Connect(FSocket, Sin));
> > > > 
> > > > NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
> > > > WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
> > > > CanWrite  does an fpSelect
> > > > 
> > > > Bye
> > > > --
> > > > Luca
> > > > 
> > > > ___
> > > > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> > 
> > ___
> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] socket timeout

2013-04-17 Thread Fabio Luis Girardi
For connect, I wrote a unit that implements a connect timeout, see:

http://sourceforge.net/p/pascalscada/code/HEAD/tree/trunk/src/scada/sockets_w32_w64.pas#l70

or

http://sourceforge.net/p/pascalscada/code/HEAD/tree/trunk/src/scada/sockets_unix.pas#l48

If you want work in blocking mode after connect, do something like this:


fsocket = {$IFDEF WINDOWS}Socket{$ELSE}fpSocket{$ENDIF}(PF_INET,
SOCK_STREAM, IPPROTO_TCP)

//set socket options.

setblockingmode(fsocket,MODE_NONBLOCKING);

if connect_with_timeout(focket,@channel,sizeof(channel),FTimeoutInMs)<>0
then begin
  //check errors
end;

setblockingmode(FSocket,MODE_BLOCKING);

2013/4/17 Rainer Stratmann :
>  On Wednesday 17 April 2013 10:22:58 you wrote:
>> I thought MSG_DONTWAIT is actually the flag to switch to nonblocking mode,
>> isn't it?
> May be.
>> As a matter of fact, the fprecv() above would get a result of -1
>> and a sockterror of "Try Again", which is exactly the behavior of
>> nonblocking read.
> Yes it seems so.
>
> I do always separately switch to the nonblocking mode before.
>>
>>
>> 2013/4/17 Rainer Stratmann 
>>
>> >  On Wednesday 17 April 2013 09:17:09 you wrote:
>> > > Will this be a CPU hog:
>> > >
>> > > t := Now;
>> > > while fprecv(s, @buf, buf_len, MSG_DONTWAIT) < 0 do begin
>> > >
>> > >   if Now - t > 0.1 * timeout then Break;   // approx. 
>> >
>> > seconds
>> >
>> > > end;
>> > >
>> > > Thanks
>> >
>> > I did not read the whole thread, but that you favorite blocking mode
>> > (which I
>> > don't use).
>> >
>> > For MSG_DONTWAIT as far I know you have to change to the nonblocking
>> > mode.
>> >
>> > > 2013/4/16 Luca Olivetti 
>> > >
>> > > > Al 16/04/13 12:20, En/na Michael Schnell ha escrit:
>> > > > > On 04/16/2013 11:26 AM, Xiangrong Fang wrote:
>> > > > >> How can I set the connection and read/write timeout when using
>> >
>> > socket
>> >
>> > > > >> in free pascal?
>> > > > >
>> > > > > I seem to remember that synapse can do this.
>> > > >
>> > > > Only in svn and it does it this way
>> > > >
>> > > > if FConnectionTimeout > 0 then
>> > > > begin
>> > > >
>> > > >   // connect in non-blocking mode
>> > > >   b := NonBlockMode;
>> > > >   NonBlockMode := true;
>> > > >   SockCheck(synsock.Connect(FSocket, Sin));
>> > > >   if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK)
>> >
>> > then
>> >
>> > > > if not CanWrite(FConnectionTimeout) then
>> > > >
>> > > >   FLastError := WSAETIMEDOUT;
>> > > >
>> > > >   NonBlockMode := b;
>> > > >
>> > > > end
>> > > > else
>> > > >
>> > > >   SockCheck(synsock.Connect(FSocket, Sin));
>> > > >
>> > > > NonBlockMode in turn uses fpIoCtl with the FIONBIO parameter,
>> > > > WSAEINPROGRESS=EsysEINPROGRESS, WSAEWOULDBLOCK=EsysEWOULDBLOCK and
>> > > > CanWrite  does an fpSelect
>> > > >
>> > > > Bye
>> > > > --
>> > > > Luca
>> > > >
>> > > > ___
>> > > > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
>> > > > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>> >
>> > ___
>> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
>> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



-- 
The best regards,

Fabio Luis Girardi
PascalSCADA Project
http://sourceforge.net/projects/pascalscada
http://www.pascalscada.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] How can retrive value from OUT parameter?

2013-04-17 Thread Toru Takubo

Hi All,

I have an application build with Delphi7+ADO connecting
to MSSQL database, and planning to migrate to FPC+SQLdb.

It has many stored procedures which have OUT parameters
to retrieve value from database. I am trying to migrate
by using TMSSQLConnection+TSQLQuery, but still I can not
settle it. I can execute and pass values to stored procedures,
but not the other way. The RETURN_VALUE (default result)
can not be retrieved either.

I would appreciate any advice.

Toru


 
 
___

fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Bending System.IndexByte to my will!!?

2013-04-17 Thread Reinier Olislagers
Hi all,

(FPC 2.6.2 x86, trunk x64, on Windows; found similar behaviour on Linux x64)

Busy getting DBase III memo support correct ;)

In fcl-db\src\dbase\dbf_common.pas we find this part used to e.g. find
end of file ($1A/ASCII 26) markers in a buffer with memo data: [1]

The problem is: the first MemScan function doesn't work:
System.IndexByte just always return -1 even if the character is there.
Tried system.indexbyte with a simple test program and of course it worked.
If I comment out $ifdef fpc to force use of the second function, the $1A
is found perfectly.

Where lies the problem?

Thanks,
Reinier

[1]
{$ifdef FPC}
function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
var
  I: Integer;
begin
  I := System.IndexByte(Buffer, Length, Chr);
  if I = -1 then
Result := nil
  else
Result := Buffer+I;
end;

{$else}

function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
asm
PUSHEDI
MOV EDI,Buffer
MOV AL, Chr
MOV ECX,Length
REPNE   SCASB
MOV EAX,0
JNE @@1
MOV EAX,EDI
DEC EAX
@@1:POP EDI
end;

{$endif}
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Bending System.IndexByte to my will!!?

2013-04-17 Thread Jeppe Græsdal Johansen

Den 18-04-2013 07:57, Reinier Olislagers skrev:

Hi all,

(FPC 2.6.2 x86, trunk x64, on Windows; found similar behaviour on Linux x64)

Busy getting DBase III memo support correct ;)

In fcl-db\src\dbase\dbf_common.pas we find this part used to e.g. find
end of file ($1A/ASCII 26) markers in a buffer with memo data: [1]

The problem is: the first MemScan function doesn't work:
System.IndexByte just always return -1 even if the character is there.
Tried system.indexbyte with a simple test program and of course it worked.
If I comment out $ifdef fpc to force use of the second function, the $1A
is found perfectly.

Where lies the problem?

Thanks,
Reinier

[1]
{$ifdef FPC}
function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
var
   I: Integer;
begin
   I := System.IndexByte(Buffer, Length, Chr);
   if I = -1 then
 Result := nil
   else
 Result := Buffer+I;
end;

{$else}

function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
asm
 PUSHEDI
 MOV EDI,Buffer
 MOV AL, Chr
 MOV ECX,Length
 REPNE   SCASB
 MOV EAX,0
 JNE @@1
 MOV EAX,EDI
 DEC EAX
@@1:POP EDI
end;

{$endif}

Since you have a typed const pointer instead of an untyped const 
parameter, you need to do this:


System.IndexByte(PByte(Buffer)^, Length, Chr);

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Bending System.IndexByte to my will!!?

2013-04-17 Thread Reinier Olislagers
On 18-4-2013 8:14, Jeppe Græsdal Johansen wrote:
> Den 18-04-2013 07:57, Reinier Olislagers skrev:
>> In fcl-db\src\dbase\dbf_common.pas we find this part used to e.g. find
>> end of file ($1A/ASCII 26) markers in a buffer with memo data: [1]
>>
>> The problem is: the first MemScan function doesn't work:
>> System.IndexByte just always return -1 even if the character is there.
>> Tried system.indexbyte with a simple test program and of course it
>> worked.
>> If I comment out $ifdef fpc to force use of the second function, the $1A
>> is found perfectly.
>>
>> Where lies the problem?

> Since you have a typed const pointer instead of an untyped const
> parameter, you need to do this:
> 
> System.IndexByte(PByte(Buffer)^, Length, Chr);
> 

Thanks a lot, that works beautifully!

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to use TThread?

2013-04-17 Thread Antonio Fortuny

  
  
First of all change the order of lines 25-26
      inherited Create(False);
      FreeOnTerminate := True;
  
  instead of
      FreeOnTerminate := True;
      inherited Create(False);
  
  The, drop the DoExecute procedure and replace it by the Execute
  procedure. It is useless to Synchronize a thread's procedure
  inside itself !
  After the creation, the thread executes immediately the overriden
  procedure Execute because, at creation time (inherited
  Create(False); ) the thread is created in the state NON SUSPENDED.
  The use of the DoExecute is obviously useless
  our program will execute the procedure Excute only once as there
  is no loop.
  
  
  

  




   Antonio
  Fortuny
Senior Software engineer

220, avenue de la Liberté
L-4602 Niederkorn
Tel.: +352 58 00 93 - 93
www.sitasoftware.lu
  




  

  
  Le 18/04/2013 07:03, silvioprog a écrit :


  Hi,


I tried to use TThread in a small sample, but it don't
  works. The code is very simple, and I'm sending it in
  attached.


Thanks,

  
  
  -- 
  Silvio Clécio
  My public projects - github.com/silvioprog

  
  
  
  
  ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal