I'm testing some mysql integration to my C code. I noticed that if mydomain.com is not available at the time the binary runs, it is stuck for little more than 2 minutes. I'd like to avoid this and set a timeout of 5 seconds maximum. How can I do that?
#include <my_global.h>
#include <mysql.h>
int main() {
MYSQL *con = mysql_init(NULL);
if (con == NULL) {
fprintf(stderr, "%s\n", "debug: could not initialize database");
exit(1);
}
if (mysql_real_connect(con, "mydomain.com", "testuser",
"testuserpwd", "db_test", 0, NULL, 0) == NULL) {
exit(1);
}
...
mysql_close(con);
}