jeikabu / runng

MIT License
25 stars 3 forks source link

How do I close a connection? #26

Closed najamelan closed 5 years ago

najamelan commented 5 years ago

I see that structs like protocol::pair1::Pair1 have methods like dial and listen, but not close?

I wondered about this after running into this problem. Messages get dropped because the sender shuts down before they have finished sending. I wasn't using threads, but when sleeping 500ms before shutting the program down I can't reproduce the problem anymore, so I suppose it's what happens.

I wondered if a close method could flush the connection and then disconnect? And if that could prevent problems like this.

jeikabu commented 5 years ago

NngSocket has a Arc<InnerSocket> with impl Drop. I should document that somewhere. Thanks for these suggestions, it's very helpful to get a second opinion.

najamelan commented 5 years ago

Ok, so I can do pair1.socket() to obtain NngSocket, but then how do I make it drop?

You're most welcome for the feedback. Thanks for writing this. IPC isn't trivial right now in rust. And yeah, zeromq seems to be a bit dated.

jeikabu commented 5 years ago

You should just need to do:

{
    let socket: protocol::pair1::Pair1 = // create it
    // Do whatever
} // Last `Arc` reference goes away calling `InnerSocket.Drop()` which calls `nng_close()`

Relevant code is here