Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux setsockopt(TCP_节点延迟,1):权限被拒绝_Linux_Sockets_Nagle - Fatal编程技术网

Linux setsockopt(TCP_节点延迟,1):权限被拒绝

Linux setsockopt(TCP_节点延迟,1):权限被拒绝,linux,sockets,nagle,Linux,Sockets,Nagle,我有一些代码自90年代以来一直在工作,现在在Linux上试图关闭Nagle算法时被拒绝了权限。阅读手册页和谷歌搜索并没有说明原因。有什么想法吗 int iFlags, iSize; /* NOTE: Sol 2.8 header requires socklen_t but man page says int! */ int iSizeSize = sizeof( iSize ); #ifdef _WIN32 unsigned long ulMSDummy;

我有一些代码自90年代以来一直在工作,现在在Linux上试图关闭Nagle算法时被拒绝了权限。阅读手册页和谷歌搜索并没有说明原因。有什么想法吗

  int iFlags, iSize;

  /* NOTE: Sol 2.8 header requires socklen_t but man page says int! */

  int iSizeSize = sizeof( iSize );

#ifdef _WIN32
  unsigned long      ulMSDummy;
  if ( ioctlsocket( iFD, FIONBIO, (u_long FAR*) &ulMSDummy ) != 0 ) {
      printf( "%s: ioctlsocket( %s:%d, FIONBIO, 1 ): %s",
           pszName, pszAddr, iPort, strerror(errno));
      return -1;
  }
#else
  if ( ( iFlags = fcntl( iFD, F_GETFL, 0 ) ) < 0 ) {
      AKWarn( "%s: fcntl( %s:%d, F_GETFL ): %s",
           pszName, pszAddr, iPort, strerror(errno));
      return -1;
  }

  // NOTE: O_NDELAY may need to be changed to FNDELAY on some
  // platforms (which does the same thing) or O_NONBLOCK (which may
  // cause AKread() to return different values when there's no data).
  // Any of these three make the socket non-blocking, which is
  // DIFFERENT from TCP_NODELAY (see below).

  if ( fcntl( iFD, F_SETFL, iFlags | O_NDELAY ) < 0 ) {
      printf( "%s: fcntl( %s:%d, F_SETFL, +NDELAY ): %s",
           pszName, pszAddr, iPort, strerror(errno));
      return -1;
  }
#endif

  // NOTE: TCP_NODELAY is unrelated to the various NDELAY/NONBLOCK
  // options (above).  Instead, it disables the "Nagle Algorithm",
  // which caches tiny packets.

  // NOTE: This option hardcodes a tradeoff for less latency and more
  // packets.  Actually this could be a configuration parameter.

  iFlags = 1;
  if ( setsockopt( iFD, SOL_SOCKET, TCP_NODELAY,
                   (char*) &iFlags, sizeof( int ) ) ) {
      printf( "%s: setsockopt( %s:%d, TCP_NODELAY, %d ): %s",
           pszName, pszAddr, iPort, iFlags, strerror(errno) );
#ifndef __linux__
      return -1; // giving Permission denied on Linux???
#endif
  }
intiflags,iSize;
/*注意:Sol 2.8页眉需要socklen_t,但手册页上显示int*/
int-iSizeSize=sizeof(iSize);
#ifdef_WIN32
未签名的长乌尔姆;
如果(ioctlsocket(iFD,FIONBIO,(u_long FAR*)和ulMSDummy)!=0){
printf(“%s:ioctlsocket(%s:%d,FIONBIO,1):%s”,
pszName、pszAddr、iPort、strerror(errno));
返回-1;
}
#否则
如果((iFlags=fcntl(iFD,F_GETFL,0))<0){
AKWarn(“%s:fcntl(%s:%d,F_GETFL):%s”,
pszName、pszAddr、iPort、strerror(errno));
返回-1;
}
//注:在某些情况下,O_NDELAY可能需要更改为FNDELAY
//平台(做同样的事情)或O_NONBLOCK(可能
//使AKread()在没有数据时返回不同的值)。
//这三个选项中的任何一个都可以使套接字不阻塞,即
//不同于TCP_节点延迟(见下文)。
如果(fcntl(iFD、F|U SETFL、iFlags | O|U NDELE)<0){
printf(“%s:fcntl(%s:%d,F_SETFL,+NDELAY):%s”,
pszName、pszAddr、iPort、strerror(errno));
返回-1;
}
#恩迪夫
//注:TCP_节点延迟与各种NDELAY/NONBLOCK无关
//选项(见上文)。相反,它禁用了“Nagle算法”,
//它可以缓存小数据包。
//注意:此选项硬编码是一个折衷方案,可以减少延迟,提高效率
//包。实际上,这可能是一个配置参数。
iFlags=1;
if(设置锁定选项)(iFD、SOL_插槽、TCP_节点延迟、,
(字符*)&iFlags,sizeof(int))){
printf(“%s:setsockopt(%s:%d,TCP\u节点延迟,%d):%s”,
pszName、pszAddr、iPort、iFlags、strerror(errno));
#ifndef\uuu linux__
return-1;//在Linux上拒绝授予权限???
#恩迪夫
}
这从一开始就是错误的。它应该是IPPROTO_TCP,而不是SOL_套接字。这些是不同的常数。可能它以前从未正常工作过,即做了超出您预期的事情


这从一开始就是错误的。它应该是IPPROTO_TCP,而不是SOL_套接字。这些是不同的常数。很可能它以前从未正常工作过,即做了超出您预期的事情。

奇怪。什么改变了?Linux升级?事实上,我第一次注意到它在Linux 2.4.20上停止工作,但我在警告后添加了条件编译不中止。后来我忘了,现在又注意到了——但它仍然不起作用。我想知道我是不是只是把int的大小弄错了还是什么。奇怪。什么改变了?Linux升级?事实上,我第一次注意到它在Linux 2.4.20上停止工作,但我在警告后添加了条件编译不中止。后来我忘了,现在又注意到了——但它仍然不起作用。我想知道我是不是只是把int的大小弄错了什么的。实际上,它应该是
SOL\u TCP
@MartinRosenau:明确地说
IPPROTO\u TCP
。但这两个常数实际上是一样的。谢谢Steffen!是的,古虫子。。。我不知道它在遥远的过去做了什么,但Linux上的TCP_节点延迟目前值为1。SOL_SOCKET的值1可能是SO_DEBUG,我认为这不是用户级程序要激活的…实际上,它应该是
SOL_TCP
@MartinRosenau:明确地说
IPPROTO\u TCP
。但这两个常数实际上是一样的。谢谢Steffen!是的,古虫子。。。我不知道它在遥远的过去做了什么,但Linux上的TCP_节点延迟目前值为1。SOL_SOCKET的值1可能是SO_DEBUG,我想这不是用户级程序要激活的。。。
 if ( setsockopt( iFD, SOL_SOCKET, TCP_NODELAY,