Make select() return
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Make select() return

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    20

    Make select() return

    Hi All
    I want to use select() socket function with NULL timeout so that it will wait indefinitely. In such case, is there a way to make select() return? Can I add two file descriptors to select, one for network events and the other one, say, user defined events? And if yes, is there a way to set this user fd so that select() returns?

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Make select() return

    What is it you are attempting to do? select() will block until one of up to three conditions are met when using the fd_set parameters for read, write, or error; or after the timeout set in timeval has elapsed.

  3. #3
    Join Date
    Jan 2010
    Posts
    20

    Re: Make select() return

    What is it you are attempting to do?
    Nothing very fancy, I'm afraid. I want to do something like WSAWaitForMultipleEvents() (with infinite timeout) Win32 API call sort of trick with select(). I want to set fd1 and fd2 for, say, read file descriptor while fd1 would be a socket (return value of a socket() call) to get the network events and fd2 would be in my control.
    Or, int other words. I know select() returns when one of the file descriptors is set by a network event. The question is, may I set this file desriptor explicitly from another thread when the original thread blocks on select() ?

  4. #4
    Join Date
    Sep 2005
    Location
    New Delhi, India
    Posts
    332

    Re: Make select() return

    Quote Originally Posted by stolencoin View Post
    What is it you are attempting to do?
    Nothing very fancy, I'm afraid. I want to do something like WSAWaitForMultipleEvents() (with infinite timeout) Win32 API call sort of trick with select(). I want to set fd1 and fd2 for, say, read file descriptor while fd1 would be a socket (return value of a socket() call) to get the network events and fd2 would be in my control.
    Or, int other words. I know select() returns when one of the file descriptors is set by a network event. The question is, may I set this file desriptor explicitly from another thread when the original thread blocks on select() ?
    If you want your other thread which is in your control to make select call return, you can also send a signal.
    Appreciate others by rating good posts

    "Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett

  5. #5
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Make select() return

    I suppose the other thread could close or shutdown the socket which would flag the error fd_set and break out of the select() block.

    I generally run an infinite loop with a reasonable timeout for the select() timeval ("reasonable" requires some experimenting), then break out of the loop once all data have been read or written.

  6. #6
    Join Date
    Jan 2010
    Posts
    20

    Re: Make select() return

    Thanks hoxsiew, I'll try what you suggested.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center