etcimon / libasync

Cross-platform event loop library of asynchronous objects
MIT License
147 stars 30 forks source link

Refresh m_local after bind #62

Closed dazoe closed 8 years ago

dazoe commented 8 years ago

Sorry for all the pull requests, but here is another feature/bug fix.

Using AsyncTCPListener and AsyncUDPSocket if you've used 0 as the port local() will always return port 0. When you bind on port 0 the OS will pick one for you. After which you need to call getsockname to ask the OS which port was assigned. I didn't see an easy we to do this with out modifying the library. I figured after the run call there wasn't any problem with asking the os to just update m_local weather or not port 0 was used. Although I think the only time getsockname will return something different than what you passed to bind is if port 0 was used.

etcimon commented 8 years ago

Might be able to avoid a system call if you do an if m_local.port == 0 first

dazoe commented 8 years ago

Added port ==0 check

etcimon commented 8 years ago

thanks!