C-chat
Functions | Variables
server.c File Reference

Server file. More...

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include "server.h"
#include "../common/packets.h"
#include "communication.h"
#include "handshake.h"
#include "client-info.h"
#include "file-transfer.h"
#include "room.h"

Functions

void handleServerClose (int signal)
 Catch interrupt signal. More...
 
void handleClientsPackets (Client *client)
 Relay messages sent by given client to all known clients. More...
 
THREAD_ENTRY_POINT clientThread (void *idPnt)
 
int main ()
 Program entry point.
 

Variables

ReadWriteLock clientsLock
 
ReadWriteLock roomsLock
 
Clientclients [NUMBER_CLIENT_MAX] = {NULL}
 
Roomrooms [NUMBER_ROOM_MAX] = {NULL}
 

Detailed Description

Server file.

Allows multiple clients to discuss, relaying messages between them.

Function Documentation

◆ handleClientsPackets()

void handleClientsPackets ( Client client)

Relay messages sent by given client to all known clients.

Waits for an incoming message, and broadcast it (in a correctly formed relayed message) to all known clients.

Parameters
clientThe client to wait messages from

◆ handleServerClose()

void handleServerClose ( int  signal)

Catch interrupt signal.

Parameters
signalIncoming signal

Variable Documentation

◆ rooms

Room* rooms[NUMBER_ROOM_MAX] = {NULL}

An array containing all pointers to existing rooms.

It can be written by any client thread at any time if a client creates or deletes a room. It can be read by any client thread at any time if a client joins a room.

We MUST acquire roomsLock to access this field.