Open noglass opened 6 years ago
Oh quit has been fixed in the devlop Branch. However, that has only been tested on Windows. However, I should be able to charrypick then into the master branch.
Also run blocks, do myClientClass(DISCORD_TOKEN, 3);
this will make the client use 3 threads and it'll call run on a sperate thread for you.
Actually, I just checked quit had already been fixed in the master branch. The issue had to do with websocketpp_websockets.cpp
, I've already talked about a fix in issue #63
run blocking isn't the issue here. In fact, I kind of want it to, but when it's no longer running, it should stop blocking. Unless there is a way to return the current connection state?
Also, confirmed the master branch no longer crashes when disconnecting, but it doesn't ever return focus to the main thread even when run with 3 threads, it still blocks.
Wait.. I was doing something wrong. I need to run more tests first..
Okay the real issue is that the SleepyDiscord::DiscordClient
constructor always calls run for you, even when in SLEEPY_ONE_THREAD
mode. This should not happen, especially in a single threaded environment.
Ah ha! Just defining SLEEPY_ONE_THREAD
isn't enough, I also had to set it to 1 on construction. Now everything works exactly as I would expect:
[2018-04-08 16:56:38] [connect] Successful connection
[2018-04-08 16:56:38] [connect] WebSocket Connection 104.16.60.37:443 v-2 "WebSocket++/0.7.0" /?v=6 101
[16:56:44] [Discord thread/MSG]: [nigel] !quit
[2018-04-08 16:56:44] [warning] got non-close frame while closing
[2018-04-08 16:56:44] [error] handle_read_frame error: asio.ssl.stream:1 (stream truncated)
[2018-04-08 16:56:49] [disconnect] Disconnect close local:[1006,stream truncated] remote:[1000]
[DEBUG] Discord disconnected.
As you can see, focus is returned to the main program when finished.
So now I have a new question. If run()
disconnects and you call run()
again, it doesn't do anything. Is there a way to make it reconnect?
the only place that run is called in the library is here https://github.com/yourWaifu/sleepy-discord/blob/master/sleepy_discord/client.cpp#L27
I'm was doing test as of yesterday and I didn't run into those issues, but they do sound simalar to some issues I ran into a while back that were fixed with these few lines. https://github.com/yourWaifu/sleepy-discord/blob/master/sleepy_discord/websocketpp_websocket.cpp#L57 please check you have these.
as for your 2nd comment, umm I've never thought of doing that but there is an undocumented function that may work for that situation. reconnect
in client.h. I'm not sure if it'll work here but worth a try I guess.
I was mistaken. I wasn't even calling run()
myself. I had a silly check: if (discord == nullptr)
before calling run()
, but after constructing it so it wasn't even calling it, the constructor was calling it on its own because I wasn't specifically telling it to only use 1 thread. (I thought defining SLEEPY_ONE_THREAD
was enough)
This issue can be closed now, everything works with the newest commit.
Thanks, I will try reconnect
!
I'm unable to return back to the rest of my code once I've run the run() function.
Maybe it's just me, but I feel like my program should be able to try to recover in the event of an error instead of just crashing.. I tried wrapping the run() in a try block, but that solved nothing.
My code (it is a shared library loaded by dlfcn.h):
Program output:
Sorry for the extra code and output, but thought it might prove somewhat helpful.
TL;DR: When calling
SleepyDiscord::DiscordClient::quit()
the program will hang until what I assume is a heartbeat that notices it's no longer connected, throws an uncaught exception and exits without allowing the rest of the program to finish running its course. This also happens when any error occurs.