sys-socket: Introduce some utility to make sockets more portable

Enterprise / Virtualization / SPICE - Frediano Ziglio [] - 7 May 2019 09:14 EDT

Between Unix and Windows socket are quite different:- on Windows sockets have a different namespace from C file descriptors so you can't use read/write/close or similar functions;- errors are not stored in errno but you must be read/write the errors with specific function;- sometimes sockets are put in non-blocking mode automatically calling some functions;- SOCKET type is 64 bit on Windows 64 which does not fit technically in an int. Is however safe to assume them to fit in an int.

So encapsulate the socket APIs in some definition to make easier and more safe to deal with them. Where the portability to Windows would make to code more offuscated a Unix style was preferred. For instance if errors are detected errno is set from Windows socket error instead of changing all code handling. Fortunately on Windows Qemu core interface accepts socket (but not other types like C file descriptors!).

55dd7410 sys-socket: Introduce some utility to make sockets more portable
server/ | 2 +
server/ | 2 +
server/sys-socket.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++
server/sys-socket.h | 139 ++++++++++++++++++++++++++++++++++
4 files changed, 353 insertions(+)


  • Share