Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, One of the classics problems in Unix/Linux socket programming, is to force cancel block operation (accept, recv ...). Here is description of my problem: I have thread which ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    6

    How to cancel socket block operation

    Hi All,

    One of the classics problems in Unix/Linux socket programming,
    is to force cancel block operation (accept, recv ...).
    Here is description of my problem:

    I have thread which is blocked with socket function recv (I am waiting for data from client). But it is situation when I need to cancel
    recv blocking, and send data to client using this socket.

    Question: how to cancel recv operation, to have ability to use this socket for sending data (so we can/t close socket).

    Mutlithreading implemented using POSIX threads.

    One of the ways how to deal with this problem, is to use pthread_kill.

    Second way - using non-blocking sockets and select function, but I would like to avoid this way.

    If somebody know other ways to resolve this problem, I will be very thankful for your help.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Typically you set a timer which will raise a signal. When you return from the signal handler, recv will return an EINTR error if there was no data to process. Since you are using pthreads, then you will want to use pthread_kill in order to deliver the signal to the thread in question. The thread receiving the signal can handle it as appropriate - it doesn't need to die.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    6
    Thanks guys,
    I also found other methods of resolving this problem, but I should try it first, to be sure.
    Will try all known solutions, and will report you about results.

    Thanks!

Posting Permissions

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