Make sure tx_write() and friends report -1 when TX layer flagged an error.

To help spotting a bug where a TX layer would be flagging an error and still
be reporting data written we wrap all the write calls and forcefully return -1
when that happens, with errno forced to EIO.

A message is logged with a stack trace to help diagnose the problem.  Upper
layers will then always check the returned amount of bytes written and will
properly do the necessary cleanup.