MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / nw_CloseSocket

Function nw_CloseSocket

networking/networking.cpp:1677–1730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1675}
1676
1677void nw_CloseSocket(SOCKET *sockp) {
1678 reliable_header diss_conn_header;
1679#ifdef WIN32
1680 if (DP_active) {
1681 dp_DirectPlayDestroyPlayer(*sockp);
1682 return;
1683 }
1684#endif
1685
1686 if (*sockp >= MAXRELIABLESOCKETS) {
1687 mprintf(0, "Invalid socket id passed to nw_NewCloseSocket() -- %d\n", *sockp);
1688 return;
1689 }
1690
1691 if (reliable_sockets[*sockp].status == RNF_UNUSED) {
1692 mprintf(0, "Trying to close an unused socket (%d) -- ignoring request.\n", *sockp);
1693 }
1694 mprintf(0, "Closing socket %d\n", *sockp);
1695 // Go through every buffer and "free it up(tm)"
1696 int i;
1697 for (i = 0; i < MAXNETBUFFERS; i++) {
1698 if (reliable_sockets[*sockp].rbuffers[i]) {
1699 mem_free(reliable_sockets[*sockp].rbuffers[i]);
1700 reliable_sockets[*sockp].rbuffers[i] = NULL;
1701 reliable_sockets[*sockp].rsequence[i] = 0;
1702 }
1703 if (reliable_sockets[*sockp].sbuffers[i]) {
1704 mem_free(reliable_sockets[*sockp].sbuffers[i]);
1705 reliable_sockets[*sockp].sbuffers[i] = NULL;
1706 reliable_sockets[*sockp].rsequence[i] = 0;
1707 }
1708 }
1709 diss_conn_header.type = RNT_DISCONNECT;
1710 diss_conn_header.seq = INTEL_SHORT((int16_t)(CONNECTSEQ));
1711 diss_conn_header.data_len = 0;
1712 if (*sockp == serverconn)
1713 serverconn = -1;
1714
1715 network_address send_address;
1716 memset(&send_address, 0, sizeof(network_address));
1717
1718 send_address.connection_type = reliable_sockets[*sockp].connection_type;
1719 if (NP_TCP == reliable_sockets[*sockp].connection_type) {
1720 SOCKADDR_IN *inaddr = (SOCKADDR_IN *)&reliable_sockets[*sockp].addr;
1721 memcpy(send_address.address, &inaddr->sin_addr, 4);
1722 send_address.port = htons(inaddr->sin_port);
1723 send_address.connection_type = NP_TCP;
1724 }
1725
1726 nw_SendWithID(NWT_RELIABLE, (uint8_t *)&diss_conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZE, &send_address);
1727
1728 memset(&reliable_sockets[*sockp], 0, sizeof(reliable_socket));
1729 reliable_sockets[*sockp].status = RNF_UNUSED;
1730}
1731
1732int nw_CheckReliableSocket(int socknum) {
1733 // Checks to see if a socket is connected or not.

Callers 6

MultiSendConnectBailFunction · 0.85
MultiDoLeaveGameFunction · 0.85
MultiCheckListenFunction · 0.85
MultiDisconnectPlayerFunction · 0.85
TryToJoinServerFunction · 0.85
MultiCloseGameFunction · 0.85

Calls 2

nw_SendWithIDFunction · 0.85

Tested by

no test coverage detected