Esempio n. 1
0
static void on_packet(void *ud, const char *buff, size_t len) {
    zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
    zn_sendprepare(&node->send, buff, len);
    zn_send(node->tcp,
            zn_sendbuff(&node->send),
            zn_sendsize(&node->send), on_send, node);
}
Esempio n. 2
0
static void on_client_packet(void *ud, const char *buff, size_t len) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    if (zn_sendprepare(&data->send, buff, len)
            && zn_send(data->tcp, zn_sendbuff(&data->send), zn_sendsize(&data->send),
                on_client_send, ud) != ZN_OK)
        client_error(data->tcp, ud);
}
Esempio n. 3
0
static void on_packet(void *ud, const char *buff, size_t len) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    if (zn_sendprepare(&data->send, buff, len)
            && zn_send(data->tcp, zn_sendbuff(&data->send), zn_sendsize(&data->send),
                on_send, ud) != ZN_OK)
    {
        zn_deltcp(data->tcp);
        zn_putbuffer(&pool, data);
    }
}
Esempio n. 4
0
static void on_send(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    if (err != ZN_OK) {
        zn_deltcp(tcp);
        zn_putbuffer(&pool, data);
        return;
    }
    if (zn_sendfinish(&data->send, count))
        zn_send(tcp, zn_sendbuff(&data->send), zn_sendsize(&data->send),
                on_send, ud);
}
Esempio n. 5
0
static void on_client_send(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    if (err != ZN_OK) {
        ++send_err;
        client_error(tcp, data);
        return;
    }
    ++send_ok;
    send_bytes += count;
    if (zn_sendfinish(&data->send, count))
        zn_send(tcp, zn_sendbuff(&data->send), zn_sendsize(&data->send),
                on_client_send, ud);
}
Esempio n. 6
0
static size_t on_header(void *ud, const char *buff, size_t len) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    printf("client(%p) send: %.*s\n", data->tcp, len, buff);
    if (zn_sendprepare(&data->send, buff, len)
            && zn_send(data->tcp,
                zn_sendbuff(&data->send),
                zn_sendsize(&data->send), on_send, ud) != ZN_OK)
    {
        zn_deltcp(data->tcp);
        zn_putbuffer(&pool, data);
    }
    return len;
}
Esempio n. 7
0
static void on_connect(void *ud, zn_Tcp *tcp, unsigned err) {
    zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
    if (err != ZN_OK) {
        zn_putbuffer(&pool, node);
        zn_deltcp(tcp);
        return;
    }
    ++connect_count;
    zn_recv(tcp,
        zn_recvbuff(&node->recv),
        zn_recvsize(&node->recv), on_recv, ud);
    if (zn_sendprepare(&node->send, data, DATA_SIZE+2))
        zn_send(tcp,
            zn_sendbuff(&node->send),
            zn_sendsize(&node->send), on_send, ud);
}
Esempio n. 8
0
static void on_connect(void *ud, zn_Tcp *tcp, unsigned err) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;

    if (err != ZN_OK) {
        client_error(tcp, ud);
        return;
    }

    if (zn_recv(tcp, zn_recvbuff(&data->recv), zn_recvsize(&data->recv),
                on_client_recv, ud) != ZN_OK)
        client_error(tcp, ud);
    else if (zn_sendprepare(&data->send, send_data, BLOCK_SIZE)
            && zn_send(tcp, zn_sendbuff(&data->send), zn_sendsize(&data->send),
                on_client_send, ud) != ZN_OK)
        client_error(tcp, ud);
}