-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start sync connection then switch to async #2285
Comments
I don't think you're queuing your writes. You must not have any more than one asynchronous write in progress at any one time. This example may help: |
You shouldn't mix sync and async on the same open socket. Pick one and use it. If you want your program to block until something takes place, use the |
@vinniefalco Do you say "shouldn't" because it's bad form or because it's not supported? If it's the former, that doesn't concern me. But if it fundamentally breaks what I'm trying to do than that's a different issue. |
The implementation does not guarantee that mixing sync and async will work. Don't do it. |
Thanks. Good to know. So for my original question, and in reading issue #1589, it seems that a single stream cannot have a pending async_read in progress when async_write is called. Is that correct? @madmongo1, in his response, says you can't have more than 1 of any type of async operation in progress so I'm a bit confused about what can actually be done. If I want an arbitrary bi-directional client/server flow where the server may send data to the client at some point in time not necessarily in response to a client operation and vice versa, is that possible on a single connection? |
You may have one read and one write and one close in progress at the same time. but you may not initiate a read while a read is in progress, etc. think of “chains” of these operations as running in parallel. Each chain governs one of the types of operation: read, write, close. |
Thanks to both of you and the great reference materials. I've gotten my fully async client/server working but the last piece I need is how an arbitrary client thread can queue a message to send to the server. In another comment (#1381), Vinnie wrote the following code
This is obviously a very simple question but how do you define
but for
But that causes an error saying So, how can I convert my |
Is spelled:
|
This issue has been open for a while with no activity, has it been resolved? |
I'm slowly getting my websocket client/server working but I've hit a wall.
I have the client setup the connection to the server synchronously because I don't want to the rest of the program running until a connection is made and the server accepts the client registration. Once it is connected and registered, I want to pass the connection context off to a thread so there can be async comms between the client and server.
After the registration, I can't get the async piece to work. Below is an example of what I'm trying to do. After the new thread is spun up, I call
run()
in theWSClientSession
class which callsasync_read.
on_read
is immediately called with zero bytes read and the following error:I then try to call
dowrite
which callsasync_write
but the same error occurs immediately.Finally, I call
run()
of my globalnet::io_context
variable but that also just returns immediately.Why does
on_read
get called as soon as I make theasync_read
call? And more importantly, how can I keep the thread running so there can be arbitrary back and forth comms between the client and server? The examples, while useful, are lacking in that respect.The text was updated successfully, but these errors were encountered: