Exemplo n.º 1
0
static void on_connect(void *ud, zn_Tcp *tcp, unsigned err) {
    if (err != ZN_OK)
        client_error(tcp);
    else if (zn_send(tcp, client.send, BLOCK_SIZE, on_client_send, &client) != ZN_OK)
        client_error(tcp);
    else if (zn_recv(tcp, client.recv, BLOCK_SIZE, on_client_recv, &client) != ZN_OK)
        client_error(tcp);
}
Exemplo n.º 2
0
static void on_accept(void *ud, zn_Accept *accept, unsigned err, zn_Tcp *tcp) {
    if (err != ZN_OK)
        return;
    if (zn_send(tcp, server.send, BLOCK_SIZE, on_send, &server) != ZN_OK)
        zn_deltcp(tcp);
    else if (zn_recv(tcp, server.recv, BLOCK_SIZE, on_recv, &server) != ZN_OK)
        zn_deltcp(tcp);
    zn_accept(accept, on_accept, ud);
}
Exemplo n.º 3
0
inline bool TcpSocket::doRecv(char* buf, unsigned len, OnRecvHandler&& h)
{
    if (zn_recv(tcp, buf, len, recv_cb, this) == ZN_OK)
    {
        recvHandler = std::move(h);
        return true;
    }
    return false;
}
Exemplo n.º 4
0
static void on_recv(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;
    }
    zn_recvfinish(&data->recv, count);
    zn_recv(tcp, zn_recvbuff(&data->recv), zn_recvsize(&data->recv),
            on_recv, ud);
}
Exemplo n.º 5
0
static void on_recv(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
    Userdata *data = (Userdata*)ud;
    if (err != ZN_OK) {
        ++data->recv_err;
        zn_deltcp(tcp);
        return;
    }
    ++data->recv_ok;
    data->recv_bytes += count;
    if (zn_recv(tcp, data->recv, BLOCK_SIZE, on_recv, ud) != ZN_OK)
        zn_deltcp(tcp);
}
Exemplo n.º 6
0
static void on_accept(void *ud, zn_Accept *accept, unsigned err, zn_Tcp *tcp) {
    zn_BufferPoolNode *data = zn_getbuffer(&pool);
    if (err != ZN_OK)
        return;
    zn_recvonheader(&data->recv, on_header, data);
    zn_recvonpacket(&data->recv, on_packet, data);
    data->tcp = tcp;
    if (zn_recv(tcp, zn_recvbuff(&data->recv), zn_recvsize(&data->recv),
                on_recv, data) != ZN_OK)
        zn_deltcp(tcp);
    zn_accept(accept, on_accept, ud);
}
Exemplo n.º 7
0
static void on_recv(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
    zn_BufferPoolNode *node = (zn_BufferPoolNode*)ud;
    if (err != ZN_OK) {
        zn_putbuffer(&pool, node);
        zn_deltcp(tcp);
        return;
    }
    recv_count += count;
    zn_recvfinish(&node->recv, count);
    zn_recv(tcp,
            zn_recvbuff(&node->recv),
            zn_recvsize(&node->recv), on_recv, ud);
}
Exemplo n.º 8
0
static void on_client_recv(void *ud, zn_Tcp *tcp, unsigned err, unsigned count) {
    zn_BufferPoolNode *data = (zn_BufferPoolNode*)ud;
    if (err != ZN_OK) {
        ++recv_err;
        client_error(tcp, data);
        return;
    }

    ++recv_ok;
    recv_bytes += count;
    zn_recvfinish(&data->recv, count);
    zn_recv(tcp, zn_recvbuff(&data->recv), zn_recvsize(&data->recv),
            on_client_recv, ud);
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
static void on_accept(void *ud, zn_Accept *accept, unsigned err, zn_Tcp *tcp) {
    zn_BufferPoolNode *node;
    if (err != ZN_OK)
        exit(2);
    ++connect_count;
    node = zn_getbuffer(&pool);
    zn_recvonheader(&node->recv, on_header, node);
    zn_recvonpacket(&node->recv, on_packet, node);
    node->tcp = tcp;
    if (zn_recv(tcp,
               zn_recvbuff(&node->recv),
               zn_recvsize(&node->recv), on_recv, node) != ZN_OK) {
        zn_putbuffer(&pool, node);
        zn_deltcp(tcp);
    }
    zn_accept(accept, on_accept, ud);
}