Forum > Networking and Web Programming
Converting launch_activate_socket() from C to Pascal - issues
(1/1)
trev:
After having successfully converted the SampleD C daemon code into working, non-deprecated C code (ie replacing the deprecated ASL logging with OSLog; replacing the myriad deprecated launch_ functions with launch_activate_socket) my quest to convert it into Pascal has hit a pot hole, er, wall.
My working, converted, C code:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#include <launch.h>[...] int *listening_fd_array; size_t listening_fds_count; int err;[...]err = launch_activate_socket("MySocket", &listening_fd_array, &listening_fds_count);if (err != 0) { os_log_error(OS_LOG_DEFAULT, "launch_activate_socket() failed error %d (%s)", err, strerror(err));} if (NULL == listening_fd_array) { os_log_error(OS_LOG_DEFAULT, "No known sockets found to answer requests on!"); retval = EXIT_FAILURE; goto done;}
My failed Pascal attempt:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function launch_activate_socket(const name: string; var fds: PInteger; cnt: size_t): integer; external name '_launch_activate_socket'; [...]var err : integer; listening_fd_array: PInteger; listening_fds_count: size_t; [...]err := launch_activate_socket('MySocket', listening_fd_array, listening_fds_count);if(err <> 0) then begin if(err = ENOENT) then writeln('Error: Socket not found in plist file (', err, ')') else if(err = ESRCH) then writeln('Error: Calling process is not managed by launchd (', err, ')') else if(err = EALREADY) then writeln('Error: Socket already activated (', err, ')') else writeln('Error: ', err); end; if(Nil = listening_fds_count) then begin writeln('No known sockets found to answer requests on!'); goto Done; end;
Where did I go wrong? It compiles successfully, but errors out with ESRCH and "No known sockets...".
PascalDragon:
I have really strong doubts that launch_activate_socket as a C function takes a Pascal string instead of a PChar. Also shouldn't your cnt parameter be a var (or out) as well?
(Also I doubt that Nil = listening_fds_count does indeed compile)
trev:
Dang (cut 'n paste errors from another version):
- Nil should have been 0
- string should have been pchar
Thanks - I'd missed the missing var. No more spurious errors :)
PascalDragon:
--- Quote from: trev on May 04, 2021, 02:45:51 pm ---Thanks - I'd missed the missing var. No more spurious errors :)
--- End quote ---
You're welcome. :)
Navigation
[0] Message Index