- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在创建一个 UDP 套接字 (centos 6),我想用它发送广播消息。一切正常,创建套接字有效 - socket(..) 返回 value=25,但是:
int val = 1;
if (setsockopt(a, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) < 1){
debug("setsockoopt failed with errno: %d, socket %d", errno, a);
}
setsockopt 将 errno 设置为 value = 2。通信正常,我将 udp 数据包发送到 x.x.x.255 主机,我所有的应用程序都收到了它,但我想知道 errno 是从哪里来的(errno=2=没有这样的文件或目录)
最好的问候
最佳答案
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
来自 setsockopt manpage成功返回 0,所以这只是你的条件错误。如果没有错误,errno 的值是不相关的,这就是为什么在这里你得到一个相当荒谬的值。
if (setsockopt(a, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) != 0){
是你需要的。
关于c - setsockopt 返回 errno=2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7498191/
有没有人知道 setsockopt() 的等价物,它适用于基于非套接字的文件描述符? 具体来说,考虑这段代码: int on = 1; setsockopt(socketfd, SOL_SOCKET,
我的查询与 setsocketopt() api 中的“SO_RCVBUF”选项有关。setsockopt()中为SO_RCVBUF指定的新值何时生效? 我正在测试 TCP/IP 的流量控制,下面是我
我正在使用通过 TCP 通信使用 XML 的代码。此实现对每个 send() 和 recv() 都有 10 秒超时,以使用 setsockopt() 等待整个数据。经过一段时间的工作后,我发现有时 r
我需要更改 sk_rcvlowat程序应用程序到性能测试。有没有办法从命令行更改套接字选项?否则,我们必须更改所有应用程序的源代码并重新编译它们。我想每个套接字都与一个 inode 相关联, 这样我们
来源: WSADATA WSAData; SOCKET sock; if (WSAStartup(MAKEWORD(2,2), &WSAData)!=0) { printf("\nProble
以下 C 语言服务器无法按预期工作。第一次运行时,没有出现任何问题。每次您下次运行它时,它都无法绑定(bind)。无论 setsockopt(...) 是否成功,有些人可能会标记为重复的问题的解决方案
我正在尝试通过 Ipv4 和 Ipv6 协议(protocol)加入多播组,对于 Ipv4 我成功加入了多播组但对于 Ipv6 使用此 tutorial但我做不到。我的代码是: ipv6_mreq m
假设我在 C++ 中有以下代码,它将为套接字设置超时: struct timeval time_val_struct = { 0 }; time_val_struct.tv_sec = 1; time
我正在尝试编写一个简单的 UDP 服务器,在多播组上公布其服务端口,但我无法让多播正常工作。我尝试查看 Microsoft 文档并复制/粘贴他们的一些代码,但它不起作用。这是有问题的代码: t
我是套接字编程的新手。我正在尝试编写一个基本的套接字编程程序。我查看了 socket()、bind()、setsockopt() 函数和其他函数的用法以及工作代码示例。在 setsockopt() 函
现在,我正在尝试使用以下代码通过 setsockopt() 指定选项: // bind socket // Use setsockopt() function to make sure the por
我正在尝试运行一个示例来演示使用 GSOAP 的发现功能。不幸的是,我似乎在 setsockopt 上得到了 -1 关于为什么会发生这种情况的任何建议?错误号是无效的参数。 const char* h
我在树莓派上运行自己的 http 服务器。问题是当我停止程序并重新启动它时,该端口不再可用。有时我在收到大量请求时会遇到同样的问题。 我想使用 SO_REUSEADDR 这样即使发生错误我也可以继续使
我的客户端应用程序使用套接字作为 http 连接,意味着一次性发送、接收和关闭,我考虑使用单个持久连接,而不是每次单独连接,但问题是,有时服务器收到 2 个数据包32 kiB,而单个数据包为 64ki
我正在使用超时在套接字上发送和接收数据。我发现可以通过将套接字设置为非阻塞模式并使用 select 来实现超时。或使用 setsockopt与 SO_SNDTIMEO/SO_RCVTIMEO选项。 这
我的代码旨在使用一个套接字(winsock2.h 之一)在两台计算机之间建立简单的连接,但是如果没有有效的 errno(一个空的 errno,除非我初始化)setsockopt 阶段不起作用(返回一个
我正在用 C 语言进行一些基本的套接字编程,并且在我尝试运行代码的每台计算机上都遇到了此错误。代码编译得很好,但是当我尝试运行它时,我收到错误setsockopt:协议(protocol)不可用。这似
当我从 msdn link 查看 setsockopt 时.我遇到了一个参数 SO_RCVTIMEO,它的描述是“设置超时,以毫秒为单位,用于阻止接收调用。”我认为套接字监听操作是事件驱动的,这意味着
我正在尝试调用 setsockopt但无法弄清楚 c_void 的转换。 IP_HDRINCL 不在 nix 或 socket 包中,所以我必须使用 libc。我以 How to set the so
下面的 playground 演示了这个问题。 //: Playground - noun: a place where people can play import Foundati
我是一名优秀的程序员,十分优秀!