Skip to content

feat(lab7): implement iterative TCP server/client with dual-protocol parsing and tmux automation#9

Merged
Veexeq merged 9 commits into
mainfrom
lab7
May 26, 2026
Merged

feat(lab7): implement iterative TCP server/client with dual-protocol parsing and tmux automation#9
Veexeq merged 9 commits into
mainfrom
lab7

Conversation

@Veexeq
Copy link
Copy Markdown
Owner

@Veexeq Veexeq commented May 26, 2026

Description

This Pull Request introduces the complete implementation of Lab 7: Socket-based Inter-Process Communication. It delivers a robust, production-ready iterative TCP/IPv4 server capable of dual-protocol parsing (HTTP/1.1 and custom text commands), a dedicated network client utility, and a fully automated tmux integration testing harness.

The entire codebase is strictly compliant with the ISO C11 standard and enforces rigorous error policing (-Werror).

Technical Implementation Highlights

  • Dual-Protocol State Machine: The server listens on port 9000 across all interfaces (INADDR_ANY). It dynamically differentiates between incoming HTTP GET/POST sequences (incrementing the session counter by 1 and responding with compliant HTTP/1.1 plain-text payloads) and custom ZADANIE <value> datagram streams (incrementing the counter by the arbitrary integer and returning raw payload text).
  • Graceful Shutdown & Signal Hooking: Implemented a POSIX-compliant sigaction() interface to intercept SIGINT (Ctrl+C). It safely flips a volatile sig_atomic_t flag, enabling blocking system calls like accept4() to fail naturally with EINTR, breaking the main event loop, and executing clean descriptor deallocation.
  • Resource Leak Prevention: Utilizes the modern Linux-specific accept4() system call decorated with the SOCK_CLOEXEC flag to prevent descriptor pollution across process boundaries.
  • Network Resilience: Embedded the MSG_NOSIGNAL flag during standard send() routines to prevent the kernel from delivering a fatal SIGPIPE signal to the process if a client unexpectedly drops the connection.
  • Structural Portability: Full compliance with Network Byte Order conventions using htons() and htonl() macro wrappers.

Directory Topology Added

.
├── Makefile
├── bin/
├── obj/
├── include/
├── scripts/
│   └── test_automation.sh
└── src/
    ├── client/
    │   └── main.c
    └── server/
        └── main.c

Verification & Testing Performed

1. Automated Integration Test Suite

Validated end-to-end communication via the custom scripts/test_automation.sh harness. The execution sequence spawns a standalone tmux session, synchronizes local execution directories, runs sequential programmatic client queries, captures state tracking output, and triggers a clean shutdown.

chmod +x scripts/test_automation.sh
./scripts/test_automation.sh

2. Manual Diagnostics

  • Validated server compliance with local web browsers (HTTP GET /).
  • Simulated raw interface manipulation via netcat: echo -n "ZADANIE 42" | nc 127.0.0.1 9000.
  • Inspected network states using modern socket statistics utility: ss -tulpn.

3. Memory Profiling (Valgrind Audit)

Analyzed the executable layer via Valgrind Memcheck to verify strict memory management and prevent kernel object leaks.

valgrind --leak-check=full ./bin/server

Result: All heap blocks were freed -- no leaks are possible.

@Veexeq Veexeq self-assigned this May 26, 2026
@Veexeq Veexeq merged commit 2af123b into main May 26, 2026
1 check passed
@Veexeq Veexeq deleted the lab7 branch May 26, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant