How muxy03/progetto-finale works
Project Type and Purpose
• This is a distributed, concurrent client-server/archive system:
• Clients (two C programs: “type A” and “type B”) send requests over TCP.
• A Python server accepts socket connections and forwards each line (prefixed by its length) into a set of POSIX FIFOs.
• An “archivio” C program reads from those FIFOs, spawns threads (writers, readers, and their “capo” supervisors), manages a linked list buffer, and writes/archives the data.
File Structure
• Top-level files:
• client1.c, client2.c ← two client implementations
• server.py ← central TCP acceptor & FIFO writer
• archivio.c ← archive manager: thread pool + linked list
• progetto.c / progetto.h ← shared definitions, data structures (Buffer, GArg, SLArg, CArg, Node)
• makefile ← build rules
• file1, file2, file3 ← output archives or test inputs
• Key IPC/Concurrency artifacts:
• POSIX sockets (HOST, PORT in progetto.h)
• Named FIFOs for “type A” vs “type B” channels
• pthreads (writers, readers, capo threads)
• Mutexes for list/head/tot synchronization
• Signal handler for graceful shutdown (writing “2049” into FIFOs)
README for Architecture Insights
• Server protocol: prefix messages by length (ASCII), clients choose “0” or “1” to select FIFO A or B.
• Archivio uses five custom structs (Buffer, GArg, SLArg, CArg, Node) to manage its thread-pool pipeline.
• A global linked list holds pending records; two globals (head, tot) track the queue.
• Signal handler safely prints/logs and flips a “fine” flag under mutex.
a. Main Components
1. Clients
• Client A (C)
• Client B (C)
2. Server (Python)
3. Archivio (C)
• Signal Handler
• Dispatcher (“Gestore”) threads
• Scrittore threads + Capo-Scrittore
• Lettore threads + Capo-Lettore
• Linked-List buffer + Mutex (ht_mutex)
4. Archives (file1, file2, file3)
b. Relationships & Data Flows
1. Clients → TCP Socket → Server
2. Server → writes “length” + “line” messages → Named FIFO A or FIFO B
3. Archivio:
– FIFO reader (“Gestore”) threads read FIFO A/B → enqueue Node into linked list
– Scrittore threads dequeue, write to file archives
– Lettore threads may perform read/validation
– Capo threads supervise worker threads, handle termination signal
4. Signal Handler injects termination messages (“2049”) into FIFOs and sets fine=1
c. Architectural Patterns & Design Principles
• Producer–Consumer pipeline via FIFOs + thread queue
• Thread-pool pattern (workers + “capo” supervisors)
• Shared linked-list protected by mutex (ht_mutex)
• Graceful shutdown via signal + sentinel message
d. Key Technologies
• POSIX sockets (TCP)
• Named FIFOs (mkfifo)
• pthreads + mutexes
• C data structures (Buffer, Node)
• Python for socket acceptor
Essential Elements
• Annotations on key data structures (e.g., Buffer struct, Node struct).