[fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29/04/2013 17:58, waldo kitty wrote: On 4/29/2013 06:04, Reinier Olislagers wrote: On 29-4-2013 11:50, Lukasz Sokol wrote: On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barthpascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org mailto:pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org On 26.04.2013 21:38, silvioprog wrote: Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. What? The link that shows 404 page not found? Or the actual content? the original message had a link and the actual code... deleting the link is one thing but the code is already distributed around the world and cannot be deleted by the OP... I guess the devs don't use gmane so they can just cat /dev/urandom the mailbox file with the offending code ;) 3 times ;) interleaved with cat /dev/zero ;) same for the owner of the forum server if it got there. as for the rest of us, we should be fine as long as Silvio's answer won't pop up or be referenced anywhere, so e.g. google won't index it somewhere visible... which probably is why we should end this thread immediately ;) L. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Odyssey: SSockets and Threads.
On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldra...@googlemail.com mailto:pascaldra...@googlemail.com On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/__06ev02 http://www.sendspace.com/file/06ev02): Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Regards, Sven Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. L. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29-4-2013 11:50, Lukasz Sokol wrote: On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org mailto:pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org On 26.04.2013 21:38, silvioprog wrote: Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. What? The link that shows 404 page not found? Or the actual content? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29/04/2013 11:04, Reinier Olislagers wrote: On 29-4-2013 11:50, Lukasz Sokol wrote: On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org mailto:pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org On 26.04.2013 21:38, silvioprog wrote: Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. What? The link that shows 404 page not found? Or the actual content? Your post to the mailing list, now is stored in NNTP system (at least in gmane)... L. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29-4-2013 14:10, Lukasz Sokol wrote: On 29/04/2013 11:04, Reinier Olislagers wrote: On 29-4-2013 11:50, Lukasz Sokol wrote: On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org mailto:pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org On 26.04.2013 21:38, silvioprog wrote: Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. What? The link that shows 404 page not found? Or the actual content? Your post to the mailing list, now is stored in NNTP system (at least in gmane)... I understand, but the problematic part was an upload to a third party site which has been deleted long since. So even browsing gmane/other archives, there's nothing left to see... ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29 Apr 2013, at 14:12, Reinier Olislagers wrote: I understand, but the problematic part was an upload to a third party site which has been deleted long since. So even browsing gmane/other archives, there's nothing left to see... He also posted one of the Delphi functions to the list itself: http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg32794.html Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29-4-2013 14:41, Jonas Maebe wrote: On 29 Apr 2013, at 14:12, Reinier Olislagers wrote: I understand, but the problematic part was an upload to a third party site which has been deleted long since. So even browsing gmane/other archives, there's nothing left to see... He also posted one of the Delphi functions to the list itself: Ah :( ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 4/29/2013 06:04, Reinier Olislagers wrote: On 29-4-2013 11:50, Lukasz Sokol wrote: On 27/04/2013 16:06, silvioprog wrote: 2013/4/27 Sven Barthpascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org mailto:pascaldragon-gM/ye1e23mwn+bqq9rb...@public.gmane.org On 26.04.2013 21:38, silvioprog wrote: Oopppss, sorry. I'll delete it. :X Too late, gmane mail to news already stored it too. What? The link that shows 404 page not found? Or the actual content? the original message had a link and the actual code... deleting the link is one thing but the code is already distributed around the world and cannot be deleted by the OP... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. ___ 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/4/29 Jonas Maebe jonas.ma...@elis.ugent.be On 29 Apr 2013, at 14:12, Reinier Olislagers wrote: I understand, but the problematic part was an upload to a third party site which has been deleted long since. So even browsing gmane/other archives, there's nothing left to see... He also posted one of the Delphi functions to the list itself: http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg32794.html Jonas Well, I messed up badly, sorry again. I don't know if that would solve the problem, but if they prefer, we can delete me from the FPC lists, because I have no intention to piracy. Will be discretion of yours guys. x( -- 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.
On 4/29/2013 13:29, silvioprog wrote: Well, I messed up badly, sorry again. I don't know if that would solve the problem, but if they prefer, we can delete me from the FPC lists, because I have no intention to piracy. Will be discretion of yours guys. x( speaking only for myself: i think you have learned the lesson and there's no reason to kick you out of these lists... what others do to clean up the mistake on their systems is up to them. of course... there may be a method to have the article cancelled from gmane and the other news servers that propagate the list in news format... the question is if the cancelmsg will propagate thru those news servers and be honored... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 29 Apr 2013, at 19:29, silvioprog wrote: I don't know if that would solve the problem, but if they prefer, we can delete me from the FPC lists, because I have no intention to piracy. I know you don't, and there's definitely no way you will be removed from the list because you simply made a mistake. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/06ev02): Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Regards, Sven ___ 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/4/27 Sven Barth pascaldra...@googlemail.com On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/**06ev02http://www.sendspace.com/file/06ev02 ): Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Regards, Sven Oopppss, sorry. I'll delete it. :X -- 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.
On 4/27/2013 11:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldra...@googlemail.com mailto:pascaldra...@googlemail.com On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/__06ev02: Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Oopppss, sorry. I'll delete it. :X you can't delete it from everywhere... eg: systems that download this _mailing_list_ as separate emails into whatever mail reading tool is used... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. ___ 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/4/27 waldo kitty wkitt...@windstream.net On 4/27/2013 11:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldra...@googlemail.com mailto:pascaldragon@**googlemail.com pascaldra...@googlemail.com On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/**__06ev02http://www.sendspace.com/file/__06ev02 : Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Oopppss, sorry. I'll delete it. :X you can't delete it from everywhere... eg: systems that download this _mailing_list_ as separate emails into whatever mail reading tool is used... -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. From the SendSpace yes. Try to download it now. ;) -- 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.
On 4/27/2013 13:51, silvioprog wrote: 2013/4/27 waldo kitty wkitt...@windstream.net mailto:wkitt...@windstream.net On 4/27/2013 11:06, silvioprog wrote: 2013/4/27 Sven Barth pascaldra...@googlemail.com On 26.04.2013 21:38, silvioprog wrote: Select in socket of Delphi 2007 (a friend sent it to me: http://www.sendspace.com/file/06ev02: Gaahhh!!! Don't simply send Delphi code to this list! Did you ever heard of stuff like clean room reverse engineeering?! Oopppss, sorry. I'll delete it. :X you can't delete it from everywhere... eg: systems that download this _mailing_list_ as separate emails into whatever mail reading tool is used... From the SendSpace yes. Try to download it now. ;) what SendSpace?? i've never heard of it... the code came in /inside/ your posting... [time passes] there was a link to the code in your post, yes... but you also posted the actual code, too...[/time passes] my example explicitly points to local storage in a email client, as well... if you or anyone can delete posts from my local email storage from remote, i'd definitely like to know about it :P -- NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
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.
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.
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.
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.
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.
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] Re: Odyssey: SSockets and Threads.
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] Re: Odyssey: SSockets and Threads.
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/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/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.
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.
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
Re: [fpc-pascal] Re: Odyssey: SSockets and Threads.
On 04/24/2013 10:21 PM, silvioprog wrote: 2013/4/24 silvioprog silviop...@gmail.com mailto:silviop...@gmail.com Hello, There are a multi-thread example using SSockets in FPC? I'm trying to implement it*, but it's very hard and this work it's consuming all my time. The difficulty is to read and write at the same time. I'm almost certain that using SSockets, I would have to create one socket for writing and one for reading, separately by threads. Thank you! * https://bitbucket.org/silvioprog/tcpipcomp (this repo is temporary, and this all code can undergo drastic changes at any time) ... like ScktComp of Delphi. (no Synapse, LNet or Indy please, I need to use native code) what is the problem with using Synapse, LNet or Indy? Seen the questions you are asking I would suggest you use an existing library and stay away from writing your own socket library or start with learning the basics of socket programming. SOCK_STREAM sockets are full duplex and you can read and write simultaneously on them, even without threading if you use non blocking mode. SSocket has a Property NonBlocking but I don't see any code that handles the EAGAIN or EWOULDBLOCK errors. That is probably left to the user of TSocketStream to deal with. So SSocket is a really thin layer that leaves the user with all the problems you are trying to solve. 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.
On Wed, 24 Apr 2013, silvioprog wrote: 2013/4/24 silvioprog silviop...@gmail.com Hello, There are a multi-thread example using SSockets in FPC? I'm trying to implement it*, but it's very hard and this work it's consuming all my time. The difficulty is to read and write at the same time. I'm almost certain that using SSockets, I would have to create one socket for writing and one for reading, separately by threads. Why is that ? Please define read and write at the same time first. Thank you! * https://bitbucket.org/silvioprog/tcpipcomp (this repo is temporary, and this all code can undergo drastic changes at any time) ... like ScktComp of Delphi. (no Synapse, LNet or Indy please, I need to use native code) Strange remark. Synapse, lnet or Indy are native pascal code. 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.
On 04/24/2013 10:21 PM, silvioprog wrote: (no Synapse, LNet or Indy please, I need to use native code) Indy does provide support for threading (as does AsyncPro, the Socket flavor of which could be of interest here). But I don't know if it's easy to use Indy with Lazarus, and I know that there is no Lazarus port for AsyncPro yet (even though it is open Source and especially the COM-Port flavor is requested rather often). -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/4/25 Ludo Brands ludo.bra...@free.fr [...] what is the problem with using Synapse, LNet or Indy? Seen the questions you are asking I would suggest you use an existing library and stay away from writing your own socket library or start with learning the basics of socket programming. There no problem. Zeos has various features, auto-commit, script-executor, monitor etc.., But I prefer using SQLdb even when SQLdb was starting. :) I'm not trying to write a library. I'm trying to solve a problem but using native units of Free Pascal (I miss a SktComp in Free Pascal, Delphi has it and works fine). After I solving my problem, I want to send the sources to be distributed in the samples of Free Pascal or Lazarus, so I'm avoiding third-party libraries. SOCK_STREAM sockets are full duplex and you can read and write simultaneously on them, even without threading if you use non blocking mode. SSocket has a Property NonBlocking but I don't see any code that handles the EAGAIN or EWOULDBLOCK errors. That is probably left to the user of TSocketStream to deal with. So SSocket is a really thin layer that leaves the user with all the problems you are trying to solve. Ludo Very interesting this information. I'll study more and try to solve this problem. Thank you very much Ludo! :) -- 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/4/25 Michael Van Canneyt mich...@freepascal.org Why is that ? Please define read and write at the same time first. Sorry, my English is bad. ^^ So, a small example (pseudo code): procedure TMyThread1.Execute; begin while not Terminated do begin GlobalSocket.Write ... end; end; procedure TMyThread2.Execute; begin while not Terminated do begin GlobalSocket.Read ... end; end; MyThread1.Start; MyThread2.Start; Thank you! * https://bitbucket.org/**silvioprog/tcpipcomphttps://bitbucket.org/silvioprog/tcpipcomp (this repo is temporary, and this all code can undergo drastic changes at any time) ... like ScktComp of Delphi. (no Synapse, LNet or Indy please, I need to use native code) Strange remark. Synapse, lnet or Indy are native pascal code. Michael. Yes, I love Synapse, but it is not distributed with Free Pascal. I think the Free Pascal need to distribute something like SktComp( http://pastebin.com/QBZU89cy) of Delphi. SSockets is not multi-threaded. -- 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/4/25 silvioprog silviop...@gmail.com [...] Yes, I love Synapse, but it is not distributed with Free Pascal. I think the Free Pascal need to distribute something like SktComp( http://pastebin.com/QBZU89cy) of Delphi. SSockets is not multi-threaded. ... and I'm trying to por SktComp to Free Pascal, but I do not know if the license of Delphi allow it. I ported only for studies. -- 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/4/25 Michael Schnell mschn...@lumino.de On 04/24/2013 10:21 PM, silvioprog wrote: (no Synapse, LNet or Indy please, I need to use native code) Indy does provide support for threading (as does AsyncPro, the Socket flavor of which could be of interest here). But I don't know if it's easy to use Indy with Lazarus, and I know that there is no Lazarus port for AsyncPro yet (even though it is open Source and especially the COM-Port flavor is requested rather often). -Michael Indy has a feature (OnDisconnect property) that notifies you when a client is not online. I find this feature very interesting, and I intend to implement it with threads. But I seen that I have much work to do. :) -- 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.
On 04/25/2013 05:15 PM, silvioprog wrote: Indy has a feature (OnDisconnect property) that notifies you when a client is not online. Nope. It notifies you when the other site actively and successfully does a disconnect and your site correctly understands the notification. Not correctly communicated aborts stay undetected. -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/4/25 Michael Schnell mschn...@lumino.de On 04/25/2013 05:15 PM, silvioprog wrote: Indy has a feature (OnDisconnect property) that notifies you when a client is not online. Nope. It notifies you when the other site actively and successfully does a disconnect and your site correctly understands the notification. Not correctly communicated aborts stay undetected. -Michael I'll write an example for you to test, please wait ... -- 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.
silvioprog wrote: 2013/4/25 Michael Schnell mschn...@lumino.de On 04/25/2013 05:15 PM, silvioprog wrote: Indy has a feature (OnDisconnect property) that notifies you when a client is not online. Nope. It notifies you when the other site actively and successfully does a disconnect and your site correctly understands the notification. Not correctly communicated aborts stay undetected. -Michael I'll write an example for you to test, please wait ... Maybe I can then update this old page? :) http://www.brenemanlabs.com/iConnect.htm ___ 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/4/25 Paul Breneman paul2...@brenemanlabs.com silvioprog wrote: 2013/4/25 Michael Schnell mschn...@lumino.de On 04/25/2013 05:15 PM, silvioprog wrote: Indy has a feature (OnDisconnect property) that notifies you when a client is not online. Nope. It notifies you when the other site actively and successfully does a disconnect and your site correctly understands the notification. Not correctly communicated aborts stay undetected. -Michael I'll write an example for you to test, please wait ... Maybe I can then update this old page? :) http://www.brenemanlabs.com/**iConnect.htmhttp://www.brenemanlabs.com/iConnect.htm hehe... I'll read 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.
Very nice article: http://www.bastisoft.de/programmierung/pascal/pasinet.html Outdated, but very very nice. :) -- 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/4/25 silvioprog silviop...@gmail.com Very nice article: http://www.bastisoft.de/programmierung/pascal/pasinet.html Outdated, but very very nice. :) in...: repeat put all sockets currently connected in the read set; put the listening socket in the read set; Select(read set, no other sets, no timeout); respond to all sockets that are left in the read set; until false; :o So I need of Select function. If I am not mistaken it is not being used in ssockets. I'll to do it manually. I will implement it on my own. -- 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.
On Thu, 25 Apr 2013, silvioprog wrote: 2013/4/25 silvioprog silviop...@gmail.com Very nice article: http://www.bastisoft.de/programmierung/pascal/pasinet.html Outdated, but very very nice. :) in...: repeat put all sockets currently connected in the read set; put the listening socket in the read set; Select(read set, no other sets, no timeout); respond to all sockets that are left in the read set; until false; :o So I need of Select function. If I am not mistaken it is not being used in ssockets. I'll to do it manually. I will implement it on my own. 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.___ 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/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... -- 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] Re: Odyssey: SSockets and Threads.
2013/4/24 silvioprog silviop...@gmail.com Hello, There are a multi-thread example using SSockets in FPC? I'm trying to implement it*, but it's very hard and this work it's consuming all my time. The difficulty is to read and write at the same time. I'm almost certain that using SSockets, I would have to create one socket for writing and one for reading, separately by threads. Thank you! * https://bitbucket.org/silvioprog/tcpipcomp (this repo is temporary, and this all code can undergo drastic changes at any time) ... like ScktComp of Delphi. (no Synapse, LNet or Indy please, I need to use native code) -- 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