static void new_connection(void *ud, zn_State *S) { zn_BufferPoolNode *data = zn_getbuffer(&pool); zn_recvonheader(&data->recv, on_header, data); zn_recvonpacket(&data->recv, on_client_packet, data); data->tcp = zn_newtcp(S); if (zn_connect(data->tcp, addr, port, on_connect, data) != ZN_OK) zn_post(S, new_connection, NULL); }
static zn_Time on_client(void *ud, zn_Timer *timer, zn_Time elapsed) { zn_BufferPoolNode *node = zn_getbuffer(&pool); zn_Tcp *tcp = zn_newtcp(S); zn_recvonheader(&node->recv, on_header, node); zn_recvonpacket(&node->recv, on_packet, node); node->user_data = 0; node->tcp = tcp; zn_connect(tcp, addr, port, on_connect, node); return 1; }
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_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); }