C-chat
Classes | Macros | Typedefs | Functions | Variables
server.h File Reference

Header file for server.c. More...

#include "../common/sockets.h"
#include "../common/constants.h"
#include "../common/threads.h"
#include "../common/packets.h"
#include "../common/synchronization.h"

Go to the source code of this file.

Classes

class  Client
 A type representing a connected client. More...
 
struct  Room
 

Macros

#define NUMBER_CLIENT_MAX   10
 Maximum of simultaneous connected clients.
 
#define SYNC_CLIENT_READ(op)
 Macro to synchronize clients read operation. More...
 
#define SYNC_CLIENT_WRITE(op)
 Macro to synchronize clients write operation. More...
 
#define SYNC_ROOMS_READ(op)
 Macro to synchronize rooms read operation. More...
 
#define SYNC_ROOMS_WRITE(op)
 Macro to synchronize rooms write operation. More...
 
#define SYNC_ROOM_READ(room, op)
 Macro to synchronize read operation on a single room. More...
 
#define SYNC_ROOM_READ(room, op)
 Macro to synchronize read operation on a single room. More...
 

Typedefs

typedef struct Client Client
 
typedef struct Room Room
 

Functions

void handleServerClose (int signal)
 Catch interrupt signal. More...
 
void handleClientsPackets (Client *client)
 Relay messages sent by given client to all known clients. More...
 

Variables

ReadWriteLock clientsLock
 
ReadWriteLock roomsLock
 
Clientclients [NUMBER_CLIENT_MAX]
 
Roomrooms [NUMBER_ROOM_MAX]
 

Detailed Description

Header file for server.c.

Macro Definition Documentation

◆ SYNC_CLIENT_READ

#define SYNC_CLIENT_READ (   op)
Value:
acquireRead(clientsLock); \
op; \
releaseRead(clientsLock);

Macro to synchronize clients read operation.

◆ SYNC_CLIENT_WRITE

#define SYNC_CLIENT_WRITE (   op)
Value:
acquireWrite(clientsLock); \
op; \
releaseWrite(clientsLock);

Macro to synchronize clients write operation.

◆ SYNC_ROOM_READ [1/2]

#define SYNC_ROOM_READ (   room,
  op 
)
Value:
acquireRead(room->lock); \
op; \
releaseRead(room->lock);

Macro to synchronize read operation on a single room.

◆ SYNC_ROOM_READ [2/2]

#define SYNC_ROOM_READ (   room,
  op 
)
Value:
acquireRead(room->lock); \
op; \
releaseRead(room->lock);

Macro to synchronize read operation on a single room.

◆ SYNC_ROOMS_READ

#define SYNC_ROOMS_READ (   op)
Value:
acquireRead(roomsLock); \
op; \
releaseRead(roomsLock);

Macro to synchronize rooms read operation.

◆ SYNC_ROOMS_WRITE

#define SYNC_ROOMS_WRITE (   op)
Value:
acquireWrite(roomsLock); \
op; \
releaseWrite(roomsLock);

Macro to synchronize rooms write operation.

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

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.

acquireRead
void acquireRead(ReadWriteLock lock)
Acquires read lock on the given read/write lock.
Definition: synchronization.c:16
acquireWrite
void acquireWrite(ReadWriteLock lock)
Acquires write lock on the given read/write lock.
Definition: synchronization.c:38