joyent / libuv

Go to
https://github.com/libuv/libuv
3.27k stars 653 forks source link

rfc: create sockets in uv_*_init() functions #368

Open bnoordhuis opened 12 years ago

bnoordhuis commented 12 years ago

Create sockets immediately in uv_tcp_init(), uv_udp_init(), etc. Don't defer until connect() or bind() time.

Benefits:

  1. Less complex, don't have to remember socket options[1].

Drawbacks:

  1. Changes API considerably. Caller now needs to specify the socket type upfront (e.g. IPv4 vs. IPv6). Then again, that means we can remove the uv_tcp_bind() / uv_tcp_bind4() dichotomy.
  2. Pushes burden of async error reporting in case of e.g. EMFILE to user.

I'm tentatively scheduling this for v0.8.

/cc @piscisaureus

[1] Currently broken in various ways. uv_tcp_keepalive() doesn't remember the delay, uv_udp_set_ttl() doesn't work at all, etc.

piscisaureus commented 12 years ago

@bnoordhuis

I think that would be better. Remarks:

saghul commented 10 years ago

This crossed my mind during the weekend, so I'll just dump some thoughts here, for whomever wants to read them :-)

indutny commented 10 years ago

+1, transitional AF_UNSPEC sounds fine.

saghul commented 10 years ago

Actually, it's not really transitional. We need to avoid binding the socket whendoping uv_accept. Do you have any other ideas on how to handle that case?

indutny commented 10 years ago

Why should we avoid doing it?

saghul commented 10 years ago

Well, imagine we always create the socket in uv_tcp_init. When you initialize the handle for uv_accept()-ing a connection, it would be a wasted effort because now you need to close it and replace it with what accept() returned.

indutny commented 10 years ago

Oh, I see... yeah, this is a bit of problem, indeed. Perhaps we could add API to queue handles ahead of time, but I'm not sure if the resulting code would be much better than the current one.