I understand,thank you very much. 在 2015年5月11日星期一 UTC+8下午3:45:40,Saúl Ibarra Corretgé写道: > > No. I mean you must allocate them on the heap, because they outlive the > function where you create them. > On May 11, 2015 9:42 AM, "simon yu" <[email protected] <javascript:>> > wrote: > >> so, you mean,I can't use UDP and TCP on the stack at the same time ? >> >> 在 2015年5月11日星期一 UTC+8下午3:17:12,Saúl Ibarra Corretgé写道: >>> >>> You are allocating the UDP and TCP handles on the stack. >>> On May 11, 2015 08:01, "simon yu" <[email protected]> wrote: >>> >>>> uv_loop_t *loop = NULL; >>>> void start_ev() >>>> { >>>> loop = uv_default_loop(); >>>> init_tcp(loop); >>>> init_udp(loop); >>>> >>>> uv_run(loop, UV_RUN_DEFAULT); >>>> } >>>> >>>> >>>> void init_tcp(uv_loop_t *loop) >>>> { >>>> struct sockaddr_in addr; >>>> uv_tcp_t server; >>>> char szIP[80],szPort[10]; >>>> int nPort; >>>> int r; >>>> >>>> GetCfg("server", "tcp_listen_ip", szIP, sizeof(szIP)); >>>> GetCfg("server", "tcp_listen_port", szPort, sizeof(szPort)); >>>> >>>> nPort = atoi(szPort); >>>> >>>> r = uv_tcp_init(loop, &server); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_tcp_init error,"<<uv_strerror(r)); >>>> return; >>>> } >>>> >>>> r = uv_ip4_addr(szIP, nPort, &addr); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_ip4_addr >>>> error,"<<uv_strerror(r)<<",ip="<<szIP<<",port="<<nPort); >>>> return ; >>>> } >>>> r = uv_tcp_bind(&server, (const struct sockaddr*)&addr, 0); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_tcp_bind error,"<<uv_strerror(r)); >>>> return ; >>>> } >>>> r = uv_listen((uv_stream_t*) &server, DEFAULT_BACKLOG, >>>> OnTcpNewConnection); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_listen error,"<<uv_strerror(r)); >>>> return ; >>>> } >>>> } >>>> >>>> void init_udp(uv_loop_t *loop) >>>> { >>>> struct sockaddr_in addr; >>>> uv_udp_t server; >>>> char szIP[80],szPort[10]; >>>> int nPort; >>>> int r; >>>> >>>> GetCfg("server", "udp_listen_ip", szIP, sizeof(szIP)); >>>> GetCfg("server", "udp_listen_port", szPort, sizeof(szPort)); >>>> >>>> nPort = atoi(szPort); >>>> >>>> r = uv_udp_init(loop, &server); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_udp_init error"<<uv_strerror(r)); >>>> return; >>>> } >>>> >>>> r = uv_ip4_addr(szIP, nPort, &addr); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_ip4_addr >>>> error,"<<uv_strerror(r)<<",ip="<<szIP<<",port="<<nPort); >>>> return ; >>>> } >>>> r = uv_udp_bind(&server, (const struct sockaddr*)&addr, 0); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_udp_bind error"<<uv_strerror(r)); >>>> return ; >>>> } >>>> r = uv_udp_recv_start(&server, AllocBuffer, OnUDPRead); >>>> if (r != 0) >>>> { >>>> LOG_FATAL("uv_udp_recv_start error"<<uv_strerror(r)); >>>> return ; >>>> } >>>> } >>>> >>>> >>>> XXXXXXX: src/unix/linux-core.c:170: uv__io_poll: Assertion `w->fd < >>>> (int) loop->nwatchers' failed. >>>> 已放弃 (core dumped) >>>> >>>> GDB: >>>> #0 0x00007f5fb86b8885 in raise () from /lib64/libc.so.6 >>>> #1 0x00007f5fb86ba065 in abort () from /lib64/libc.so.6 >>>> #2 0x00007f5fb86b19fe in __assert_fail_base () from /lib64/libc.so.6 >>>> #3 0x00007f5fb86b1ac0 in __assert_fail () from /lib64/libc.so.6 >>>> #4 0x000000000053df7f in uv__io_poll (loop=0x2901a720, timeout=-1) at >>>> src/unix/linux-core.c:170 >>>> #5 0x000000000053550d in uv_run (loop=0x2901a720, mode=UV_RUN_DEFAULT) >>>> at src/unix/core.c:324 >>>> #6 0x0000000000425d3a in start_ev () at RiskServer.cpp:6215 >>>> >>>> -- >>>> 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 http://groups.google.com/group/libuv. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] <javascript:> >> . >> Visit this group at http://groups.google.com/group/libuv. >> For more options, visit https://groups.google.com/d/optout. >> >
-- 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 http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
