'Write any buffer headers and payloads to the given connection.
Args:
conn : any object with a ``write_message`` method.
Typically, a Tornado WSHandler or WebSocketClientConnection
Returns:
int : number of bytes sent'

@gen.coroutine
def write_buffers(self, conn, locked=True):

    if (conn is None):
        raise ValueError('Cannot    write_buffers    to    connection    None')
    sent = 0
    for (header, payload) in self._buffers:
        (yield conn.write_message(header, locked=locked))
        (yield conn.write_message(payload, binary=True, locked=locked))
        sent += (len(header) + len(payload))
    raise gen.Return(sent)
