Mail Archives: cygwin/2002/06/28/08:35:23
I am a bit confused about the current signal handling in a blocking
accept call (i have not checked other system calls yet)
If the process is blocked it is not interrupted by a signal. It first
waits until a connection is made and call the signal handler afterwards.
Is this by design ? IMHO it should call the signal handler and return
EINTR.
I have attached a small testprogram.
When i press CTRL-C during accept the program will stay until i make a
connection, then the signal handler is called. If i press CTRL-C twice the
process starts to eat CPU time.
Thomas
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <signal.h>
#define MY_PORT (5678)
static void sig_handler( int signo );
int main( void )
{
int listen_sock;
int conn_sock;
struct sockaddr_in s_local;
struct sockaddr_in from;
int fromlen = sizeof( from );
signal( SIGTERM, sig_handler );
signal( SIGINT, sig_handler );
s_local.sin_family = AF_INET;
s_local.sin_addr.s_addr = INADDR_ANY;
s_local.sin_port = htons( MY_PORT );
listen_sock = socket( AF_INET, SOCK_STREAM, 0 );
bind( listen_sock, (struct sockaddr*) &s_local, sizeof( s_local ) );
listen( listen_sock, 1 );
conn_sock = accept( listen_sock, (struct sockaddr*) &from, &fromlen);
if(conn_sock >= 0)
{
printf( "Got connection\n");
close( conn_sock );
}
close( listen_sock );
return 0;
}
static void sig_handler( int signo )
{
printf("terminated\n");
exit( 0 );
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -