|
Event-Driven Programming in C++ 1.0
A case study on event-driven programming in C++
|
Demonstrates cross-platform monitoring of both socket events and console I/O. More...
#include <iostream>#include <string>#include <chrono>#include <thread>#include <algorithm>#include <sys/select.h>#include <sys/socket.h>#include <arpa/inet.h>#include <unistd.h>#include <fcntl.h>#include "logger.hpp"Namespaces | |
| namespace | io_and_sockets |
| Provides cross-platform functionality for monitoring I/O and socket events. | |
Macros | |
| #define | PORT 12345 |
| The port number on which the TCP server listens. | |
Functions | |
| void | io_and_sockets::close_socket (int s) |
| Closes a socket on POSIX systems. | |
| int | io_and_sockets::runDemo () |
| Run demo for the I/O and socket monitoring example. | |
Demonstrates cross-platform monitoring of both socket events and console I/O.
This example creates a simple TCP server that listens on port 12345 for incoming connections and monitors console input for commands. The example is designed to run on both Windows and POSIX systems, using platform-specific mechanisms:
select() system call is used to monitor both the server socket and the standard input (STDIN_FILENO).select() function monitors the server socket, while _kbhit() is used in a polling loop to check for console input.Typing "quit" at the console terminates the server loop.
| #define PORT 12345 |
The port number on which the TCP server listens.