D-Bus 1.4.0
dbus-sockets-win.h
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-sockets.h Wrappers around socket features (internal to D-BUS implementation)
00003  * 
00004  * Copyright (C) 2005 Novell, Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 #ifndef DBUS_SOCKETS_H
00025 #define DBUS_SOCKETS_H
00026 
00027 #if defined(DBUS_WIN) || defined(DBUS_WINCE)
00028 
00029 
00030 
00031 #ifndef STRICT
00032 #define STRICT
00033 #include <winsock2.h>
00034 #undef STRICT
00035 #endif
00036 #include <winsock2.h>
00037 
00038 #undef interface
00039 
00040 #if HAVE_ERRNO_H
00041 #include <errno.h>
00042 #endif
00043 
00044 /* Make use of the fact that the WSAE* error codes don't
00045  * overlap with errno E* codes. Wrapper functions store
00046  * the return value from WSAGetLastError() in errno.
00047  */
00048 #if defined(EPROTONOSUPPORT) || \
00049     defined(EAFNOSUPPORT) || \
00050     defined(EWOULDBLOCK)
00051 #error This does not look like Win32 and the Microsoft C library
00052 #endif
00053 
00054 #define DBUS_SOCKET_IS_INVALID(s) ((SOCKET)(s) == INVALID_SOCKET)
00055 #define DBUS_SOCKET_API_RETURNS_ERROR(n) ((n) == SOCKET_ERROR)
00056 #define DBUS_SOCKET_SET_ERRNO() (_dbus_win_set_errno (WSAGetLastError()))
00057 
00058 #define DBUS_CLOSE_SOCKET(s) closesocket(s)
00059 
00060 #else
00061 
00062 #include <sys/socket.h>
00063 #include <sys/un.h>
00064 #include <netinet/in.h>
00065 #include <netdb.h>
00066 #include <errno.h>
00067 
00068 #define DBUS_SOCKET_IS_INVALID(s) ((s) < 0)
00069 #define DBUS_SOCKET_API_RETURNS_ERROR(n) ((n) < 0)
00070 #define DBUS_SOCKET_SET_ERRNO() /* empty */
00071 
00072 #define DBUS_CLOSE_SOCKET(s) close(s)
00073 
00074 #endif /* !Win32 */
00075 
00076 #endif /* DBUS_SOCKETS_H */