'Return a GrrQueue message list from the queue, draining it.
This is used to get the messages going _TO_ the server when the
client connects.
Args:
max_size: The size (in bytes) of the returned protobuf will be at most
one message length over this size.
Returns:
A MessageList protobuf'

def Drain(self, max_size=1024):

    queue = rdf_flows.MessageList()
    length = 0
    for message in self._out_queue.Get():
        queue.job.Append(rdf_flows.GrrMessage.FromSerializedString(message))
        stats.STATS.IncrementCounter('grr_client_sent_messages')
        length += len(message)
        if (length > max_size):
            break
    return queue
