![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Regression: a listening bind is EXCLUSIVE on every platform. More...
#include "nilorea/n_log.h"#include "nilorea/n_network.h"#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Functions | |
| static int | check_exclusive (int udp) |
| Bind a listener, then try to bind the same port again; the second must fail. | |
| int | main (void) |
Regression: a listening bind is EXCLUSIVE on every platform.
netw_make_listening and netw_bind_udp set SO_REUSEADDR so a restarted listener can re-take the port it just released. That option means the opposite thing on Windows: it lets an UNRELATED process bind over a socket already holding the port, the second bind succeeds, and which socket receives a given connection is undefined. A program that reports "listening" while another process owns the port is worse than one that refuses to start, so the option is POSIX-only and this example holds that contract in place.
The port is taken from the OS rather than hardcoded, so the check cannot fail because some unrelated service happened to own a fixed number.
Definition in file ex_bind_exclusive.c.
|
static |
Bind a listener, then try to bind the same port again; the second must fail.
| udp | non-zero to test netw_bind_udp, zero for netw_make_listening. |
Definition at line 28 of file ex_bind_exclusive.c.
References LOG_ERR, LOG_INFO, n_log, netw_bind_udp(), netw_close(), netw_make_listening(), NETWORK_IPV4, and port.
Referenced by main().
| int main | ( | void | ) |
Definition at line 98 of file ex_bind_exclusive.c.
References check_exclusive(), LOG_INFO, and set_log_level().