Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 305244 Details for
Bug 446206
select() on listening socket returns prematurely
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
test case to show functionality of select
listener.c (text/plain), 2.87 KB, created by
Neil Horman
on 2008-05-13 15:43:23 UTC
(
hide
)
Description:
test case to show functionality of select
Filename:
MIME Type:
Creator:
Neil Horman
Created:
2008-05-13 15:43:23 UTC
Size:
2.87 KB
patch
obsolete
>/********************************************************* >*Copyright (C) 2004 Neil Horman >*This program is free software; you can redistribute it and\or modify >*it under the terms of the GNU General Public License as published >*by the Free Software Foundation; either version 2 of the License, >*or any later version. >* >*This program is distributed in the hope that it will be useful, >*but WITHOUT ANY WARRANTY; without even the implied warranty of >*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >*GNU General Public License for more details. >* >*File: listener.c >* >*Author:Neil Horman >* >*Date: Aug 3, 2004 >* >*Description run ./listener <port number> >*********************************************************/ > >#include <stdlib.h> >#include <stdio.h> >#include <signal.h> >#include <sys/types.h> >#include <sys/socket.h> >#include <netinet/in.h> >#include <sys/time.h> >#include <sys/types.h> >#include <unistd.h> > >int sd,csd; > >void sigint_handler(int sig, siginfo_t *info, void *unused) >{ > close(sd); > exit(0); >} > >int main(int argc, char **argv) >{ > struct sigaction action; > struct sockaddr_in my_addr; > struct sockaddr_in clntaddr; > socklen_t clntaddrlen; > int keepalive; > fd_set rfds; > fd_set efds; > int n; > > action.sa_sigaction = sigint_handler; > sigemptyset(&action.sa_mask); > action.sa_flags = SA_SIGINFO; > action.sa_restorer = NULL; > > if(sigaction(SIGINT,&action,NULL) < 0) { > perror("Unable to register sig handler\n"); > exit(0); > } > > /* > *get a socket > */ > sd = socket(PF_INET,SOCK_STREAM,0); > if(sd < 0) { > perror("Could not open a socket"); > exit(0); > } > > my_addr.sin_family=AF_INET; > my_addr.sin_addr.s_addr = htonl(INADDR_ANY); > my_addr.sin_port = htons(10000); > > if(bind(sd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr_in))) { > perror("Unable to bind socket"); > close(sd); > exit(0); > } > > FD_ZERO(&rfds); > FD_ZERO(&efds); > FD_SET(sd, &rfds); > FD_SET(sd, &efds); > > > printf("Selecting on a non-listening socket, this should return immediately\n"); > n = select(sd+1,&rfds,NULL,&efds, NULL); > printf("select returned %d\n",n); > > if (FD_ISSET(sd, &rfds)) { > char buf=0; > printf("sd is readable\n"); > if (read(sd, &buf, 1) < 0) { > perror("Read Failed: "); > printf("This is expected\n"); > } else { > printf("Read returned data, this is unexpected\n"); > printf("Buf is %c\n",buf); > } > } > if (FD_ISSET(sd, &efds)) { > printf("sd is in error\n"); > printf("This is unexpected\n"); > } > > > printf("Setting socket to listen\n"); > listen(sd, 6); > > FD_ZERO(&rfds); > FD_ZERO(&efds); > FD_SET(sd, &rfds); > FD_SET(sd, &efds); > printf("Trying select again, this should block until a socket connection is attempted\n"); > printf("Hit Ctrl-C to abort\n"); > n = select(sd+1,&rfds,NULL,&efds, NULL); > printf("Select returned! Did someone try to connect?\n"); > > close(sd); > exit(1); > >} >
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 446206
: 305244