Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | a771a51 | 2007-02-19 01:13:53 +0000 | [diff] [blame] | 3 | * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #ifndef __PJ_COMPAT_SOCKET_H__ |
| 20 | #define __PJ_COMPAT_SOCKET_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file socket.h |
| 24 | * @brief Provides all socket related functions,data types, error codes, etc. |
| 25 | */ |
| 26 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 27 | #if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0 |
| 28 | # include <winsock2.h> |
| 29 | #endif |
| 30 | |
Benny Prijono | c5b6dbf | 2006-09-10 16:33:48 +0000 | [diff] [blame] | 31 | #if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0 |
| 32 | # include <winsock.h> |
| 33 | #endif |
| 34 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 35 | #if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0 |
| 36 | # include <sys/types.h> |
| 37 | #endif |
| 38 | |
| 39 | #if defined(PJ_HAS_SYS_SOCKET_H) && PJ_HAS_SYS_SOCKET_H != 0 |
| 40 | # include <sys/socket.h> |
| 41 | #endif |
| 42 | |
| 43 | #if defined(PJ_HAS_LINUX_SOCKET_H) && PJ_HAS_LINUX_SOCKET_H != 0 |
| 44 | # include <linux/socket.h> |
| 45 | #endif |
| 46 | |
| 47 | #if defined(PJ_HAS_SYS_SELECT_H) && PJ_HAS_SYS_SELECT_H != 0 |
| 48 | # include <sys/select.h> |
| 49 | #endif |
| 50 | |
| 51 | #if defined(PJ_HAS_NETINET_IN_H) && PJ_HAS_NETINET_IN_H != 0 |
| 52 | # include <netinet/in.h> |
| 53 | #endif |
| 54 | |
Benny Prijono | 87a0089 | 2007-02-01 00:33:12 +0000 | [diff] [blame] | 55 | #if defined(PJ_HAS_NETINET_IP_H) && PJ_HAS_NETINET_IP_H != 0 |
| 56 | /* To pull in IPTOS_* constants */ |
| 57 | # include <netinet/ip.h> |
| 58 | #endif |
| 59 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 60 | #if defined(PJ_HAS_ARPA_INET_H) && PJ_HAS_ARPA_INET_H != 0 |
| 61 | # include <arpa/inet.h> |
| 62 | #endif |
| 63 | |
| 64 | #if defined(PJ_HAS_SYS_IOCTL_H) && PJ_HAS_SYS_IOCTL_H != 0 |
| 65 | # include <sys/ioctl.h> /* FBIONBIO */ |
| 66 | #endif |
| 67 | |
| 68 | #if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0 |
| 69 | # include <errno.h> |
| 70 | #endif |
| 71 | |
| 72 | #if defined(PJ_HAS_NETDB_H) && PJ_HAS_NETDB_H != 0 |
| 73 | # include <netdb.h> |
| 74 | #endif |
| 75 | |
| 76 | #if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0 |
| 77 | # include <unistd.h> |
| 78 | #endif |
| 79 | |
| 80 | |
| 81 | /* |
| 82 | * Define common errors. |
| 83 | */ |
Benny Prijono | ace0093 | 2006-02-14 21:04:47 +0000 | [diff] [blame] | 84 | #if (defined(PJ_WIN32) && PJ_WIN32!=0) || \ |
| 85 | (defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0) |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 86 | # define OSERR_EWOULDBLOCK WSAEWOULDBLOCK |
| 87 | # define OSERR_EINPROGRESS WSAEINPROGRESS |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 88 | # define OSERR_ECONNRESET WSAECONNRESET |
Benny Prijono | 9f0a523 | 2006-06-26 10:03:09 +0000 | [diff] [blame] | 89 | # define OSERR_ENOTCONN WSAENOTCONN |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 90 | #else |
| 91 | # define OSERR_EWOULDBLOCK EWOULDBLOCK |
| 92 | # define OSERR_EINPROGRESS EINPROGRESS |
Benny Prijono | fa73e3e | 2006-01-05 23:35:46 +0000 | [diff] [blame] | 93 | # define OSERR_ECONNRESET ECONNRESET |
Benny Prijono | 9f0a523 | 2006-06-26 10:03:09 +0000 | [diff] [blame] | 94 | # define OSERR_ENOTCONN ENOTCONN |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 95 | #endif |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | * And undefine this.. |
| 100 | */ |
| 101 | #undef s_addr |
| 102 | |
| 103 | /* |
| 104 | * Linux kernel specifics |
| 105 | */ |
Benny Prijono | 9cf138e | 2006-01-19 03:58:29 +0000 | [diff] [blame] | 106 | #if defined(PJ_LINUX_KERNEL) |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 107 | # include <linux/net.h> |
| 108 | # include <asm/ioctls.h> /* FIONBIO */ |
| 109 | # include <linux/syscalls.h> /* sys_select() */ |
| 110 | # include <asm/uaccess.h> /* set/get_fs() */ |
| 111 | |
| 112 | typedef int socklen_t; |
| 113 | # define getsockopt sys_getsockopt |
| 114 | |
| 115 | /* |
| 116 | * Wrapper for select() in Linux kernel. |
| 117 | */ |
| 118 | PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp, |
| 119 | struct timeval *tvp) |
| 120 | { |
| 121 | int count; |
| 122 | mm_segment_t oldfs = get_fs(); |
| 123 | set_fs(KERNEL_DS); |
| 124 | count = sys_select(n, inp, outp, exp, tvp); |
| 125 | set_fs(oldfs); |
| 126 | return count; |
| 127 | } |
| 128 | #endif /* PJ_LINUX_KERNEL */ |
| 129 | |
| 130 | |
| 131 | /* |
Benny Prijono | c5b6dbf | 2006-09-10 16:33:48 +0000 | [diff] [blame] | 132 | * This will finally be obsoleted, since it should be declared in |
| 133 | * os_auto.h |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 134 | */ |
Benny Prijono | c5b6dbf | 2006-09-10 16:33:48 +0000 | [diff] [blame] | 135 | #if !defined(PJ_HAS_SOCKLEN_T) || PJ_HAS_SOCKLEN_T==0 |
Benny Prijono | 9cf138e | 2006-01-19 03:58:29 +0000 | [diff] [blame] | 136 | typedef int socklen_t; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | |
| 140 | #endif /* __PJ_COMPAT_SOCKET_H__ */ |
| 141 | |