Identifying Server graceful shutdown

Hi
I have written a Client server Application .The client will receive messages from Server and pass it to some library for processing .I also want to notify server close the socket connection gracefully.

Roughly my code is some kind of

void getMsg()
{
while(recv(....)>0)
{
cout<<"Process Message";
}
cout<<"Server Disconnected";
}

The problem with the above code is of server get crash because of some reason recv function is returning 0 immediately .But There is no way to identify from client side whether server is close gracefully or because of some error .

Is there any way to identify them .

If it really returned zero, then, according to recv's manpage the shutdown was orderly -- you were informed the socket was going away. You didn't have to wait several minutes before timing out. It's not disorderly, simply unexpected, and your code is the only that might realize that, TCP/IP wouldn't know.

Thanks for your reply.
But I need to write log based on if server is shutdown gracefully or because of some Crash.

There's only so much you can learn from a lack of information.

If you weren't expecting even a graceful close, you can probably mark that down to either a server bug, server crash, or someone killing that program. I'd have expected an actual error return from a network problem. And if it breaks gracelessly that could be either a network problem or someone pulling the plug(data, power, whatever -- yours or theirs!). Experiment with it a bit, see what results you get from different kinds of failures. There might be nothing for it but to see if it's possible to recontact the server after the socket close to tell the difference between some failures.