On Thu, Jun 26, 2014 at 13:43, Arne Becker wrote:
> Hi.
>
>> Now soliciting diffs to change readwrite to a loop with two buffers
>> that poll()s in all four directions. :)
>
> Good thing you made me remember I wrote just this a while ago.
> This is my first OpenBSD diff, so tell me if I missed anything obvious.
> Tested quite extensively originally; for this diff I only checked a
> simple nc to nc "hello".
> @@ -608,7 +616,7 @@ remote_connect(const char *host, const c
>
> if (bind(s, (struct sockaddr *)ares->ai_addr,
> ares->ai_addrlen) < 0)
> - err(1, "bind failed");
> + errx(1, "bind failed: %s", strerror(errno));
> freeaddrinfo(ares);
This doesn't seem necessary, or correct.
> @@ -640,7 +648,7 @@ timeout_connect(int s, const struct sock
> if (timeout != -1) {
> flags = fcntl(s, F_GETFL, 0);
> if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
> - err(1, "set non-blocking mode");
> + warn("unable to set non-blocking mode");
ok, maybe. i wonder what this will break...
> -readwrite(int nfd)
> +readwrite(int net_fd)
this part read ok, for the actual poll changes.
> @@ -877,8 +1049,20 @@ atelnet(int nfd, unsigned char *buf, uns
>
> p++;
> obuf[2] = *p;
> +
> + if (!blocking) {
> + flags = fcntl(nfd, F_GETFL, 0);
> + if (fcntl(nfd, F_SETFL, flags & ~O_NONBLOCK) == -1)
> + warn("unable to set blocking mode");
> + blocking = 1;
> + }
> if (atomicio(vwrite, nfd, obuf, 3) != 3)
> warn("Write Error!");
> + }
> + if (blocking) {
> + flags = fcntl(nfd, F_GETFL, 0);
> + if (fcntl(nfd, F_SETFL, flags | O_NONBLOCK) == -1)
> + warn("unable to set non-blocking mode");
> }
> }
I don't understand this part. What's the reasoning?