Please find my full code on stack overflow, why it is crashed? please give
me a help. thanks...
https://stackoverflow.com/questions/49920982/libuv-udp-echo-server-regarding
Segmentation fault happened.
static void on_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
const struct sockaddr* addr, unsigned flags) {
if(addr == NULL || nread == 0){
printf("addr is null addr: [%p], nread: [%d]\n", addr, nread);
return;
}
printf("called next on rcv\n");
if (nread > 0) {
printf("%lu\n",nread);
printf("%s",rcvbuf->base);
}
printf("free :%lu %p handle: %p \n",rcvbuf->len,rcvbuf->base, handle);
free(rcvbuf->base);
uv_udp_send_t send_req;
char sender[17] = "";
struct sockaddr snd_addr;
uv_buf_t sndbuf = uv_buf_init("PONG",4);
uv_ip4_name((const struct sockaddr_in*) addr, sender, 16);
fprintf(stderr, "Recv from %s\n", sender);
if(uv_udp_send(&send_req, handle, (const struct uv_buf_t *)&sndbuf, 1,
(const struct sockaddr *)addr, on_send))
{
printf("error\n");
}
printf("send success\n");
return;}
crashed status:
----------------------
Program received signal SIGSEGV, Segmentation fault.0x0012af4a in
uv__udp_run_completed (handle=0x80491a0) at src/unix/udp.c:100100
QUEUE_REMOVE(q);(gdb) bt#0 0x0012af4a in uv__udp_run_completed
(handle=0x80491a0) at src/unix/udp.c:100#1 0x0012b111 in uv__udp_io
(loop=0x132800, w=0x80491e0, revents=4) at src/unix/udp.c:146#2 0x0011da69 in
uv__run_pending (loop=0x132800, mode=UV_RUN_DEFAULT) at src/unix/core.c:778#3
uv_run (loop=0x132800, mode=UV_RUN_DEFAULT) at src/unix/core.c:360#4
0x08048bf2 in main (argc=1, argv=0xbffffa14) at test-udp.c:108(gdb)
--
You received this message because you are subscribed to the Google Groups
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.