MCPcopy Create free account
hub / github.com/antirez/smallchat / freeClient

Function freeClient

smallchat-server.c:95–113  ·  view source on GitHub ↗

Free a client, associated resources, and unbind it from the global * state in Chat. */

Source from the content-addressed store, hash-verified

93/* Free a client, associated resources, and unbind it from the global
94 * state in Chat. */
95void freeClient(struct client *c) {
96 free(c->nick);
97 close(c->fd);
98 Chat->clients[c->fd] = NULL;
99 Chat->numclients--;
100 if (Chat->maxclient == c->fd) {
101 /* Ooops, this was the max client set. Let's find what is
102 * the new highest slot used. */
103 int j;
104 for (j = Chat->maxclient-1; j >= 0; j--) {
105 if (Chat->clients[j] != NULL) {
106 Chat->maxclient = j;
107 break;
108 }
109 }
110 if (j == -1) Chat->maxclient = -1; // We no longer have clients.
111 }
112 free(c);
113}
114
115/* Allocate and init the global stuff. */
116void initChat(void) {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected