FreeBSD Bugzilla – Attachment 150652 Details for
Bug 196035
Subsequent connect on ready socket returns EINVAL instead of ECONNREFUSED
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Sample program to reproduce
file_196035.txt (text/plain), 1.29 KB, created by
Mark Nunberg
on 2014-12-16 19:10:07 UTC
(
hide
)
Description:
Sample program to reproduce
Filename:
MIME Type:
Creator:
Mark Nunberg
Created:
2014-12-16 19:10:07 UTC
Size:
1.29 KB
patch
obsolete
>#include <sys/socket.h> >#include <sys/select.h> >#include <arpa/inet.h> >#include <netinet/in.h> >#include <assert.h> >#include <fcntl.h> >#include <string.h> >#include <stdlib.h> >#include <stdio.h> >#include <errno.h> > >int main(int argc, char **argv) >{ > struct sockaddr_in inaddr; > int s; > int rv; > fd_set wfd, efd; > > s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); > assert(s > -1); > > memset(&inaddr, 0, sizeof inaddr); > > inaddr.sin_family = AF_INET; > inaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); > inaddr.sin_port = htons(1); /* :1 */ > > /* Set noblock */ > rv = fcntl(s, F_GETFL); > assert(rv > -1); > rv = fcntl(s, F_SETFL, rv|O_NONBLOCK); > assert(rv > -1); > > rv = connect(s, (struct sockaddr *)&inaddr, sizeof inaddr); > assert(rv < 0); > if (errno != EINPROGRESS) { > perror("UNEXPECTED!"); > exit(EXIT_FAILURE); > } > > FD_ZERO(&wfd); > FD_ZERO(&efd); > > FD_SET(s, &wfd); > FD_SET(s, &efd); > rv = select(s+1, NULL, &wfd, &efd, NULL); > assert(rv == 1); > assert(! FD_ISSET(s, &efd)); > assert(FD_ISSET(s, &wfd)); > > rv = connect(s, (struct sockaddr *)&inaddr, sizeof inaddr); > printf("Second connect returns ERRNO %d (%s)\n", errno, strerror(errno)); > return EXIT_SUCCESS; >}
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 196035
: 150652 |
150658
|
150662