Skip to main content
3 of 3
edited body
vnp
  • 57.3k
  • 4
  • 51
  • 140

I hope I am not overusing assert calls

You do. assert is a debugging instrument. If NDEBUG macro is defined, the calls to assert are removed at the compile time. This is a usual practice for the production code.

  • #define whaterror strerror(errno)

    I advise against it. The macro adds no value, and only obfuscates the code.

  • memset(malloc

    Keep in mind that malloc may fail.

  • memset(bytes == -1 ? chunk : chunk + bytes, 0, BUFFSIZE);

    Setting BUFFSIZE bytes to 0 writes beyond the allocated space. You need BUFFSIZE - bytes.

    On the other hand, clearing the entire tail of the chunk is not necessary. chunk[bytes] = 0; is enough.

  • !errno ?, besides being another obfuscation, is quite wrong. errno is a way to inspect errors, not to detect them. In fact, quoting man errno,

    Successful calls never set errno; once set, it remains until another error occurs.

    recv returning -1 is one and only indication of error.

  • Since the socket is not marked nonblocking, it may never return EAGAIN. On the other hand, some errors are transient, and should not break the loop.

vnp
  • 57.3k
  • 4
  • 51
  • 140