sockets - send() 中的套接字错误 -- 没有这样的文件或目录

标签 sockets send errno

if (fcntl (i4SockDesc, F_SETFL, O_NONBLOCK) < 0)
{
    printf(LDP_IF_MISC, "LDPTCP: Client : Can't Set Sckt in NON BLK\n");
    return CONNECT_FAIL;
}

i4RetVal = send (i4SockDesc, (UINT1 *) pu1Data, u2BufLen, MSG_NOSIGNAL);
if (i4RetVal != u2BufLen)
{
    perror("Socket send failure!!\n");
    printf(i4SockDesc = %d, u2BufLen = %d, i4RetVal = %d\n", i4SockDesc, u2BufLen, i4RetVal);
    printf("Socket send Failure: %s, errno = %d\n",strerror(errno), errno);
}

send() 调用因错误“没有此类文件或目录”errno = 2 而失败。
i4SockDesc = 90, u2BufLen = 100, i4RetVal = -1
Socket send Failure: No such file or directory, errno = 2

最佳答案

如果 send() 还不算失败实际上发送更少的字节 han 请求。我想你的 errno更早发生。

i4RetVal < u2BufLen您应该在将“发送光标”推进 i4RetVal 后继续发送并将 buf 长度(更好:要发送的长度)减少相同的数量。

继续这样做,直到您真的发送了所有内容。

只有在 i4RetVal < 0 时才应该检查错误.

关于sockets - send() 中的套接字错误 -- 没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16601676/

相关文章:

bash - 将 Ctrl-A 和 Ctrl-D 从 shell 脚本发送到 GNU screen

node.js - Node 0.10。 net.Socket 上没有发出 'data' 事件

c++ - 从 C++ 程序向 Rails 服务器发送数据的最佳方式

.net - 队列不存在或您没有足够的权限来执行该操作。通过 MSMQ 发送消息时出现异常

python-2.7 - python多处理socket.error : [Errno 111] Connection refused?

php - 仅从错误代码获取 MySQL 错误消息

python - 操作系统错误 : [Errno 2] No such file or directory - code worked on new computer doesnt work on old one

python - 发送消息后关闭客户端套接字会导致错误

c++ - 没有 SSLManager 的 Poco SecureServerSocket

java - Android 客户端向 C 套接字服务器发送对象失败