Hi,
i need to set a timeout on a mysql_query, and believe it or not, there is no built in function to do this in the mysql c api.
so, i thought about using a simple alarm signal around the mysql_query call - this didn't work.
with some searching on the web i found this solution: (quote)
For now the only solution I know of is this (in C):
- establish connection
- remember connection id
- signal(SIGALRM, got_bored_waiting);
- alarm(10);
- do your query
- in your alarm handler (got_bored_waiting) use siglongjmp() to jump out of the trap
- after your query call sigsetjmp()
- test the return value -- if sigsetjmp() tells you your are there because you
timed out, establish another connection and do mysql_kill_thread on your old connection id to clean up and to make sure you still have the connection
- don't forget to alarm(0)
now this seems ok, but i also found a answer to the same suggestion elsewhere that described the safety of siglongjmp as questionable.
does anyone know about siglongjmp and its safety in this context?
TIA, rotis23