setsockopt() SO_RCVTIMEO zurücksetzen

Thomasio

Erfahrenes Mitglied
Ich experimentiere mit timeouts bei blocking Sockets.

Code:
int timeout = 5000;
long rc = 0;
char buffer[101];

setsockopt(Socket,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(int));
rc = recv(Socket,buffer,100,0);

Das klappt prima, er bricht den recv() nach 5 Sekunden ab.
Nur wenn ich danach den timeout zurücksetzen will, so dass er nicht mehr abbricht, dann geht das nicht.

Code:
timeout = 0;
setsockopt(Socket,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(int));
rc = recv(Socket,buffer,100,0);

Bricht immer sofort ab, sprich er wartet tatsächlich 0ms.
Soweit ich es bei MSDN gelesen habe, sollte 0 aber soviel wie kein timeout heissen.

Wie bringe ich ihn dazu den timeout aufzuheben, bzw. auf default zurückzusetzen?
 
Hi.

MSDN hat gesagt.:
If a send or receive operation times out on a socket, the socket state is indeterminate, and should not be used; TCP sockets in this state have a potential for data loss, since the operation could be canceled at the same moment the operation was to be completed.
Gruß
 
Hmm, das heisst ich kann timeout nur zum Abbrechen der Verbindung nutzen.
Nicht ganz was ich wollte, aber wenigstens weiss ich woran es liegt.
Vielen Dank für den Hinweis.
 
Zurück