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