(lwip)套接字发送()返回“连接”
我正在维护使用LWIP的嵌入式系统。相关代码如下(编辑):
iobSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connectRC = connect(socket, &serverAddress, sizeof(struct sockaddr));
FD_SET(socket, &fdset);
selectRC = select((socket) + 1, NULL, &fdset, NULL, &tv);
sendRC = send(iobSocket, dout, strlen(dout), 0);
这似乎有效。但是,当我删除select()调用时,我在send()上会收到一个错误,该错误将ERRNO设置为119或已在进行中的连接。此错误代码未记录在Send()MAN页面中。
有人可以告诉我为什么在这里甚至需要select()命令,为什么如果没有它,我可能会遇到无证件错误?
谢谢。
I'm maintaining an embedded system that uses LwIP. The relevant code is as follows (edited):
iobSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connectRC = connect(socket, &serverAddress, sizeof(struct sockaddr));
FD_SET(socket, &fdset);
selectRC = select((socket) + 1, NULL, &fdset, NULL, &tv);
sendRC = send(iobSocket, dout, strlen(dout), 0);
This seems to work. When I remove the select() call, however, I get an error on the send() which sets errno to 119 or Connection already in progress. This error code isn't documented in the send() man pages.
Can someone tell me why the select() command is even necessary here, and why I might be getting an undocumented error without it?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误代码119是
einprogress
。这意味着该插座在非阻滞模式 1 中运行,并且以前send()
失败。1 :这意味着,您必须有更多的代码,因为插座通常在最初创建时处于阻止模式,并且需要明确的代码将其放置进入非阻滞模式,例如通过
fcntl(f_setfl,o_nonblock);
。使用
select()
来测试套接字的写入性,允许您的代码等待直到插座实际完成并准备好发送。这在
Error code 119 is
EINPROGRESS
. It means the socket is operating in non-blocking mode 1, and the previousconnect()
operation hasn't finished yet, which is why thesend()
fails.1: Which means, there must be more code that you are not showing, as sockets are normally in blocking mode when they are initially created, and require explicit code to put them into non-blocking mode, such as via
fcntl(F_SETFL, O_NONBLOCK);
.Using
select()
to test the socket for writability allows your code to wait until the socket is actually done connecting and is ready for sending.This is explained in the man page for
connect()
: