Open bnoordhuis opened 12 years ago
@bnoordhuis
I think that would be better. Remarks:
This crossed my mind during the weekend, so I'll just dump some thoughts here, for whomever wants to read them :-)
uv_accept
is called the fd has already been accepted, so we shouln't initialize the socket when initializing the client handle. AF_UNSPEC could be used in that case, which wouldn't bind the socket in init.+1, transitional AF_UNSPEC
sounds fine.
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?
Why should we avoid doing it?
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.
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.
Create sockets immediately in uv_tcp_init(), uv_udp_init(), etc. Don't defer until connect() or bind() time.
Benefits:
Drawbacks:
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.