Re: [fpc-pascal] How to close TInetServer without except?

2013-05-06 Thread Ludo Brands
On 05/06/2013 07:17 AM, silvioprog wrote: Ludo, I'm almost by completing the units in this link: https://bitbucket.org/silvioprog/tcpipcomp (this repository is temporary) The current code (I'm updating it daily) in these units is good? I'm open to suggestions, and we can change whatever

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-06 Thread Zaher Dirkey
On Mon, May 6, 2013 at 9:10 PM, Ludo Brands ludo.bra...@free.fr wrote: Watch out for Synchronize(@DoReceive) in a recv loop. That is going to drag down your performance considerably. ​Maybe you do need to call synh, leave it to the user to add it in his event, or make it as an option. For

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-06 Thread silvioprog
2013/5/6 Ludo Brands ludo.bra...@free.fr In TTcpIpClientSocketThread.Execute you do a read followed by a select. The logic is: first select then read when something is available. Sorry, but I don't understand well this part. :/ In the old code I not used select, and now I'm using it just to

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-06 Thread silvioprog
2013/5/6 Zaher Dirkey parm...@gmail.com On Mon, May 6, 2013 at 9:10 PM, Ludo Brands ludo.bra...@free.fr wrote: Watch out for Synchronize(@DoReceive) in a recv loop. That is going to drag down your performance considerably. Maybe you do need to call synh, leave it to the user to add it in

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-05 Thread Ludo Brands
On 05/04/2013 09:59 PM, Zaher Dirkey wrote: now in this example http://msdn.microsoft.com/en-us/library/windows/desktop/ms737526%28v=vs.85%29.aspx They not use Select before acce​pt If you are happy with accept blocking or if you use non-blocking sockets you don't need select before accept.

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-05 Thread silvioprog
2013/5/5 Ludo Brands ludo.bra...@free.fr On 05/04/2013 09:59 PM, Zaher Dirkey wrote: now in this example http://msdn.microsoft.com/en-us/library/windows/desktop/ms737526%28v=vs.85%29.aspx They not use Select before accept If you are happy with accept blocking or if you use

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
On Sat, May 4, 2013 at 8:47 AM, silvioprog silviop...@gmail.com wrote: repeat if Socket.CanRead(timeout) then begin insock:=Socket.Accept; if insock-1 then //start working with insock else //deal with error end; until ThreadTerminated; Ludo Thank

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
On Sat, May 4, 2013 at 8:45 AM, Ludo Brands ludo.bra...@free.fr wrote: Take a look at TBlockSocket.InternalCanRead and TBlockSocket.CanRead in synapse on how to set up select correctly. Then do something like repeat if Socket.CanRead(timeout) then begin insock:=Socket.Accept;

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Ludo Brands
On 05/04/2013 04:31 PM, Zaher Dirkey wrote: ​I have put Select before Accept and it doesn't work, it blocked forever ​ without accepting any connection. Accept function who block the thread and get new connection. Can you show the code you use? You tested on Windows, linux, Mac, ...?

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
On Sat, May 4, 2013 at 5:40 PM, Ludo Brands ludo.bra...@free.fr wrote: Can you show the code you use? You tested on Windows, linux, Mac, ...? ​Only on Windows XP source here https://sourceforge.net/p/minilib/source/ci/master/tree/socket/source/mnServers.pas about line 323 i changed it to

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
But mnServer is works with me for a years, and there is mnHttpServer demo and it is work fine too without Select before Accept https://sourceforge.net/p/minilib/source/ci/master/tree/socket/demo/lazarus/ On Sat, May 4, 2013 at 6:05 PM, Zaher Dirkey parm...@gmail.com wrote: On Sat, May 4, 2013

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Ludo Brands
On 05/04/2013 05:05 PM, Zaher Dirkey wrote: On Sat, May 4, 2013 at 5:40 PM, Ludo Brands ludo.bra...@free.fr mailto:ludo.bra...@free.fr wrote: Can you show the code you use? You tested on Windows, linux, Mac, ...? ​Only on Windows XP This is a small test program that works for

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread silvioprog
2013/5/4 Zaher Dirkey parm...@gmail.com On Sat, May 4, 2013 at 8:47 AM, silvioprog silviop...@gmail.com wrote: repeat if Socket.CanRead(timeout) then begin insock:=Socket.Accept; if insock-1 then //start working with insock else //deal with error end;

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread silvioprog
2013/5/4 Ludo Brands ludo.bra...@free.fr On 05/04/2013 05:05 PM, Zaher Dirkey wrote: On Sat, May 4, 2013 at 5:40 PM, Ludo Brands ludo.bra...@free.fr mailto:ludo.bra...@free.fr wrote: Can you show the code you use? You tested on Windows, linux, Mac, ...? Only on Windows XP

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
Hmm there is diffrents Yours res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv); Mine c := WinSock2.select(0, PSetRead, PSetWrite, nil, @TimeVal); 0 here in mine, in yours sock+1 (FHandle+1 in mine). I will take more testing. On Sat, May 4, 2013 at 8:01 PM, Ludo Brands ludo.bra...@free.fr

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Ludo Brands
On 05/04/2013 08:00 PM, Zaher Dirkey wrote: Hmm there is diffrents Yours res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv); Mine c := WinSock2.select(0, PSetRead, PSetWrite, nil, @TimeVal); 0 here in mine, in yours sock+1 (FHandle+1 in mine). I will take more testing. According

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-04 Thread Zaher Dirkey
On Sat, May 4, 2013 at 9:42 PM, Ludo Brands ludo.bra...@free.fr wrote: However, in your code you do if (c = 0) or (c = SOCKET_ERROR) then begin Error; which is not correct. c=0 is the result of select returning after a timeout. It is not an error. The fact that if

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ludo Brands
On 05/02/2013 10:00 PM, silvioprog wrote: Lines 277 and 278. That is, I already do that. The problem now is how to stop the Accept but without errors. I implemented the Stop method in socket, but I did not want to do it this ugly way. Same solution as for recv and send. Or use blocking

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ewald
On 03 May 2013, at 00:15, Zaher Dirkey wrote: On Fri, May 3, 2013 at 12:51 AM, Ewald ew...@yellowcouch.org wrote: pthread_cancel() pthread_cancel() ​ ​​ not clos​e​ the handles i though​.​ That's true, but at least it returns control to you (= the programmer), so you can close the

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 12:18 PM, Ewald ew...@yellowcouch.org wrote: That's true, but at least it returns control to you (= the programmer), so you can close the handles manually. ​I am notprefer force to close any thing, that will make more bugs in your application​, while it is work fine

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread silvioprog
2013/5/3 Ludo Brands ludo.bra...@free.fr On 05/02/2013 10:00 PM, silvioprog wrote: Lines 277 and 278. That is, I already do that. The problem now is how to stop the Accept but without errors. I implemented the Stop method in socket, but I did not want to do it this ugly way. Same

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ewald
On 03 May 2013, at 11:30, Zaher Dirkey wrote: On Fri, May 3, 2013 at 12:18 PM, Ewald ew...@yellowcouch.org wrote: That's true, but at least it returns control to you (= the programmer), so you can close the handles manually. ​I am notprefer force to close any thing, that will make more

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 6:57 PM, silvioprog silviop...@gmail.com wrote: when I close the server with one or more clients connected, I got a memory leak. ​Check if the thread freed​? ​Try to stop server manually (by button or in Close event in the form)​ Best Regards Zaher Dirkey

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 7:22 PM, Ewald ew...@yellowcouch.org wrote: Accept but without errors ​You cant, Accept give you a handle of new socket or give you an error, not all is fatal error, just check what is it, if it a closed handle or shutdown.​ Best Regards Zaher Dirkey

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread silvioprog
2013/5/3 Zaher Dirkey parm...@gmail.com On Fri, May 3, 2013 at 6:57 PM, silvioprog silviop...@gmail.com wrote: when I close the server with one or more clients connected, I got a memory leak. Check if the thread freed? Try to stop server manually (by button or in Close event in the form)

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ewald
Once upon a time, Zaher Dirkey said: On Fri, May 3, 2013 at 7:22 PM, Ewald ew...@yellowcouch.org wrote: Accept but without errors ​You cant, Accept give you a handle of new socket or give you an error, not all is fatal error, just check what is it, if it a closed handle or shutdown.​ Yes, I

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Marco van de Voort
In our previous episode, Ewald said: The point being that the answer to one of the OP sub-problems [the one quoted _partially_ above], can be to either use: - pthread_cancel() [overkill, I know, but nonetheless a solution] - non-blocking sockets [not very code-efficient IMHO if you only want

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread silvioprog
Fixed all errors: https://bitbucket.org/silvioprog/tcpipcomp/src/273b28b52b30621ffb4955e1136f8a06c160d20a/src/tcpipserver.pas?at=master I'll test this class severely. -- Silvio Clécio My public projects - github.com/silvioprog ___ fpc-pascal maillist

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 9:13 PM, Marco van de Voort mar...@stack.nl wrote: Select on the main socket before doing the accept? ​No i am not use Select before Accept, accept is blocking the thread. Best Regards Zaher Dirkey ___ fpc-pascal maillist -

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Marco van de Voort
In our previous episode, Zaher Dirkey said: On Fri, May 3, 2013 at 9:13 PM, Marco van de Voort mar...@stack.nl wrote: Select on the main socket before doing the accept? ?No i am not use Select before Accept, accept is blocking the thread. That's the point. Don't. Use a select, it has a

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ewald
On 03 May 2013, at 20:13, Marco van de Voort wrote: In our previous episode, Ewald said: The point being that the answer to one of the OP sub-problems [the one quoted _partially_ above], can be to either use: - pthread_cancel() [overkill, I know, but nonetheless a solution] - non-blocking

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort mar...@stack.nl wrote: That's the point. Don't. Use a select, it has a timeout, and accept only if select shows activity on the listened to socket. ​Not sure, but i believe i used it in the past and have problems with it, We can leave it to

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Zaher Dirkey
On Fri, May 3, 2013 at 11:47 PM, Zaher Dirkey parm...@gmail.com wrote: On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort mar...@stack.nlwrote: That's the point. Don't. Use a select, it has a timeout, and accept only if select shows activity on the listened to socket. ​Not sure, but i

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ewald
On 03 May 2013, at 22:56, Zaher Dirkey wrote: On Fri, May 3, 2013 at 11:47 PM, Zaher Dirkey parm...@gmail.com wrote: On Fri, May 3, 2013 at 11:27 PM, Marco van de Voort mar...@stack.nl wrote: That's the point. Don't. Use a select, it has a timeout, and accept only if select shows

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread Ludo Brands
On 05/03/2013 05:57 PM, silvioprog wrote: Could you give me an example in practice? Theoretically I understand, but I don't know do in practice. :/ Now, TTcpIpServer is working well. The new problem is: when I close the server with one or more clients connected, I got a memory leak.

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-03 Thread silvioprog
2013/5/4 Ludo Brands ludo.bra...@free.fr On 05/03/2013 05:57 PM, silvioprog wrote: Could you give me an example in practice? Theoretically I understand, but I don't know do in practice. :/ Now, TTcpIpServer is working well. The new problem is: when I close the server with one or more

[fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread silvioprog
Hi, I'm trying to close a socket (full code here: https://bitbucket.org/silvioprog/tcpipcomp/src/6b43739d5416424e82112b858a9b71d26c8c6165/src/tcpipserver.pas?at=master ): destructor TTcpIpServerSocketThread.Destroy; begin FSocket.StopAccepting; FSocket.Free; inherited Destroy; end; But,

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread Zaher Dirkey
​After termintate you need to wait the thread to stop, WaitFor here the function. Search for WaitFor​ in https://sourceforge.net/p/minilib/source/ci/master/tree/socket/source/mnServers.pas On Thu, May 2, 2013 at 8:57 PM, silvioprog silviop...@gmail.com wrote: destructor

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread silvioprog
2013/5/2 Zaher Dirkey parm...@gmail.com After termintate you need to wait the thread to stop, WaitFor here the function. Search for WaitFor in https://sourceforge.net/p/minilib/source/ci/master/tree/socket/source/mnServers.pas Yes, but in this case, WaitFor blocks my app. -- Silvio

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread Zaher Dirkey
On Thu, May 2, 2013 at 10:45 PM, silvioprog silviop...@gmail.com wrote: Yes, but in this case, WaitFor blocks my app. ​Yes, but before terminate your socket/client connections, you need also close the handle of it, or stop receive, it will return immateriality without receive (with error), so

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread silvioprog
2013/5/2 Zaher Dirkey parm...@gmail.com On Thu, May 2, 2013 at 10:45 PM, silvioprog silviop...@gmail.com wrote: Yes, but in this case, WaitFor blocks my app. Yes, but before terminate your socket/client connections, you need also close the handle of it, or stop receive, it will return

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread silvioprog
2013/5/2 silvioprog silviop...@gmail.com 2013/5/2 Zaher Dirkey parm...@gmail.com On Thu, May 2, 2013 at 10:45 PM, silvioprog silviop...@gmail.com wrote: Yes, but in this case, WaitFor blocks my app. Yes, but before terminate your socket/client connections, you need also close the

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread Zaher Dirkey
On Thu, May 2, 2013 at 11:47 PM, silvioprog silviop...@gmail.com wrote: I tested current code on Linux, but unfortunately when I try to close, the app stays locked. :| ​Yes headache :P​ ​Do not close, i use Shutdown function TmnSocket.DoShutdown(How: TmnShutdown): TmnError; const cHow:

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread Ewald
On 02 May 2013, at 22:00, silvioprog wrote: Lines 277 and 278. That is, I already do that. The problem now is how to stop the Accept but without errors. Using linux (or some other unix like thingie), you could cancel the thread using pthread_cancel(), the call will then return immediately

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread Zaher Dirkey
On Fri, May 3, 2013 at 12:51 AM, Ewald ew...@yellowcouch.org wrote: pthread_cancel() pthread_cancel() ​ ​ ​ not clos ​e​ the handles i though​.​ -- I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3 Best Regards Zaher Dirkey ___

Re: [fpc-pascal] How to close TInetServer without except?

2013-05-02 Thread silvioprog
2013/5/2 silvioprog silviop...@gmail.com I tried with fpshotdown ... fpshutdown... -- Silvio Clécio My public projects - github.com/silvioprog ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org