- /* --- Make the socket nonblocking --- */
-
- {
- int f;
-
- if ((f = fcntl(fd, F_GETFL)) < 0 ||
- fcntl(fd, F_SETFL, f | O_NONBLOCK))
- goto fail_close;
- }
-
- /* --- Set up the source address and bind it to the socket --- */
-
- {
- struct sockaddr_in sin;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = saddr;
- sin.sin_port = sport;
- if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
- goto fail_close;
- }
-
- /* --- Finally, set up the destination and try the connect --- */
-
- {
- struct sockaddr_in sin;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = daddr;
- sin.sin_port = dport;
- if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- if (errno != EINPROGRESS)
- goto fail_close;
- c->func = func;
- c->p = p;
- sel_initfile(s, &c->writer, fd, SEL_WRITE, conn_connect, c);
- sel_addfile(&c->writer);
- } else
- func(fd, p);
- }
-
- /* --- Everything is set up now --- */
+ if (connect(fd, dst, dsz) < 0) {
+ if (errno != EINPROGRESS)
+ goto fail;
+ c->func = func;
+ c->p = p;
+ sel_initfile(s, &c->writer, fd, SEL_WRITE, conn_connect, c);
+ sel_addfile(&c->writer);
+ } else
+ func(fd, p);