English 中文(简体)
Socket selected()在Windows工作,有时在短链氯化石蜡中消失
原标题:Socket select() works in Windows and times out in Linux

I m 把窗户网络应用到灯塔,并面临一个排时问题,选择电线。 在我用客户已经发送数据的包裹检查时,整个离职价值和收益的以下功能区块。

int recvTimeOutTCP( SOCKET socket, long sec, long usec )
{
  struct timeval timeout;
  fd_set fds;.

  timeout.tv_sec = sec;
  timeout.tv_usec = usec;
  FD_ZERO( &fds );
  FD_SET( socket, &fds );

  // Possible return values:
  // -1: error occurred
  // 0: timed out
  // > 0: data ready to be read
  cerr << "Waiting on fd " << socket << endl;
  return select(1, &fds, 0, 0, &timeout);
}
最佳回答

我认为,<代码>电子显示()的第一个参数应为socket+1

您确实应当使用另一个名称作为<代码>。 其他物品也使用。 通常使用<代码>sock。

问题回答

http://www.ohchr.org。 来自MSDN:

C++
int select(
  __in     int nfds,
  __inout  fd_set *readfds,
  __inout  fd_set *writefds,
  __inout  fd_set *exceptfds,
  __in     const struct timeval *timeout
);

Parameters

nfds [in]

    Ignored. The nfds parameter is included only for
    compatibility with Berkeley sockets.
...

问题是,气球中的脂肪是一环(最初只是一环,但你只能看看你工作的头16英寸)。 在窗户中,窗户是一系列长篇的袖珍(这就是为什么窗户不需要知道要看多少条块)。

民意测验职能有一系列记录,以观察气质,并具有比选择更好的选择的其他好处。

int recvTimeOutTCP( SOCKET socket, long msec )
{
    int iret ;
    struct polldf   sockpoll ;

    sockpoll.fd= socket ;
    sockpoll.events= POLLIN ;

    return poll(& sockpoll, 1, msec) ;
}   

选用手页:

int select(int nfds,
           fd_set* restrict readfds,
           fd_set* restrict writefds,
           fd_set* restrict errorfds, 
           struct timeval* restrict timeout);

每一组都检查了第一批Nfds的描述;即,描述器从0到Nfds-1的描述器都经过审查。

因此,第1个参数应排入1号。

return select(socket + 1, &fds, 0, 0, &timeout);

http://www.manpagez.com/man/2/select/“rel=“nofollow noretinger”>select(......)的第一项参数是文件记录员在册内核对的数量。 你的号召告诉我们,只有看档案记录员0,这几乎肯定不是socket





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签