Benny Prijono | 4766ffe | 2005-11-01 17:56:59 +0000 | [diff] [blame] | 1 | /* $Id$ |
| 2 | * |
| 3 | */ |
Benny Prijono | dd859a6 | 2005-11-01 16:42:51 +0000 | [diff] [blame] | 4 | /* $Log: /pjproject-0.3/pjlib/include/pj/compat/socket.h $ |
| 5 | * |
| 6 | * 5 10/29/05 11:51a Bennylp |
| 7 | * Version 0.3-pre2. |
| 8 | * |
| 9 | * 4 10/14/05 12:26a Bennylp |
| 10 | * Finished error code framework, some fixes in ioqueue, etc. Pretty |
| 11 | * major. |
| 12 | * |
| 13 | * 3 9/21/05 1:39p Bennylp |
| 14 | * Periodic checkin for backup. |
| 15 | * |
| 16 | * 2 9/17/05 10:37a Bennylp |
| 17 | * Major reorganization towards version 0.3. |
| 18 | * |
| 19 | */ |
| 20 | #ifndef __PJ_COMPAT_SOCKET_H__ |
| 21 | #define __PJ_COMPAT_SOCKET_H__ |
| 22 | |
| 23 | /** |
| 24 | * @file socket.h |
| 25 | * @brief Provides all socket related functions,data types, error codes, etc. |
| 26 | */ |
| 27 | |
| 28 | #if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0 |
| 29 | # include <winsock.h> |
| 30 | #endif |
| 31 | |
| 32 | #if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0 |
| 33 | # include <winsock2.h> |
| 34 | #endif |
| 35 | |
| 36 | #if defined(PJ_HAS_SYS_TYPES_H) && PJ_HAS_SYS_TYPES_H != 0 |
| 37 | # include <sys/types.h> |
| 38 | #endif |
| 39 | |
| 40 | #if defined(PJ_HAS_SYS_SOCKET_H) && PJ_HAS_SYS_SOCKET_H != 0 |
| 41 | # include <sys/socket.h> |
| 42 | #endif |
| 43 | |
| 44 | #if defined(PJ_HAS_LINUX_SOCKET_H) && PJ_HAS_LINUX_SOCKET_H != 0 |
| 45 | # include <linux/socket.h> |
| 46 | #endif |
| 47 | |
| 48 | #if defined(PJ_HAS_SYS_SELECT_H) && PJ_HAS_SYS_SELECT_H != 0 |
| 49 | # include <sys/select.h> |
| 50 | #endif |
| 51 | |
| 52 | #if defined(PJ_HAS_NETINET_IN_H) && PJ_HAS_NETINET_IN_H != 0 |
| 53 | # include <netinet/in.h> |
| 54 | #endif |
| 55 | |
| 56 | #if defined(PJ_HAS_ARPA_INET_H) && PJ_HAS_ARPA_INET_H != 0 |
| 57 | # include <arpa/inet.h> |
| 58 | #endif |
| 59 | |
| 60 | #if defined(PJ_HAS_SYS_IOCTL_H) && PJ_HAS_SYS_IOCTL_H != 0 |
| 61 | # include <sys/ioctl.h> /* FBIONBIO */ |
| 62 | #endif |
| 63 | |
| 64 | #if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0 |
| 65 | # include <errno.h> |
| 66 | #endif |
| 67 | |
| 68 | #if defined(PJ_HAS_NETDB_H) && PJ_HAS_NETDB_H != 0 |
| 69 | # include <netdb.h> |
| 70 | #endif |
| 71 | |
| 72 | #if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0 |
| 73 | # include <unistd.h> |
| 74 | #endif |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | * Define common errors. |
| 79 | */ |
| 80 | #ifdef PJ_WIN32 |
| 81 | # define OSERR_EWOULDBLOCK WSAEWOULDBLOCK |
| 82 | # define OSERR_EINPROGRESS WSAEINPROGRESS |
| 83 | #else |
| 84 | # define OSERR_EWOULDBLOCK EWOULDBLOCK |
| 85 | # define OSERR_EINPROGRESS EINPROGRESS |
| 86 | #endif |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | * And undefine this.. |
| 91 | */ |
| 92 | #undef s_addr |
| 93 | |
| 94 | /* |
| 95 | * Linux kernel specifics |
| 96 | */ |
| 97 | #ifdef PJ_LINUX_KERNEL |
| 98 | # include <linux/net.h> |
| 99 | # include <asm/ioctls.h> /* FIONBIO */ |
| 100 | # include <linux/syscalls.h> /* sys_select() */ |
| 101 | # include <asm/uaccess.h> /* set/get_fs() */ |
| 102 | |
| 103 | typedef int socklen_t; |
| 104 | # define getsockopt sys_getsockopt |
| 105 | |
| 106 | /* |
| 107 | * Wrapper for select() in Linux kernel. |
| 108 | */ |
| 109 | PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp, |
| 110 | struct timeval *tvp) |
| 111 | { |
| 112 | int count; |
| 113 | mm_segment_t oldfs = get_fs(); |
| 114 | set_fs(KERNEL_DS); |
| 115 | count = sys_select(n, inp, outp, exp, tvp); |
| 116 | set_fs(oldfs); |
| 117 | return count; |
| 118 | } |
| 119 | #endif /* PJ_LINUX_KERNEL */ |
| 120 | |
| 121 | |
| 122 | /* |
| 123 | * Windows specific |
| 124 | */ |
| 125 | #ifdef PJ_WIN32 |
| 126 | typedef int socklen_t;; |
| 127 | #endif |
| 128 | |
| 129 | |
| 130 | #endif /* __PJ_COMPAT_SOCKET_H__ */ |
| 131 | |