tags:

views:

202

answers:

2

I have the following code:

Client side:

n=recv(sock,buf,1200,NULL);

Server side:

shutdown(sockk,SD_BOTH);

The problem is, the client side recv is returning 0, meaning graceful shutdown. I need it to return -1 (I can't change the client side, I need to adapt my code to it.)

What can i do to cause it returning -1?

A: 

Do not call shutdown() or close() from server, and you can then send some signal to the client side process. So recv() call will return -1 with errno set with EINTR. Hope this helps.

But I suggest you should not adopt such coding practice. recv() can return 0, +ve number and -1. Its good to handle all these cases.

vinit dhatrak
+1  A: 

i figured it out. set my socket with SO_LINGER and caused abortive shutdown, now it returns -1 after shutdown(). thanks

John