Added callback for write protocol, added drain support for piping.