At 9:57 PM +0200 12/8/03, Frank Heckenbach wrote:
Peter N Lewis wrote:
It's a triffle tedious to convert the C stuff over, but since I do it ad hoc as needed, it's not to bad at any one time. It's a bit error prone and obviously not going to handle changing the interfaces or porting to another unix system, but my code is all heaviy Mac specific anyway so no big deal there.
Of course, you can do in your own code as you please. However, I'd prefer if on this list portable techniques were advocated where available.
The code is portable if the interfaces are generated automatically. That bit has not been implemented unfortunately, and since requires parsing C headers, is quite challenging, so the interfaces are generated manually. Other than that, coding to the sockets layer is certainly portable.
Here, a little C wrapper can easily use the system header definitions, and since it's only needed for setting up/closing a connection etc., while the actual socket I/O can go through regular files, the (anyway small) performance overhead should be negligible.
I'm not sure what you mean by "regular files". Personally, I do network transfer code that has to transfer at the speed of the harddisk, so I prefer to avoid any wrapping in the actual transfer, thought as you mention, wrapping the connect etc is not really an issue. However, error handling does become an issue for any wrapped code, writing robust code with other peoples wrappers is often very challenging as you have to know exactly how things are implemented in order to get it exactly right, especially with the sockets API.
Ideally we'd have direct access to the POSIX API on any given system, but until we can parse the C headers on each platform to make Pascal interfaces, that's probably not going to happen. The next best thing might be to make a Posix.pas file for each platform that is generated somewhat automatically and somewhat manually.
Enjoy, Peter.