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); }
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); }
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); }
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); }
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); }
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); }
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); }