如何从异步套接字报告错误连接? [英] How is an error reported from async socket connect?

查看:128
本文介绍了如何从异步套接字报告错误连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我异步连接套接字(O_NONBLOCK +连接)。 POSIX标准规定了插座已经连接后应通过套接字准备好写入文件描述符信号事件。这似乎并不在异步连接要说失败什么。

I'm connecting a socket asynchronously (O_NONBLOCK + connect). POSIX standard specifies that after socket has been connected is should signal the event by making the file descriptor for the socket ready for writing. It doesn't seem to say anything about failures during async connect.

在Linux上测试它,看来有时候我越来越POLLOUT有时POLLERR在这种情况下。是否有行为的任何模式?我可以把它在一个单一的方式报告错误?难道POSIX说什么我都忽略了?

When testing it on Linux, it seems that sometimes I'm getting POLLOUT and sometimes POLLERR in this situation. Is there any pattern in the behaviour? Can I make it report the errors in a single way? Does POSIX say something I have overlooked?

推荐答案

Ð。伯恩斯坦有一些东西,看起来像它可能是相关的: http://cr.yp.to /docs/connect.html 。他特别提出了几种不同的方式来得到错误的。

D. J. Bernstein has some stuff that looks like it might be relevant: http://cr.yp.to/docs/connect.html. In particular he suggests several different ways to get errors out.

在Unix套接字常见问题与超时在连接部分,这包括使用从失败的连接得到错误的getsockopt

The UNIX Socket FAQ has a section on Connect with timeout, that includes getting the error from a failed connection using getsockopt

这篇关于如何从异步套接字报告错误连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆