Re: reuse of socket handles

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mike McMahon (MikeMcMahon_at_discussions.microsoft.com)
Date: 01/27/05


Date: Thu, 27 Jan 2005 05:21:01 -0800

Yes. You are right. So let me explain the scenario.

Say you have two threads. One is performing blocking recvfrom() calls on the
socket and the second one closes the socket. There is a window
between when the first thread acquires the socket handle and when
it calls recvfrom(), during which the socket could be closed and
the handle allocated to some other newly created socket. When the
first thread calls recvfrom() it will be operating on the new socket
and it has no way to know.

Say you try to protect the socket with a mutex and all threads
using the socket need to hold the mutex, then it is no longer
possible to pre-empt blocking calls like recvfrom() with closesocket()
(called from a different thread).

So maybe I could add the following pieces to the question:

- is there some way to close a socket without releasing the handle ?

- is there some other way to make this work?

Thanks
Mike.

"Gabriel Bogdan" wrote:
> You should desing your code to work corectly even if this happens.
> And, there is no way to guarantee it won't happen no matter what you do to
> the sistem.
>
>
> "Mike McMahon" <MikeMcMahon@discussions.microsoft.com> wrote in message
> news:B1DC1D73-0505-4F64-8A4A-2BA2B3C03215@microsoft.com...
> > We have run into a problem which we think may be caused
> > by socket handles being recycled, by which I mean when
> > you close a socket, and create a new one around the same time,
> > the new socket gets the same handle as the old one.
> >
> > My question is if there is some way of tweaking the system
> > to increase the number of handles, or modifying the handle allocation
> behavior
> > in some way to reduce the probability of handles being recycled like this?
> >
> > The OS would be Windows 2000, or XP.
> >
> > Thanks
> > Mike.
>
>
>



Relevant Pages

  • Re: recvfrom returns with an error code of 14, EFAULT "Bad Address"
    ... the socket up in case I did something wrong. ... The code is at the bottom of the page again. ... recvfrom I am initializing it to NULL. ... the size of the packet received and instead it was the size of the ...
    (comp.unix.programmer)
  • Re: call is blocked in recvfrom() and no further proceedings in Wi
    ... I have tested it on real device. ... call is blocked in recvfrom() and no further proceedings). ... >> My program has to send request to service through port 5070(in this port ... Received the response in Windows(means, for reception I created socket ...
    (microsoft.public.windowsce.embedded)
  • Re: UDP packets receiving...
    ... yes i realized that it is already a blocking function and i wrapped it ... non blocking or blocking socket code:- ... (note that if there are multiple UDP packets recieved and waiting ... than recvfrom is a blocking function.... ...
    (microsoft.public.win32.programmer.networks)
  • Re: UDP packets receiving...
    ... yes i realized that it is already a blocking function and i wrapped it ... non blocking or blocking socket code:- ... (note that if there are multiple UDP packets recieved and waiting ... than recvfrom is a blocking function.... ...
    (microsoft.public.win32.programmer.networks)
  • O_NOBLOCK increases UDP socket latency
    ... receiver side, I use the recvfrom() call to read data from the network ... the socket to non-blocking mode by setting the O_NONBLOCK flag. ... milliseconds to several hundred ...
    (comp.programming)