import socket


def recvtill(s, marker, bufsize=4096):
    """ Receive until marker is found, return received message with trailing marker removed """
    buflist = []
    while True:
        buf = s.recv(bufsize, socket.MSG_PEEK)
        if not buf:
            raise IOError("Expected more bytes")
        index = buf.find(marker)
        if index == -1:
            s.recv(len(buf))
            buflist.append(buf)
        else:
            s.recv(index+len(marker))
            buflist.append(buf[:index])
            return ''.join(buflist)