'Process an individual wire protocol fragment.
The websocket RFC specifies opcodes for distinguishing
text frames from binary frames. Tornado passes us either
a text or binary string depending on that opcode, we have
to look at the type of the fragment to see what we got.
Args:
fragment (unicode or bytes) : wire fragment to process'

@gen.coroutine
def on_message(self, fragment):

    try:
        message = (yield self._receive(fragment))
    except Exception as e:
        log.error('Unhandled    exception    receiving    a    message:    %r:    %r', e, fragment, exc_info=True)
        self._internal_error('server    failed    to    parse    a    message')
    try:
        if message:
            work = (yield self._handle(message))
            if work:
                (yield self._schedule(work))
    except Exception as e:
        log.error('Handler    or    its    work    threw    an    exception:    %r:    %r', e, message, exc_info=True)
        self._internal_error('server    failed    to    handle    a    message')
    raise gen.Return(None)
