skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.84k stars 209 forks source link

How to handle an existing UNIX socket? #257

Closed nmkoremblum closed 2 years ago

nmkoremblum commented 2 years ago

Hi!

I am trying to handle a UNIX socket (PipeHandle) and I noticed that, when using the bind method, it creates such a file on the system. Now I am facing the problem that, when the socket already exists on the filesystem, the bind method fails, even though no other process is using it. I've also tried using connect but it fails too.

Do you have any advice on how to handle this situation?

Thanks in advance!

stefanofiorentino commented 2 years ago

Ciao @nmkoremblum, it is a thing that the application developer should take care of. If the application fails for whatever reason, it's its responsibility to cleanup dangling files. From the other way round, you can always cleanup on startup if you need to (not the best way, but works in many environment). Is it more clear to you now? Do you agree?

nmkoremblum commented 2 years ago

Hi @stefanofiorentino! Thanks for answering :smile: I was expecting to have a workaround for connecting to an existing socket, of course removing the dangling files came up to my mind, but it seemed to be a naive solution. So, if there is no other way, I will go with that solution. Thanks again :)

skypjack commented 2 years ago

Consider that uvw doesn't add anything on top of libuv, it's just a wrapper to correctly manage memory automatically. Therefore, if it's not possible with libuv, it's not possible with uvw. I guess we're in this case here. 🙂

stefanofiorentino commented 2 years ago

Exactly, I'm sure there isn't a cross-platform way to do it. So no way libuv supports it. I'll close this, feel free to reopen in case you think it needs more discussion.