Tal A.
Tal A.

Reputation: 407

close() vs. shutdown() with recv()

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?

Upvotes: 0

Views: 1403

Answers (2)

Tal A.
Tal A.

Reputation: 407

I figured it out. Set the socket with SO_LINGER and thus cause an abortive shutdown. Now it returns -1 after shutdown().

Upvotes: 2

Vinit Dhatrak
Vinit Dhatrak

Reputation: 7034

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.

Upvotes: 0

Related Questions