Sourceware Bugzilla – Attachment 2827 Details for
Bug 6745
si_code != SI_SIGIO when a signal is generated by queued SIGIO
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
server code to see the problem
server.c (text/x-csrc), 2.25 KB, created by
who
on 2008-07-14 17:28:34 UTC
(
hide
)
Description:
server code to see the problem
Filename:
MIME Type:
Creator:
who
Created:
2008-07-14 17:28:34 UTC
Size:
2.25 KB
patch
obsolete
>#include <stdio.h> > >#define __USE_GNU >#include <fcntl.h> >#include <sys/socket.h> >#include <netdb.h> >#include <signal.h> > >/*this flag will force the server to sleep*/ >int flag = 1; > >/*this function will handle SIGTERM signals*/ >/*it will set the flag to 0 so the server exits the sleep loop*/ >void MyTermHandler(int signo, siginfo_t *info, void *context){ > flag = 0; >} > >/*this function will handle SIGIO signals*/ >/*it shows that si_code does not have SI_SIGIO contrary to what the man pages say*/ >void MySigHandler(int signo, siginfo_t *info, void *context){ > if(info->si_code == SI_SIGIO) > printf("w00t\n"); > else > printf("The value of si_code is: %d\n", info->si_code); >} > >int main(void){ > > struct sockaddr_in address; > struct hostent *hostname; > struct sigaction action; > int listenSocket; > > /*printing the values of SI_SIGIO and SI_USER*/ > printf("\n"); > printf("The value of SI_SIGIO is: %d\n", SI_SIGIO); > printf("The value of SI_USER is: %d\n", SI_USER); > > /*making the socket*/ > if((listenSocket = socket(PF_INET, SOCK_STREAM, 0)) == -1) > return 1; > > /*setting up the socket so it sends signals of type SIGIO to the current process*/ > if(fcntl(listenSocket, F_SETSIG, SIGIO)) > return 1; > if(fcntl(listenSocket, F_SETFL, O_ASYNC | O_NONBLOCK)) > return 1; > if(fcntl(listenSocket, F_SETOWN, getpid())) > return 1; > > /*setting up the handler for SIGIO signals*/ > action.sa_sigaction = &MySigHandler; > action.sa_flags = SA_SIGINFO; > if(sigaction(SIGIO, &action, NULL)) > return 1; > > /*setting up the handler for SIGTERM signals*/ > action.sa_sigaction = &MyTermHandler; > action.sa_flags = SA_SIGINFO; > if(sigaction(SIGTERM, &action, NULL)) > return 1; > > /*setting up the address to which the socket will listen*/ > if((hostname = gethostbyname("localhost")) == NULL) > return 1; > address.sin_family = AF_INET; > address.sin_port = htons(60069); > address.sin_addr = *(struct in_addr *)hostname->h_addr; > > /*binding the socket to the address*/ > if(bind(listenSocket, (struct sockaddr *)&address, sizeof(address))) > return 1; > > /*listening for incoming connections*/ > if(listen(listenSocket, 20)) > return 1; > > /*sleep loop*/ > /*sleep gets cancelled whenever a signal arrives or the time runs out*/ > while(flag) > sleep(200); > > /*closing the socket*/ > if(close(listenSocket)) > return 1; > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 6745
: 2827 |
2828