f



BIND error after crash: how to reset winsock ?

Hello, I have a common problem, after my program crash without
cleaningup winsock correctly I can't bind anymore on the same port,
the only way I found is to restat my windows session.
I tried using SO_REUSEADDR but it just make the bind error hidding not
allowing the communication anymore.

Then as it don't seems to be a material problem (I tried
uninstalling / reinstalling my network card and still can't bind) I
would like to know how to reset the windows component handling the
bind fonction, in other words I would like to reset winsock.

Thanks
0
Greg2fs
4/12/2010 6:48:17 AM
comp.os.programmer.win32 14505 articles. 0 followers. Post Follow

9 Replies
786 Views

Similar Articles

[PageSpeed] 0

Greg2fs wrote:
> Hello, I have a common problem, after my program crash without
> cleaningup winsock correctly I can't bind anymore on the same port,
> the only way I found is to restat my windows session.
> I tried using SO_REUSEADDR but it just make the bind error hidding not
> allowing the communication anymore.
> 
> Then as it don't seems to be a material problem (I tried
> uninstalling / reinstalling my network card and still can't bind) I
> would like to know how to reset the windows component handling the
> bind fonction, in other words I would like to reset winsock.

That's the wrong solution. The right solution is to find out why your 
program is crashing, and fix it so that it doesn't crash any more.

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
0
Richard
4/12/2010 6:50:23 AM
On Apr 11, 11:48=A0pm, Greg2fs <greg...@gmail.com> wrote:

> Hello, I have a common problem, after my program crash without
> cleaningup winsock correctly I can't bind anymore on the same port,

What happens when you try?

> the only way I found is to restat my windows session.
> I tried using SO_REUSEADDR but it just make the bind error hidding not
> allowing the communication anymore.

What bind error?

> Then as it don't seems to be a material problem (I tried
> uninstalling / reinstalling my network card and still can't bind) I
> would like to know how to reset the windows component handling the
> bind fonction, in other words I would like to reset winsock.

You forgot to describe your problem. Does some Winsock function return
an error? If so, what function and what error? Or do the functions
succeed and then something doesn't happen? If so, what?

DS
0
David
4/12/2010 8:01:46 AM
On Apr 12, 7:50=A0am, Richard Heathfield <r...@see.sig.invalid> wrote:

> That's the wrong solution. The right solution is to find out why your
> program is crashing, and fix it so that it doesn't crash any more.

Of course he should be investigating the crashes but he'll be able to
do that a lot quicker if he doesn't have to restart his machine after
each crash. :)
0
Leo
4/12/2010 8:18:59 AM
Greg2fs wrote:
> Hello, I have a common problem, after my program crash without
> cleaningup winsock correctly I can't bind anymore on the same port,
> the only way I found is to restat my windows session.
> I tried using SO_REUSEADDR but it just make the bind error hidding not
> allowing the communication anymore.

The reason for that is probably that the socket is still considered in use,
which is also why you can patch it partially by using SO_REUSEADDR. There
are two reasons that could be the case:
1. The program is actually still running. A crash can mean pretty much
anything, it doesn't have to be the executable being terminated, which
would normally clean up the resources.
2. The timeout for the socket hasn't elapsed yet. I think that without
properly shutting down, it can take a minute until the port can be bound
again.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
4/12/2010 10:36:50 AM
My problem is than the bind function return -1
If I use SO_REUSEADDR the bind function doesn't return an error but
communcation between my server and client are like if the had returned
-1

For sur I have to avoid my program crashing and I do, but I often have
to stop debugging without letting my program close normaly and it
make me loosing a part of my time. And I think about if the problem
occurs for my users, they will say "f*c#ing app ! Uninstalling... !"

They from what you say it seems that there's no way to reset winsock...
0
Greg2fs
4/12/2010 2:52:41 PM
Greg2fs wrote:
> For sur I have to avoid my program crashing and I do, but I often have
> to stop debugging without letting my program close normaly and it
> make me loosing a part of my time. And I think about if the problem
> occurs for my users, they will say "f*c#ing app ! Uninstalling... !"

Greg, I'm working on a program here that includes a webserver, and I also
often kill the program from the debugger or when it crashes, but I never
had the problem you describe. I'm almost sure that it is something
different that's going wrong, I can't imagine an OS that is not capable of
cleaning up after an application has terminated.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
4/12/2010 3:12:58 PM
On Apr 12, 7:52=A0am, Greg2fs <greg...@gmail.com> wrote:

> My problem is than the bind function return -1
> If I use SO_REUSEADDR the bind function doesn't return an error but
> communcation between my server and client are like if the had returned
> -1

I'm not sure how that could be. If 'bind' fails, then 'listen' will
also fail. Are you saying when you use SO_REUSEADDR, 'listen' also
fails? What error does it report? You seem to be leaving out all the
details.

> For sur I have to avoid my program crashing and I do, but I often have
> to stop debugging without letting my program close normaly and it
> make me loosing a part of my time. And I think about if the problem
> occurs for my users, they will say "f*c#ing app ! Uninstalling... !"

For sure your users will be angry if your application crashes a lot.

DS
0
David
4/12/2010 4:17:18 PM
Greg2fs wrote:
> My problem is than the bind function return -1

Please read the docs at http://msdn.microsoft.com. It tells you exactly how
to detect errors and how to find further info.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
4/13/2010 6:41:14 AM
I don't use "listen" I work with udp conections...
For some days I finaly use SO_REUSEADDR and I didn't have problem
these days,
don't know what did make my program coundn't communicate.
But thanks for your help.
0
Greg2fs
4/14/2010 6:46:31 PM
Reply: