gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Closing a socket connection using dswifi

#139123 - melw - Sun Sep 02, 2007 8:36 am

As yesterday I spent banging my head several hours to the wall before I got as simple thing as this working, here's how (using dswifi lib 0.3.2):

Code:
shutdown(sock, 2); // request shutdown for both read/write
for(int i=0;i<6;i++) swiWaitForVBlank(); // wait 100ms
closesocket(sock); // close socket for good

Explanation: Unlike lot of the other socket libraries, doing a mere closesocket() on closing socket doesn't send the other end FIN message. Instead shutdown() sets an internal flag and next time the Wifi_Timer() is being called it clears the shutdown sequence and sends a FIN/ACK message. If you call closesocket() right away after shutdown() it clears up the records and the timer has never a chance to send the final message.