Replies: 15 comments
|
Disconnect? Just call uv_close(). uv_shutdown() is for when you want to signal you're going to close one end of the connection for reading or writing, but that's unnecessary if you want to disconnect immediately. |
|
Wild guess: you're freeing or reusing the uv_tcp_t's memory before the close callback is called. |
No, all memory releases are done in callback functions. I have checked and found that it is not a problem with my code, but rather an internal issue with the libuv library |
|
You're hitting an assert in libuv but that's not an internal issue, that's libuv telling you the handle got corrupted somehow. |
How can I explain why my program links to the released libuv library and still runs normally with the same code? |
|
Because the release build doesn't have debug asserts enabled of course. |
After multiple verifications, I found an issue where the client, after successfully connecting to the server, actively disconnects using uv_close in two situations without transmitting data. Repeatedly connecting and disconnecting the same uv_tcp_t object to the server within 10 times can cause an exception to pop up. This situation occurs when debugging or releasing when bored. |
`static void XXXXXXX::AsyncServerThread(void arg) }`My client event loop is placed in a separate thread, separate from Qt's event loop |
|
Are you accessing the uv_tcp_t (or any handle except uv_async_t) from multiple threads? Don't do that. |
The client has only two threads, the qt main event loop thread and the libuv event loop thread (running the uv_run() function). The main thread accesses the uv_tcp_t object to connect and disconnect from the server. If two threads are not opened, what should be done for the event loops of uv and qt? |
I don't quite understand this document. How to embed other event loops |
|
Use a uv_async_t and a message queue (e.g. linked list protected by a mutex) to send messages from your qt thread to the uv thread. That is:
Read the uv_async_t/uv_async_send documentation carefully. |
I see! No wonder I said the server can automatically shut down normally, why can't the client? The server (which is a command-line program) performs all operations on the main thread. Thank you very much for your answer. Thank you very much for your hard work. |
|
Converted to a discussion as this wasn't actually a bug report. |
Uh oh!
There was an error while loading. Please reload this page.
Hello, in the windowns 10 x64 msvc environment, how can the client actively disconnect from the server after successfully connecting to the server and there is no data transmission between the client and the server? I use uv_sthutdown (req, (uv_steam_t *)&socket,&onShutdownEvent) in the Debug library of libuv; We did not receive the onShutdownEvent callback, although the uv_sthutdown return value is 0
All reactions