mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 18:54:38 +00:00
Reducing the ifdef-zoo a bit by moving the platform specific socket close calls into separate function. On win32, this also checks the retval and potentially query for error. On Unix, just calling close(). Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
49 lines
840 B
C
49 lines
840 B
C
/* SPDX-License-Identifier: MIT OR X11
|
|
*
|
|
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
|
*/
|
|
#include <dix-config.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef WIN32
|
|
#include <X11/Xwinsock.h>
|
|
#else
|
|
#include <sys/ioctl.h>
|
|
#endif
|
|
|
|
#include "os/ossock.h"
|
|
|
|
void ossock_init(void)
|
|
{
|
|
#ifdef WIN32
|
|
static WSADATA wsadata;
|
|
if (!wsadata.wVersion)
|
|
WSAStartup(0x0202, &wsadata);
|
|
#endif
|
|
}
|
|
|
|
int ossock_ioctl(int fd, unsigned long request, void *arg)
|
|
{
|
|
#ifdef WIN32
|
|
int ret = ioctlsocket(fd, request, arg);
|
|
if (ret == SOCKET_ERROR)
|
|
ret = WSAGetLastError();
|
|
return ret;
|
|
#else
|
|
return ioctl(fd, request,arg);
|
|
#endif
|
|
}
|
|
|
|
int ossock_close(int fd)
|
|
{
|
|
#ifdef WIN32
|
|
int ret = closesocket(fd);
|
|
if (ret == SOCKET_ERROR)
|
|
errno = WSAGetLastError();
|
|
return ret;
|
|
#else
|
|
return close(fd);
|
|
#endif
|
|
}
|