ACE_SOCK_Dgram::open() 和 errno
我尝试打开已打开的 UDP 端口,但 ACE_SOCK_Dgram::open() 失败。 正如预期的那样,strace 显示bind() 失败并且errno 设置为EADDRINUSE。
为了查看发生了什么错误,我使用了 ACE_OS::last_error(),但它没有更新。
我想向用户提供有关端口已在使用中的信息错误,而不是一些一般错误。
额外问题 - 何时可以使用 ACE_OS::last_error()?
总氮
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, 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您提供更多详细信息,将会有所帮助。您在哪个平台上运行您的应用程序?您使用的 ACE 库版本是什么?它是 1-1024 范围内的 UDP 端口吗?你使用广播UDP套接字吗?
假设您正在检查“errno”而不是 GetLastError(),因此您正在 UNIX 风格(例如 Linux)上运行。查看 OS_S_errno.inl,您可以找到描述不同操作系统之间行为差异的注释。
您并不是在问为什么首先要获得 UDP 套接字的 EADDRINUSE 。您使用 SO_REUSEADDR 选项吗?如果您这样做,您应该意识到只有绑定到套接字的最后一个进程才会收到通知,并且不同操作系统的行为可能会有所不同。
在bind()之后是否可能发出另一个系统函数调用?在这种情况下,bind() 返回的错误可能会被随后的系统调用重置。从last_error()的实现中可以看出,它只是在Windows上设置“errno = ::GetLastError()”,并在UNIX上直接返回errno。
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.
我发现了问题。我使用 ACE_OS::last_error() 来宏(是的,宏很糟糕),它扩展到多个链接。其中一行执行了系统调用,因此 errno 的值发生了变化
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
您是否尝试过在调用 open 之后自己检查 errno ?在我看来,如果 errno == EADDRINUSE ,您可以从那里随心所欲地处理它,而不需要 ACE 的帮助。
Have you tried just checking
errno
yourself after the call to open? It seems to me that iferrno == EADDRINUSE
you can handle it however you like from there, without needing ACE's help.