I tried to open already opened UDP port and ACE_SOCK_Dgram::open() failed. As expected, strace shows that bind() failed and errno is set to EADDRINUSE.
To see what error happen,开发者_JAVA百科 I used ACE_OS::last_error(), but it's not updated.
I'd like to give informative error to user that the port already in use, instead of some general error.
Bonus question - when ACE_OS::last_error() can be used?
Tnx
It would have helped to if you provided more details. Which platform you were running your application on? What version of ACE library you are using? Was it a UDP port in a range 1-1024? Do you use broadcast UDP socket?
Let's assume that since you are checking "errno" not GetLastError() you are running on UNIX flavor such as Linux. Looking at OS_S_errno.inl you can find comments that describe the difference in behavior between different OS.
You are not asking why you getting EADDRINUSE for UDP socket in first place. Do you use SO_REUSEADDR option? If you do you should be aware that only last process that bound to the socket will be notified and behavior may vary between OS.
Is it possible that another system function call issued after bind() ? In that case error returned by bind() may be reset by system call that follow. As you can see from implementation of last_error() it is just sets "errno = ::GetLastError()" on windows and returns errno straight on UNIX.
I found the problem. I used ACE_OS::last_error() to macro (yes, macros are bad), which expanded to several links. One of the lines executed system call, and therefore value of errno changed
Have you tried just checking errno
yourself after the call to open? It seems to me that if errno == EADDRINUSE
you can handle it however you like from there, without needing ACE's help.
精彩评论