Subject Strange works with signals in UDF (in Firebird for Linux)
Author ivzelen
Hello!My question addressed to Firebird developers and developers of UDF
who had same problem.
I'm writing UDF (C++, Linux), that uses POSIX-sockets for TCP-connection
and POSIX-signals (SIGALRM) to implement timeouts for this connection.
See sample code under this text.As you can see, I try to terminate
connection using SIGALRM. And it works correctly when function called
from my own application (using dlopen/dlsym that also used for
udf-calling in Firebird, isn't it?)But when I call this function from
Firebird i have problem. Signal-handler still called, but connect()
doesn't terminate. So, that's my question: what I did uncorrectly and
what can I do to implement this connection timeout?Thanks,Ivan
Zelenskyy.
Code:#include <stdlib.h>#include <unistd.h>#include
<sys/socket.h>#include <netinet/in.h>#include <sys/time.h>#include
<signal.h>#include <arpa/inet.h>#include <errno.h>
static void timer_handler(int signo){ return;}
extern "C" int fbconnectiontest(int i){ struct sigaction sa, sa_old;
sa.sa_handler = timer_handler; sigemptyset(&sa.sa_mask); sa.sa_flags =
SA_INTERRUPT; if (sigaction(SIGALRM, &sa, &sa_old) == -1) return -1;
//can't set sigaction
struct itimerval timerstruct; timerstruct.it_interval.tv_sec=0;
timerstruct.it_interval.tv_usec=0; timerstruct.it_value.tv_sec=0;
timerstruct.it_value.tv_usec=200000;
struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port =
htons(80); bool all_ok = inet_aton("8.8.8.8", &(addr.sin_addr)) != 0;
int sock = socket(PF_INET,SOCK_STREAM,0); if (sock==-1) return -2;
//can't create socket
if(setitimer(ITIMER_REAL,&timerstruct,NULL)!=0) return -3; //can't set
timer; if(connect(sock, (struct sockaddr*)&addr, sizeof(addr))!=0)
return errno;
close(sock); return 0; //all ok!}



[Non-text portions of this message have been removed]