-
safety of siglongjmp
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
-
thanks, i've just read about sig_atomic_t. should i use this type for all flags set in a signal handler?
mysql_query(MYSQL *mysql,char *query);
is part of the mysql c api. its a real pain in the a*se to use sometimes (the whole api). there is a problem where if the mysql server hangs (or any other reason to break the network connection), it causes the client to hang because the client has no query timeout (it eventually times out to a TCP timeout - i think 15min).
i can't use a standard signal alarm because its stopped/handled somewhere in the depths of mysql_query.
the response above is actually provided by one of the mysql developers on the archived mailling list. i was just concerned about using siglongjmp - sounds like goto to me!