Hi list, I'm currently working on a project that uses a closed source C api. I know the functions and what they return but have no clue what happends in the background. To be able to use this with mod_perl I've made a module using perlxs that basicly is a wrapper around the API's functions. This API connects to a server and can only handle one connection at the time so my wrapper needs to know if it is connected and avoid connecting again if it allready is connected. There is no reasonable way I can test my connection status, ie there is no get_connection_status or equivalent function I can call. Trying to fetch or send data if there is no connection will force me to wait for the timeout which I can't do since all scripts using the API will be extremly slow then. The connect function is very slow too, it takes a few secs to do the connect so I don't want to do extra connects either, plus it seems to result in core dumps when I try to do connect if I'm allready connected.
I was first thinking about using a global variable in the wrapper's connect function but I'm not sure what would happend if the script crashes, will the httpd process die and the global variable be reseted or will it be set to CONNECTED when the next request comes to that child? So to stop my ramble and get on with my question, how should I approach this in a way that guarantees that I'll only do connect/disconnect if needed and also be able to keep track of my status in a safe way? If you're thinking refuse to do it, go to the makers of the API and beat them untill they fix it up or snort/strace the API and make your own API based of what they send, I've allready thought about it and I've come to the conclusion they're not options :) /Jon