KDECore
syssocket.h
Go to the documentation of this file.
00001 /* -*- C++ -*- 00002 * Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org> 00003 * 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining 00006 * a copy of this software and associated documentation files (the 00007 * "Software"), to deal in the Software without restriction, including 00008 * without limitation the rights to use, copy, modify, merge, publish, 00009 * distribute, sublicense, and/or sell copies of the Software, and to 00010 * permit persons to whom the Software is furnished to do so, subject to 00011 * the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00021 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 #ifndef KDE_SYSSOCKET_H 00026 #define KDE_SYSSOCKET_H 00027 00028 #ifdef KSOCKETBASE_H 00029 #error syssocket.h must be included before ksocketbase.h! 00030 #endif 00031 00032 // needed for Solaris, but shouldn't hurt on other operating systems 00033 // and to avoid ifdef mess, rather include them for all 00034 #include <unistd.h> 00035 #ifdef HAVE_STROPTS_H 00036 #include <stropts.h> 00037 #endif 00038 00039 #include <sys/types.h> 00040 #include <sys/socket.h> 00041 #include <sys/ioctl.h> 00042 00043 namespace { 00044 00045 /* 00046 * These function here are just wrappers for the real system calls. 00047 * 00048 * Unfortunately, a number of systems out there work by redefining 00049 * symbols through the preprocessor -- symbols that we need. 00050 * 00051 * So we write wrappers for all the low-level system calls. 00052 * 00053 * Qt has a very similar implementation. I got the idea from them, but 00054 * I copied no code. 00055 */ 00056 00057 // socket 00058 inline int kde_socket(int af, int style, int protocol) 00059 { 00060 return ::socket(af, style, protocol); 00061 } 00062 00063 // bind 00064 inline int kde_bind(int fd, const struct sockaddr* sa, socklen_t len) 00065 { 00066 return ::bind(fd, sa, len); 00067 } 00068 00069 // listen 00070 inline int kde_listen(int fd, int backlog) 00071 { 00072 return ::listen(fd, backlog); 00073 } 00074 00075 // connect 00076 inline int kde_connect(int fd, const struct sockaddr* sa, socklen_t len) 00077 { 00078 return ::connect(fd, (struct sockaddr*)sa, len); 00079 } 00080 00081 // accept 00082 inline int kde_accept(int fd, struct sockaddr* sa, socklen_t* len) 00083 { 00084 return ::accept(fd, sa, len); 00085 } 00086 00087 // getpeername 00088 inline int kde_getpeername(int fd, struct sockaddr* sa, socklen_t* len) 00089 { 00090 return ::getpeername(fd, sa, len); 00091 } 00092 00093 // getsockname 00094 inline int kde_getsockname(int fd, struct sockaddr* sa, socklen_t* len) 00095 { 00096 return ::getsockname(fd, sa, len); 00097 } 00098 00099 // ioctl 00100 inline int kde_ioctl(int fd, int cmd, int* argp) 00101 { 00102 #if defined _WIN32 || defined _WIN64 00103 unsigned long l_argp = *argp; 00104 int iRet = ::ioctlsocket(fd, cmd, &l_argp); 00105 *argp = (int) l_argp; 00106 return iRet; 00107 #else 00108 return ::ioctl(fd, cmd, argp); 00109 #endif 00110 } 00111 00112 } // anonymous namespace 00113 00114 #endif
KDE 4.6 API Reference