套接字异常:“端点映射器没有更多的端点可用” [英] Socket Exception: "There are no more endpoints available from the endpoint mapper"

查看:275
本文介绍了套接字异常:“端点映射器没有更多的端点可用”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用winsock和C ++来设置服务器应用程序。我遇到的问题是,调用 listen 会导致第一次机会异常。我猜通常这些可以忽略(?),但我发现其他人有相同的问题,我在哪里它导致应用程序挂一会儿一次。

I am using winsock and C++ to set up a server application. The problem I'm having is that the call to listen results in a first chance exception. I guess normally these can be ignored (?) but I've found others having the same issue I am where it causes the application to hang every once in a while. Any help would be greatly appreciated.

第一次机会例外是:


.exe:0x000006D9:端点映射器没有更多的端点。

First-chance exception at 0x*12345678* in MyApp.exe: 0x000006D9: There are no more endpoints available from the endpoint mapper.

我发现了一些证据,这可能是由套接字和我正在使用的代码如下。 listen 在底部第五行中发生异常。

I've found some evidence that this could be cause by the socket And the code that I'm working with is as follows. The exception occurs on the call to listen in the fifth line from the bottom.

  m_accept_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  if (m_accept_fd == INVALID_SOCKET)
  {
    return false;
  }

  int optval = 1;

  if (setsockopt (m_accept_fd, SOL_SOCKET, SO_REUSEADDR,
                  (char*)&optval, sizeof(optval)))
  {
    closesocket(m_accept_fd);
    m_accept_fd = INVALID_SOCKET;
    return false;
  }

  struct sockaddr_in  local_addr;
  local_addr.sin_family = AF_INET;
  local_addr.sin_addr.s_addr = INADDR_ANY;
  local_addr.sin_port = htons(m_port);

  if (bind(m_accept_fd, (struct sockaddr *)&local_addr,
           sizeof(struct sockaddr_in)) == SOCKET_ERROR)
  {
    closesocket(m_accept_fd);
    return false;
  }

  if (listen (m_accept_fd, 5) == SOCKET_ERROR)
  {
    closesocket(m_accept_fd);
    return false;
  }


推荐答案

你可能会用尽套接字。您可能需要调整一些TCPIP参数。在注册表中调整这两个:

On a very busy server, you may be running out of Sockets. You may have to adjust some TCPIP parameters. Adjust these two in the registry:

HKLM\System\CurrentControlSet\Services\Tcpip\Parameters
   MaxUserPort  REG_DWORD  65534 (decimal)
   TcpTimedWaitDelay REG_DWORD 60 (decimal)

在释放网络端口(套接字)和何时可以重用之间几分钟的延迟。此外,根据操作系统版本,只有几千的范围,Windows将使用。在服务器上,在命令提示符下运行此命令:

By default, there's a few minutes delay between releasing a network port (socket) and when it can be reused. Also, depending on the OS version, there's only a few thousand in the range that windows will use. On the server, run this at a command prompt:


netstat -an

netstat -an

并查看结果(管道到文件是最简单的:netstat -an> netstat.txt)。如果您看到大量端口从1025-> 5000在定时等待延迟状态,那么这是您的问题,它是通过使用上面的注册表项将最大用户端口从5000调整到65534解决。您也可以使用上面的注册表项来调整延迟,以更快速地回收端口。

and look at the results (pipe to a file is easiest: netstat -an > netstat.txt). If you see a large number of ports from 1025->5000 in Timed Wait Delay status, then this is your problem and it's solved by adjusting up the max user port from 5000 to 65534 using the registry entry above. You can also adjust the delay by using the registry entry above to recycle the ports more quickly.

如果这不是问题,那么问题可能是挂起您在Listen()方法中设置的连接。

If this is not the problem, then the problem is likely the number of pending connections that you have set in your Listen() method.

这篇关于套接字异常:“端点映射器没有更多的端点可用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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