Non Blocking Sockets on Arm V6 lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- richard_rtech · 2015-01-18 21:47 I've worked with (and contributed to) ICS on delphi for years. I'm quite happy with it and it does the job. However making the jump to Linux and for a project I need TWSocket level functionality in Lazarus. I can find bits and peices but nothing quite fits the bill. The socket will be opened and then left open for background data tansfer. I'd rather not use blocking components but at a push I can fire such a component off in a thread. The real kicker, is it has to work on linux x86 and ARM6. Lots of close but no cigar packages but I'm stuck now trying to make FCL-Net work which is easier said than done. Does anyone have either : A component that works on x86 and ARM A working client example that works with FCL-Net With FCL-Net I can get a socket opened and send data to it as I need. I cant for the life of me how to get an event from it if the connection closes or data is available. I have ONE example which is what I've dismantled to get as far as I have so far. Hopefully if I can get this working I can then throw a twsocket-like wrapper round it. Any ideas gratefully received. ---------------------------------------------------------------------- Blestan · 2015-01-19 08:20 take a look on the LNET Package ... it's non blocking and available for many oses and platforms ---------------------------------------------------------------------- marcov · 2015-01-19 10:33 Non blocking sockets is a specialist item on *nix.  Specially because non blocking sockets under Unix only allow you to poll them when you want, getting asynchronous messages like on Windows is a different thing (read not possible, or at least hard/rare), so that would require emulation with threads anyway. ---------------------------------------------------------------------- Blestan · 2015-01-19 12:08 this is completely not true!!!! non blocking sockets on windows exists and LNET is a perfect example of cross platform lib writen in fpc ---------------------------------------------------------------------- Blestan · 2015-01-19 12:10 did you even know the existence of poll() and epoll() under windows? ---------------------------------------------------------------------- marcov · 2015-01-19 13:15 Quote from: Blestan on January 19, 2015, 01:08:08 pmthis is completely not true!!!! non blocking sockets on windows exists and LNET is a perfect example of cross platform lib writen in fpc READ. Non blocking sockets on unix with asynchronous messages when completed like under Windows. LNET does non blocking sockets the unix way, which is clumsy on Windows (and afaik different from what people would expect coming from ICS) P.s. Windows has select, if it has epoll, then I wonder why epoll is under $ifdef linux in lnet. ---------------------------------------------------------------------- Blestan · 2015-01-19 13:38 1/ select exists since winsock2, poll since nt epoll is present since  win vista ... the ifdef is not to break xp and earlier code 2/ lnet uses the best eventizer per platform ... select is the common less denominator ... others are kqueue, poll, epoll the diference under win is that you cannot use eventizer to watch fd ... on unix all handles can be watched if you want more abstract event lib u can use the c bindings for libuv ( the demulitlexer lib of nodejs  ) ... in this case u get a crossplatform event lib that can watch everithing and it's c (native on all platforms) and pretty easy to use ---------------------------------------------------------------------- Blestan · 2015-01-19 13:40 P.S Quote messages when completed like under Windows. this is accomplished using level trigerring or edge trigering events ---------------------------------------------------------------------- marcov · 2015-01-19 13:49 Quote from: Blestan on January 19, 2015, 02:40:27 pmP.S Quote messages when completed like under Windows. this is accomplished using level trigerring or edge trigering events And how do these enter the Lazarus event queue? Where is the lnet support for this? ---------------------------------------------------------------------- Blestan · 2015-01-19 14:25 there is a "visual" version with some components that are using the lazarus eventloop ---------------------------------------------------------------------- marcov · 2015-01-19 14:39 Quote from: Blestan on January 19, 2015, 03:25:48 pmthere is a "visual" version with some components that are using the lazarus eventloop Afaik those abuse the onidle queue for polling, and are not truely message based integration into the eventloop (like a .queue from a thread). I can vaguely remember that the windows based socketing is not the prefered one (for Windows) too. It is win32, but the WinNT way are IO Completion ports. http://msdn.microsoft.com/en-us/magazine/cc302334.aspx ---------------------------------------------------------------------- Blestan · 2015-01-19 15:55 Ok.! Ok !.. look this is going nowhere... let's stop it ---------------------------------------------------------------------- richard_rtech · 2015-01-19 23:58 Ermm, wishing I hadnt asked now I know I can use a thread to acheive non blocking in a round about sort of way and provided its documented thats fine. LNET I did look at and couldnt use, although it runs hapilly on deb/x86 it segfaults on ARM otherwise it would have been perfect. I have grabbed the source for Sockets but not had time to try it yet. Its immensely frustrating struggling to do basic things I can do easilly on another platform, doubly so when although I'm a pretty proficient Linux admin I've never tinkered under the hood or done any dev work. ---------------------------------------------------------------------- Blestan · 2015-01-20 08:22 please give more details on errors you get with LNET ---------------------------------------------------------------------- Laksen · 2015-01-20 08:59 Are you certain that it's a problem in lnet and not in your code? ARM will segfault if you do not properly handle alignments ---------------------------------------------------------------------- marcov · 2015-01-20 09:03 Well, non-blocking sockets are simply rare and Windows and Unix have different philosophies. Windows is more asynchronous event driven, and Unix is more polling of filedescriptors (and mapping a lot to filedescriptors).  The windows eventloop mechanism makes it more flexible and pluggable. (to allow later added parts of a program to register themselves in the eventloop). It can receive and relay messages from a primitive that only got the handle of the eventloop, without requiring an own handle to be added to the loop. IPC (to a certain degree) and file/sockets can both deal with the message loop. ICS is a typical windows solution that maximize usage of this layer. This while Unix can't even seem to wait on two IPC primitives at the same time (no equivalent for waitmultiple). It can on two filedescriptors though, but not on filedescriptors and IPC at the same time. LNET is thus a typical unix approach assuming it is in sole control of the main blocking point (event loop) of the program. (something that is hard to combine with GUI programming that requires its own eventloop) This fundamental different approach is the root of the discussion of Blestan, I reasoned from a porting ICS perspective (windows philosophy to unix), he (and LNET with him) is more taking Unix approach to Windows. I had exhaustive discussions with Ales on IRC about all this when he was developing lnet :-) (though iirc at the beginning Ales mainly wanted to use epoll, and wasn't even thinking about windows compat. I got him involved with FreeBSD, and he then re-setup things more pluggable since even for *nix he had to allow multiple flavours). In the past I also ported ICS to FPC, though I didn't maintain it. ---------------------------------------------------------------------- hinst · 2015-01-20 09:51 synapse library works on ARM, I tested it myself and it worked at least the TCP sockets feature worked, not sure about HTTP and SSL & SSH though to make it non-blocking use threads ---------------------------------------------------------------------- richard_rtech · 2015-01-25 16:19 Lnet just barfs is the components are dropped on the form without any code. Synapse I've not looked at as from just reading the info it didnt seem suitable. Sockets I've spent a couple of hours trying to bring it up to date as it seems the closest to what I need and I'm almost there as we speak. Of course thats on my x86 Dev VM, what will happen on the Pi is something else. Lnet seems the solution so I may revisit that. Its just frustrating having to compile things on something THAT slow. Maybe time to break out the heatsink adhesive and do some overclocking  Its that or setup cross compiling. I'll be glad when I have the components all working and can actualy write my own code. ---------------------------------------------------------------------- richard_rtech · 2015-01-25 21:02 I have Laz_Sockets working on both architectures, thanks guys.