static void handle_channel_msg(void * x) {
    Trap trap;
    ChannelNP * c = (ChannelNP *)x;
    int has_msg;

    assert(is_dispatch_thread());
    assert(c->magic == CHANNEL_MAGIC);
    assert(c->ibuf.handling_msg == HandleMsgTriggered);
    assert(c->ibuf.message_count);

    has_msg = ibuf_start_message(&c->ibuf);
    if (has_msg <= 0) {
        if (has_msg < 0 && c->chan.state != ChannelStateDisconnected) {
            trace(LOG_PROTOCOL, "Socket is shutdown by remote peer, channel %#lx %s", c, c->chan.peer_name);
            channel_close(&c->chan);
        }
    }
    else if (set_trap(&trap)) {
        if (c->chan.receive) {
            c->chan.receive(&c->chan);
        }
        else {
            handle_protocol_message(&c->chan);
            assert(c->out_bin_block == NULL);
        }
        clear_trap(&trap);
    }
    else {
        trace(LOG_ALWAYS, "Exception in message handler: %s", errno_to_str(trap.error));
        send_eof_and_close(&c->chan, trap.error);
    }
}
Пример #2
0
static void channel_receive(Channel * c) {
    struct channel_extra *ce = (struct channel_extra *)c->client_data;
    lua_State *L = ce->L;

    trace(LOG_LUA, "lua_channel_receive %p", c);
    if(ce->receive_cbrefp != NULL) {
        lua_rawgeti(L, LUA_REGISTRYINDEX, ce->receive_cbrefp->ref);
        if(lua_pcall(L, 0, 0, 0) != 0) {
            fprintf(stderr, "%s\n", lua_tostring(L,1));
            exit(1);
        }
    }
    handle_protocol_message(c);
}
Пример #3
0
static void proxy_receive(Channel * c) {
    Proxy * proxy = c->client_data;

    handle_protocol_message(proxy->proto, c);
}