Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Michael Van Canneyt



On Thu, 25 Apr 2013, silvioprog wrote:


2013/4/25 Michael Van Canneyt mich...@freepascal.org
  [...]
Well, ssockets is very low level.

fpselect() is mostly useful when you combine multiple file descriptors at once. 
Although it can be done, IMHO it makes little sense to create a select() method 
on the socket stream,
since it would only have one socket handle.

You can perfectly do a fpselect() with the handles of the streams that ssockets 
uses.

Michael.


Nice.

The socket of Delphi and Synapse implements WaitForData:

function TWinSocketStream.WaitForData(Timeout: Longint): Boolean;
var
  FDSet: TFDSet;
  TimeVal: TTimeVal;
begin
  TimeVal.tv_sec := Timeout div 1000;
  TimeVal.tv_usec := (Timeout mod 1000) * 1000;
  FD_ZERO(FDSet);
  FD_SET(FSocket.SocketHandle, FDSet);
  Result := select(0, @FDSet, nil, nil, @TimeVal)  0;
end;

I do not know where it would be used, it's just an observation hehe...


Yes, but the above is what I mean with 'it does not make much sense'.

I can easily add this - in fact I will do so, but with multiple sockets 
it is better to combine the waitfordata()


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

Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Ludo Brands
On 04/26/2013 08:58 AM, Michael Van Canneyt wrote:
 
 
 On Thu, 25 Apr 2013, silvioprog wrote:
 
 I do not know where it would be used, it's just an observation hehe...
 
 Yes, but the above is what I mean with 'it does not make much sense'.
 
 I can easily add this - in fact I will do so, but with multiple sockets
 it is better to combine the waitfordata()
 

In blocking mode the select is vital if you want to do simultaneous read
and write on the same socket in the same thread. Otherwise you are
simply blocking the thread in a recv when nothing comes in or in a send
when the socket buffer is not empty. Note that select also returns when
an exception occurs.

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Michael Van Canneyt



On Fri, 26 Apr 2013, Ludo Brands wrote:


On 04/26/2013 08:58 AM, Michael Van Canneyt wrote:



On Thu, 25 Apr 2013, silvioprog wrote:


I do not know where it would be used, it's just an observation hehe...


Yes, but the above is what I mean with 'it does not make much sense'.

I can easily add this - in fact I will do so, but with multiple sockets
it is better to combine the waitfordata()



In blocking mode the select is vital if you want to do simultaneous read
and write on the same socket in the same thread. Otherwise you are
simply blocking the thread in a recv when nothing comes in or in a send
when the socket buffer is not empty. Note that select also returns when
an exception occurs.


I am aware of all this. 
My only 'objection' is that waitfordata() will operate on a single socket only.

Good for single client, bad for server.

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said:
  when the socket buffer is not empty. Note that select also returns when
  an exception occurs.
 
 I am aware of all this. 
 My only 'objection' is that waitfordata() will operate on a single socket 
 only.
 Good for single client, bad for server.

How many open sockets must you have to qualify as a server?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Ludo Brands
On 04/26/2013 09:19 AM, Michael Van Canneyt wrote:
 
 
 On Fri, 26 Apr 2013, Ludo Brands wrote:
 
 On 04/26/2013 08:58 AM, Michael Van Canneyt wrote:


 On Thu, 25 Apr 2013, silvioprog wrote:

 I do not know where it would be used, it's just an observation hehe...

 Yes, but the above is what I mean with 'it does not make much sense'.

 I can easily add this - in fact I will do so, but with multiple sockets
 it is better to combine the waitfordata()


 In blocking mode the select is vital if you want to do simultaneous read
 and write on the same socket in the same thread. Otherwise you are
 simply blocking the thread in a recv when nothing comes in or in a send
 when the socket buffer is not empty. Note that select also returns when
 an exception occurs.
 
 I am aware of all this. 

My message is meant for the OP who wants to do simultaneous read/write
on the socket in one thread and doesn't know what the use of select is.
The 'it does not make much sense' is in that context misleading the OP
and some more explanation was needed;)

Ludo

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Michael Van Canneyt



On Fri, 26 Apr 2013, Marco van de Voort wrote:


In our previous episode, Michael Van Canneyt said:

when the socket buffer is not empty. Note that select also returns when
an exception occurs.


I am aware of all this.
My only 'objection' is that waitfordata() will operate on a single socket only.
Good for single client, bad for server.


How many open sockets must you have to qualify as a server?


Well, you can't get more than ~ 65000 so lets go for half of that :-)

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


Re: [fpc-pascal] Statically link library

2013-04-26 Thread Darius Blaszyk

On Apr 26, 2013, at 1:37 AM, Paul Breneman wrote:

 
 Yes it does find them, the statically libraries are linked into an 
 executable which works fine. That is why I was surprised. I'm sure MinGW 
 must link to other libraries as well. The question though is which. Anyway 
 to find out for a simple example project executable?
 
 http://www.dependencywalker.com/
 ___
 
Will have a look, although at first sight it seems to find dynamic libraries. I 
need to check the static ones as well.

Regards, Darius

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said:
  I am aware of all this.
  My only 'objection' is that waitfordata() will operate on a single socket 
  only.
  Good for single client, bad for server.
 
  How many open sockets must you have to qualify as a server?
 
 Well, you can't get more than ~ 65000 so lets go for half of that :-)

I maybe have cut explanation short a bit, but I meant that not all servers
are internet facing high load ones, where single thread per connection is a
mortal sin.


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


Re: [fpc-pascal] Statically link library

2013-04-26 Thread Ludo Brands
On 04/26/2013 09:54 AM, Darius Blaszyk wrote:
 
 On Apr 26, 2013, at 1:37 AM, Paul Breneman wrote:
 

 Yes it does find them, the statically libraries are linked into an 
 executable which works fine. That is why I was surprised. I'm sure MinGW 
 must link to other libraries as well. The question though is which. Anyway 
 to find out for a simple example project executable?

 http://www.dependencywalker.com/
 ___

 Will have a look, although at first sight it seems to find dynamic libraries. 
 I need to check the static ones as well.
 

Pass -M or --print-map to ld to get a memory map. It includes all object
files included.

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


Re: [fpc-pascal] Statically link library

2013-04-26 Thread Ludo Brands
On 04/26/2013 10:19 AM, Ludo Brands wrote:

 
 Pass -M or --print-map to ld to get a memory map. It includes all object
 files included.
 
On my system it shows that open and close are from
MinGW32/lib/libmoldname.a
and a
 undefined reference to `filesize'

Ludo

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread silvioprog
2013/4/26 Ludo Brands ludo.bra...@free.fr

 On 04/26/2013 08:58 AM, Michael Van Canneyt wrote:
  On Thu, 25 Apr 2013, silvioprog wrote:
 
  I do not know where it would be used, it's just an observation hehe...
 
  Yes, but the above is what I mean with 'it does not make much sense'.
 
  I can easily add this - in fact I will do so, but with multiple sockets
  it is better to combine the waitfordata()
 

 In blocking mode the select is vital if you want to do simultaneous read
 and write on the same socket in the same thread. Otherwise you are
 simply blocking the thread in a recv when nothing comes in or in a send
 when the socket buffer is not empty. Note that select also returns when
 an exception occurs.

 Ludo


Exactly. In my small sample, when no buffer is received from server, the
process stays blocked on:

https://bitbucket.org/silvioprog/tcpipcomp/src/f42be14db1e74d750fa88d6b4554b209145ff589/src/tcpipclient.pas?at=master#cl-189

-- 
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

Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread silvioprog
2013/4/26 Michael Schnell mschn...@lumino.de

 On 04/25/2013 06:15 PM, silvioprog wrote:

 Yes, OnDisconnect, it works exactly as you explained. But I also have the
 OnError event, which is useful when the client is terminated by an error
 (eg. killing the client via Ctrl+Alt+Del). :)


 It might be able to detect a certain kind of errors.

 Nonetheless, errors only arise when in fact communication is running. A
 socket stays open forever, if no communication is executed at all, thus a
 broken link in between stays undetected.

 To detect a broken link you need to do a regular life check communication.


Pefectly. I'm trying to implement it. :)

-- 
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

Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread silvioprog
2013/4/26 Ludo Brands ludo.bra...@free.fr

 On 04/26/2013 09:19 AM, Michael Van Canneyt wrote:
  On Fri, 26 Apr 2013, Ludo Brands wrote:
 
  On 04/26/2013 08:58 AM, Michael Van Canneyt wrote:
 
 
  On Thu, 25 Apr 2013, silvioprog wrote:
 
  I do not know where it would be used, it's just an observation hehe...
 
  Yes, but the above is what I mean with 'it does not make much sense'.
 
  I can easily add this - in fact I will do so, but with multiple sockets
  it is better to combine the waitfordata()
 
 
  In blocking mode the select is vital if you want to do simultaneous read
  and write on the same socket in the same thread. Otherwise you are
  simply blocking the thread in a recv when nothing comes in or in a send
  when the socket buffer is not empty. Note that select also returns when
  an exception occurs.
 
  I am aware of all this.

 My message is meant for the OP who wants to do simultaneous read/write
 on the socket in one thread and doesn't know what the use of select is.
 The 'it does not make much sense' is in that context misleading the OP
 and some more explanation was needed;)

 Ludo



Ludo, a small question

So, In loop of my thread, to the process doesn't stay blocked in recv, I
need to use select in client too?

-- 
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

Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread Ludo Brands
On 04/26/2013 07:06 PM, silvioprog wrote:

 Ludo, a small question
 
 So, In loop of my thread, to the process doesn't stay blocked in recv, I
 need to use select in client too?
 

If your socket is in blocking mode and you don't want your thread to
block, yes. Server or client, there is no difference.
The same for send. When you have a small block to send that fits in the
socket buffer and the socket buffer is empty, send will return
immediately. But if you have more data to send, your second send will
block until the first send is completed.
The same select can be used to return when the recv buffer is not empty
or the send buffer empty  or when an exception occurs. See
http://linux.die.net/man/2/select

Ludo

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


Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.

2013-04-26 Thread silvioprog
Select in socket of Delphi 2007 (a friend sent it to me:
http://www.sendspace.com/file/06ev02):

function TBaseSocket.Select(ReadReady, WriteReady, ExceptFlag: PBoolean;
TimeOut: Integer): Boolean;
var
  ReadFds: TFDset;
  ReadFdsptr: PFDset;
  WriteFds: TFDset;
  WriteFdsptr: PFDset;
  ExceptFds: TFDset;
  ExceptFdsptr: PFDset;
  tv: timeval;
  Timeptr: PTimeval;
begin
  Result := False;
  if Active then
  begin
if Assigned(ReadReady) then
begin
  ReadFdsptr := @ReadFds;
  FD_ZERO(ReadFds);
  FD_SET(FSocket, ReadFds);
end
else
  ReadFdsptr := nil;
if Assigned(WriteReady) then
begin
  WriteFdsptr := @WriteFds;
  FD_ZERO(WriteFds);
  FD_SET(FSocket, WriteFds);
end
else
  WriteFdsptr := nil;
if Assigned(ExceptFlag) then
begin
  ExceptFdsptr := @ExceptFds;
  FD_ZERO(ExceptFds);
  FD_SET(FSocket, ExceptFds);
end
else
  ExceptFdsptr := nil;
if TimeOut = 0 then
begin
  tv.tv_sec := TimeOut div 1000;
  tv.tv_usec :=  1000 * (TimeOut mod 1000);
  Timeptr := @tv;
end
else
  Timeptr := nil;
Try
{$IFDEF MSWINDOWS}
  Result := ErrorCheck(WinSock.select(FSocket + 1, ReadFdsptr,
WriteFdsptr, ExceptFdsptr, Timeptr))  0;
{$ENDIF}
{$IFDEF LINUX}
  Result := ErrorCheck(Libc.select(FSocket + 1, ReadFdsptr,
WriteFdsptr, ExceptFdsptr, Timeptr))  0;
{$ENDIF}
except
  Result := False;
end;
if Assigned(ReadReady) then
  ReadReady^ := FD_ISSET(FSocket, ReadFds);
if Assigned(WriteReady) then
  WriteReady^ := FD_ISSET(FSocket, WriteFds);
if Assigned(ExceptFlag) then
  ExceptFlag^ := FD_ISSET(FSocket, ExceptFds);
  end;
end;

-- 
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] FPC_JVM compilation fails on trunk

2013-04-26 Thread Torsten Bonde Christiansen

Hi List.

I'm trying to follow this guide: http://wiki.freepascal.org/FPC_JVM/Building

But when i reach the point where i do the actual compilation fail
with the following output:

torsten@epidata:~/FreePascal/fpc-trunk$ make all crossinstall 
CROSSOPT=-O2 -g CPU_TARGET=jvm OS_TARGET=android INSTALL_PREFIX=~/fpc

make: -iVSPTPSOTO: Command not found
make compiler_cycle RELEASE=1
make[1]: -iVSPTPSOTO: Command not found
make[1]: Entering directory `/home/torsten/FreePascal/fpc-trunk'
make -C compiler cycle
make[2]: -iVSPTPSOTO: Command not found
make[2]: Entering directory `/home/torsten/FreePascal/fpc-trunk/compiler'
make OS_TARGET= CPU_TARGET= CROSSBINDIR= BINUTILSPREFIX= 
CROSSCYCLEBOOTSTRAP=1 rtlclean rtl CYCLELEVEL=1

make[3]: Entering directory `/home/torsten/FreePascal/fpc-trunk/compiler'
make -C  clean
make: Entering an unknown directory
make: *** clean: No such file or directory.  Stop.
make: Leaving an unknown directory
make[3]: *** [rtlclean] Error 2
make[3]: Leaving directory `/home/torsten/FreePascal/fpc-trunk/compiler'
make[2]: *** [cycle] Error 2
make[2]: Leaving directory `/home/torsten/FreePascal/fpc-trunk/compiler'
make[1]: *** [compiler_cycle] Error 2
make[1]: Leaving directory `/home/torsten/FreePascal/fpc-trunk'
make: *** [base.build-stamp.jvm-android] Error 2
torsten@epidata:~/FreePascal/fpc-trunk$


I'm using the 2.6.2 compiler and i have successfully compiled a new 
fpcmake, placed it

such that I know it is first in the path, but still it fails.

Any help is appriciated.

Regards,
Torsten B. Christiansen.

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


Re: [fpc-pascal] FPC_JVM compilation fails on trunk

2013-04-26 Thread Jonas Maebe

On 26 Apr 2013, at 22:37, Torsten Bonde Christiansen wrote:

 I'm trying to follow this guide: http://wiki.freepascal.org/FPC_JVM/Building
 
 But when i reach the point where i do the actual compilation fail
 with the following output:
 
 torsten@epidata:~/FreePascal/fpc-trunk$ make all crossinstall CROSSOPT=-O2 
 -g CPU_TARGET=jvm OS_TARGET=android INSTALL_PREFIX=~/fpc

This command does not match what is written on the wiki page you refer to above.

 make: -iVSPTPSOTO: Command not found

This means that no fpc binary can be found in the path. This error is unrelated 
to building the JVM compiler specifically, it will happen regardless of what 
kind of compiler you try to build. Did you perform a standard installation of 
FPC 2.6.2 and is its installation directory in your path? 

Additionally, the merge of the 8086 branch broke several things in the compiler 
(but that's unrelated to the error you get above), so you may encounter other 
errors once you fix your configuration. For now, I would recommend sticking to 
r24323 of trunk (regardless of which platform you use).


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

Re: [fpc-pascal] FPC_JVM compilation fails on trunk

2013-04-26 Thread Torsten Bonde Christiansen

On 2013-04-26 22:53, Jonas Maebe wrote:


On 26 Apr 2013, at 22:37, Torsten Bonde Christiansen wrote:

I'm trying to follow this 
guide:http://wiki.freepascal.org/FPC_JVM/Building


But when i reach the point where i do the actual compilation fail
with the following output:

torsten@epidata:~/FreePascal/fpc-trunk$ make all crossinstall 
CROSSOPT=-O2 -g CPU_TARGET=jvm OS_TARGET=android INSTALL_PREFIX=~/fpc


This command does not match what is written on the wiki page you refer 
to above.
True, but i thought that the order of defines and make targets didn't 
matte? The only other part i left out was the FPCMAKE, but since
the fpcmake i created i now located where the old one used to be I do 
not think that should matter either?



make: -iVSPTPSOTO: Command not found


This means that no fpc binary can be found in the path. This error is 
unrelated to building the JVM compiler specifically, it will happen 
regardless of what kind of compiler you try to build. Did you perform 
a standard installation of FPC 2.6.2 and is its installation directory 
in your path?
I build fpc from scratch with my own settings, but all is installed into 
~/fpc/...
My path contains ~/fpc/bin in which i symlink to the different compilers 
and crosscompilers.


Additionally, the merge of the 8086 branch broke several things in the 
compiler (but that's unrelated to the error you get above), so you may 
encounter other errors once you fix your configuration. For now, I 
would recommend sticking to r24323 of trunk (regardless of which 
platform you use).


I downgraded to r24323, but still the same issue, even when reordering 
the defines and make targets. The actual error from make seem to be 
this  though:


make[3]: Entering directory `/home/torsten/FreePascal/fpc-trunk/compiler'
make -C  clean  === clean is not a director, perhaps it is a target?
make: Entering an unknown directory
make: *** clean: No such file or directory.  Stop.
make: Leaving an unknown directory


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

Re: [fpc-pascal] FPC_JVM compilation fails on trunk

2013-04-26 Thread Jonas Maebe

On 26 Apr 2013, at 23:38, Torsten Bonde Christiansen wrote:

 On 2013-04-26 22:53, Jonas Maebe wrote:
 
 On 26 Apr 2013, at 22:37, Torsten Bonde Christiansen wrote:
 
 I'm trying to follow this guide:http://wiki.freepascal.org/FPC_JVM/Building
 
 But when i reach the point where i do the actual compilation fail
 with the following output:
 
 torsten@epidata:~/FreePascal/fpc-trunk$ make all crossinstall CROSSOPT=-O2 
 -g CPU_TARGET=jvm OS_TARGET=android INSTALL_PREFIX=~/fpc
 
 This command does not match what is written on the wiki page you refer to 
 above.
 True, but i thought that the order of defines and make targets didn't matte? 
 The only other part i left out was the FPCMAKE, but since
 the fpcmake i created i now located where the old one used to be I do not 
 think that should matter either?

Yes, then it should not matter.

 make: -iVSPTPSOTO: Command not found
 
 This means that no fpc binary can be found in the path. This error is 
 unrelated to building the JVM compiler specifically, it will happen 
 regardless of what kind of compiler you try to build. Did you perform a 
 standard installation of FPC 2.6.2 and is its installation directory in your 
 path?
 I build fpc from scratch with my own settings,

That is not supported. Only official full install are supported. The reason is 
because otherwise you run into problems like the ones you are having.

 but all is installed into ~/fpc/...
 My path contains ~/fpc/bin in which i symlink to the different compilers and 
 crosscompilers.

The question was whether you have an fpc binary in your path (i.e., a program 
literally called fpc). If not, you have to explicitly specify the compiler to 
use via FPC=/full/path/to/ppc386 (or ppcx64, or ppcppc, etc depending on what 
your host platform is).

But again: only full official FPC installs are supported. If you keep getting 
problems, or ever have problems again in the future, please first install an 
official FPC release and try again. If you absolutely insist on not doing that 
(please do it anyway), at the very least mention that in every request for help 
when something doesn't work.


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