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

Function sendMsgToAllClientsBut

smallchat-server.c:135–145  ·  view source on GitHub ↗

Send the specified string to all connected clients but the one * having as socket descriptor 'excluded'. If you want to send something * to every client just set excluded to an impossible socket: -1. */

Source from the content-addressed store, hash-verified

133 * having as socket descriptor 'excluded'. If you want to send something
134 * to every client just set excluded to an impossible socket: -1. */
135void sendMsgToAllClientsBut(int excluded, char *s, size_t len) {
136 for (int j = 0; j <= Chat->maxclient; j++) {
137 if (Chat->clients[j] == NULL ||
138 Chat->clients[j]->fd == excluded) continue;
139
140 /* Important: we don't do ANY BUFFERING. We just use the kernel
141 * socket buffers. If the content does not fit, we don't care.
142 * This is needed in order to keep this program simple. */
143 write(Chat->clients[j]->fd,s,len);
144 }
145}
146
147/* The main() function implements the main chat logic:
148 * 1. Accept new clients connections if any.

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected