blob: 40c03455420812950f6d6481d9736b1b6c42fed5 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00004 *
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 Prijono5dcb38d2005-11-21 01:55:47 +000027#if defined(PJ_HAS_WINSOCK2_H) && PJ_HAS_WINSOCK2_H != 0
28# include <winsock2.h>
29#endif
30
Benny Prijonoc5b6dbf2006-09-10 16:33:48 +000031#if defined(PJ_HAS_WINSOCK_H) && PJ_HAS_WINSOCK_H != 0
32# include <winsock.h>
33#endif
34
Benny Prijono5dcb38d2005-11-21 01:55:47 +000035#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 Prijono87a00892007-02-01 00:33:12 +000055#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 Prijono5dcb38d2005-11-21 01:55:47 +000060#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 Prijonoace00932006-02-14 21:04:47 +000084#if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
85 (defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0)
Benny Prijono5dcb38d2005-11-21 01:55:47 +000086# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
87# define OSERR_EINPROGRESS WSAEINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000088# define OSERR_ECONNRESET WSAECONNRESET
Benny Prijono9f0a5232006-06-26 10:03:09 +000089# define OSERR_ENOTCONN WSAENOTCONN
Benny Prijonof260e462007-04-30 21:03:32 +000090#elif defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
91# define OSERR_EWOULDBLOCK -1
92# define OSERR_EINPROGRESS -1
93# define OSERR_ECONNRESET -1
94# define OSERR_ENOTCONN -1
Benny Prijono5dcb38d2005-11-21 01:55:47 +000095#else
96# define OSERR_EWOULDBLOCK EWOULDBLOCK
97# define OSERR_EINPROGRESS EINPROGRESS
Benny Prijonofa73e3e2006-01-05 23:35:46 +000098# define OSERR_ECONNRESET ECONNRESET
Benny Prijono9f0a5232006-06-26 10:03:09 +000099# define OSERR_ENOTCONN ENOTCONN
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000100#endif
101
102
103/*
104 * And undefine this..
105 */
106#undef s_addr
107
108/*
109 * Linux kernel specifics
110 */
Benny Prijono9cf138e2006-01-19 03:58:29 +0000111#if defined(PJ_LINUX_KERNEL)
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000112# include <linux/net.h>
113# include <asm/ioctls.h> /* FIONBIO */
114# include <linux/syscalls.h> /* sys_select() */
115# include <asm/uaccess.h> /* set/get_fs() */
116
117 typedef int socklen_t;
118# define getsockopt sys_getsockopt
119
120 /*
121 * Wrapper for select() in Linux kernel.
122 */
123 PJ_INLINE(int) select(int n, fd_set *inp, fd_set *outp, fd_set *exp,
124 struct timeval *tvp)
125 {
126 int count;
127 mm_segment_t oldfs = get_fs();
128 set_fs(KERNEL_DS);
129 count = sys_select(n, inp, outp, exp, tvp);
130 set_fs(oldfs);
131 return count;
132 }
133#endif /* PJ_LINUX_KERNEL */
134
135
136/*
Benny Prijonoc5b6dbf2006-09-10 16:33:48 +0000137 * This will finally be obsoleted, since it should be declared in
138 * os_auto.h
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000139 */
Benny Prijonoc5b6dbf2006-09-10 16:33:48 +0000140#if !defined(PJ_HAS_SOCKLEN_T) || PJ_HAS_SOCKLEN_T==0
Benny Prijono9cf138e2006-01-19 03:58:29 +0000141 typedef int socklen_t;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000142#endif
143
144
145#endif /* __PJ_COMPAT_SOCKET_H__ */
146