Re: [fpc-pascal] How to close TInetServer without except?
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 mode with a select before accept, or use non blocking mode and deal with EAGAIN or EWOULDBLOCK. Here you seem to use blocking mode and accept will only return with a new connection or an error. Ludo ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Generic Observables
On 2013-05-02 20:26, Michal Wallace wrote: I was experimenting with using some of FPC's features together and came up with this: https://github.com/tangentstorm/lazmvc/blob/master/umodel.pas Just curious. If you use interfaces already, then why use message methods for notifications? Why not simply stick to designing to a interface theory, and use the interface support you already have? You might also find Model-GUI-Mediator (MGM) interesting. I wrote an article about it some years back. You can get a copy of the artile with sources here: http://opensoft.homeip.net/articles/ tiOPF (a Object Persistence Framework) has a much more advanced Model-GUI-Mediator implementation that currently works with VCL, LCL, fpGUI and FireMonkey. See the tiBaseMediator, tiModelMediator, tiMediators and tiListMediators units, or simply compile Demo 21 (available for VCL, LCL or fpGUI), which is a simple Address Book demo using only MGM to build and manage the whole UI. http://www.tiopf.com Also an interesting read - especially if you are into Interface usage and model design. Some years back Joanna Carter (well known in the Delphi circles) wrote several articles building a basic Model-View-Presenter (MVP) framework, using interfaces extensively. This has taught me so much about using interfaces. http://www.carterconsulting.org.uk/MVP.htm Anyway, thanks for sharing your code. It is nice seeing others also interested in better data and UI modelling - compare to the crappy db-ware design Borland forced onto the world. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] $LINKLIB or $LINK in Lazarus/FPC on Mac OSX
Hello: I am new to the list, I have posted on the forum, but I don't really know where the center of gravity is for this FPC/Lazarus Community, so I will post on the mailing lists as well. And then I do not know if the Mac List is well subscribed or just the general fpc-pascal list is better subscribed. I am trying to compile C code with Xcode into a static library or static object files. I already have a mylib.a file ready to link if I could just figure out the $LINKLIB syntax of dot.a library files. I want to use either $LINKLIB or $LINK compiler directives to tell freepascal/lazarus to link the code STATICALLY into my binary. The $LINK would require an object file, so I would need to dig around xcode to find out there the bloody thing puts the intermediate object files (Maybe Mach-O?) What I am trying to avoid is linking to a dylib dynamically. Only static linking for some portions of the code. Thanks for any feedback, md ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 close the handles i though. That's true, but at least it returns control to you (= the programmer), so you can close the handles manually. -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 with other programmesr without using cancel it. Best Regards Zaher Dirkey ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 solution as for recv and send. Or use blocking mode with a select before accept, or use non blocking mode and deal with EAGAIN or EWOULDBLOCK. Here you seem to use blocking mode and accept will only return with a new connection or an error. Ludo 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. -- 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] How to close TInetServer without except?
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 bugs in your application, while it is work fine with other programmesr without using cancel it. Neither do I, but wasn't that what Silvio asked? [by saying: `The problem now is how to stop the Accept but without errors`] I admit, killing an entire thread is a bit overkill for just getting back control from accept, but I also recall that he wanted to close the application [or am I seeing ghosts?]. But if you don't want to use pthread_cancel(), use non-blocking sockets -- In my experience though, it isn't worth the code if you just want to kill the application gracefully. Anyway, I'm sure there are other ways to get this done (signals?), but these are two methods I know about. Each has it's bonuses and pitfalls. -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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) Best Regards Zaher Dirkey Yes, I already do it. Now I'm trying to terminate all unterminated clients: destructor TTcpIpServerSocketThread.Destroy; begin DoTerminateClients; FClients.Free; FSocket.Free; inherited Destroy; end; procedure TTcpIpServerSocketThread.DoTerminateClients; var VClients: TList; VClient: Pointer; VThread: TTcpIpServerClientThread; begin VClients := FClients.LockList; try for VClient in VClients do begin VThread := TTcpIpServerClientThread(VClient); if Assigned(VThread) and not VThread.Finished then begin VThread.FreeOnTerminate := False; VThread.Terminate; FreeAndNil(VThread.FClientSocket); VThread.WaitFor; FreeAndNil(VThread); end; end; finally FClients.UnlockList; end; end; I'm testing it, on Windows it worked fine, I'll test on Linux 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] How to close TInetServer without except?
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 know that. 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 to exit an application gracefully (high code versus ouput ratio)] - something different (one can try experimenting with shutting down the listening socket, using signals, ... but I haven't done so, so I can't give any feedback on this) -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 to exit an application gracefully (high code versus ouput ratio)] - something different (one can try experimenting with shutting down the listening socket, using signals, ... but I haven't done so, so I can't give any feedback on this) Select on the main socket before doing the accept? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 timeout, and accept only if select shows activity on the listened to socket. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 sockets [not very code-efficient IMHO if you only want to exit an application gracefully (high code versus ouput ratio)] - something different (one can try experimenting with shutting down the listening socket, using signals, ... but I haven't done so, so I can't give any feedback on this) Select on the main socket before doing the accept? Yep, possibly the most simple and effective recipe (not much code to add, no radical changes, no overkill). Shame on me for not thinking of that ;-) -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 silvio to test it :P -- I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3 Best Regards Zaher Dirkey ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 believe i used it in the past and have problems with it, We can leave it to silvio to test it :P I use Select for incoming Data not for incoming client connections! Best Regards Zaher Dirkey ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 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 silvio to test it :P I use Select for incoming Data not for incoming client connections! It doesn't matter. A few facts: - You create a listening socket which you pass as an argument to accept(). - A socket is a file descriptor. - Select operates on file descriptors. Read the man page of select [http://linux.die.net/man/2/select] and you'll see that the exact purpose of select is to query whether or not the next IO operation is going to block. Now that we have established these two facts, I believe that using select before accept to check whether the latter will block is valid logic, wouldn't you say? PS: The exact details of this implementation I do not know, I haven't tested. -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] How to detect if a project is a simple program or a application?
Hello, I'm trying to detect if a project is a simple program or a application. Please download a small test here: https://www.dropbox.com/s/w6a9gb4b9hnjit5/prova.zip On Windows it works fine, but on Linux not. -- 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] How to close TInetServer without except?
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. 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; if insock-1 then //start working with insock else //deal with error end; until ThreadTerminated; Ludo ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to close TInetServer without except?
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 clients connected, I got a memory leak. 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; if insock-1 then //start working with insock else //deal with error end; until ThreadTerminated; Ludo Thank you! -- 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