Firewall Wizards mailing list archives

Re: Code reviews [Was: FWTK and smap/smapd]


From: Darren Reed <darrenr () reed wattle id au>
Date: Wed, 24 Jul 2002 02:35:24 +1000 (EST)

In some email I received from Joseph S D Yao, sie wrote:
Oh, geez, shouldn't everyone have written [something like] this?

No...

Your parameters are wrong, for a start :-)
They were "char *buf" and "unsigned int buflen".

register char *cp = buf;
register int i, count = n;

for (;;) {
      i = write(fd, cp, count);
      if (i < 0) {
              perror("...");
              fprintf(stderr, ...);
              break;
      }
      count -= i;
      if (count <= 0) /* yes, should never be <, optionally fuss */
              break;
      cp += i;
      if (i == 0 {
              sleep(1);
              /* should probably count and break if too many */
      }
}

You're using a "for (;;)" where it isn't required - should be
"while (count != 0)", the "if (count <= 0) ..." should be nuked from orbit.

Hanlding write() returning 0 bytes, is, umm, bizarre ?  Carson never
said anything about non-blocking I/O but apparently it was implied.
That's a failure in the specification, I say :-)

Carson wanted specific handling of things like EINTR...

_______________________________________________
firewall-wizards mailing list
firewall-wizards () honor icsalabs com
http://honor.icsalabs.com/mailman/listinfo/firewall-wizards


Current thread: