source: trunk/src/emx/src/libsocket/socket.h@ 1154

Last change on this file since 1154 was 1154, checked in by bird, 22 years ago

libsocket_tcpipv4_ioclt -> libsocket_os2_ioctl.

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: socket.h 1154 2004-02-03 19:56:37Z bird $ */
2/** @file
3 *
4 * Interal libsocket stuff.
5 *
6 * Copyright (c) 2003 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of Innotek LIBC.
10 *
11 * Innotek LIBC is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Innotek LIBC is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Innotek LIBC; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef __socket_h__
28#define __socket_h__
29
30
31/** @group libsocket libsocket
32 * @{
33 */
34
35/*******************************************************************************
36* Defined Constants And Macros *
37*******************************************************************************/
38/** The offset the OS/2 TCP/IP errno values are skewed compared to the
39 * LIBC errno values. */
40#define EOS2_TCPIP_OFFSET 10000
41
42/** Get the low word of the ioctl request number.
43 * Used to support ioctl request numbers from old and new _IOC macros.
44 */
45#define __IOCLW(a) ((unsigned short)(a))
46
47#ifndef TCPV40HDRS
48
49#define V5_FD_SETSIZE 64
50#define V5_FD_SET(fd, set) do { \
51 /* if (((v5_fd_set *)(set))->fd_count < V5_FD_SETSIZE) - calcsize fixes this */ \
52 ((v5_fd_set *)(set))->fd_array[((v5_fd_set *)(set))->fd_count++]=fd;\
53} while(0)
54#define V5_FD_ISSET(fd, set) v5_isset(fd, set)
55
56#endif
57
58
59/*******************************************************************************
60* Structures and Typedefs *
61*******************************************************************************/
62/** Socket handle.*/
63typedef struct __libc_SocketHandle
64{
65 /** the common fh core. */
66 LIBCFH core;
67
68 /** OS/2 socket number. */
69 int iSocket;
70} LIBCSOCKETFH, *PLIBCSOCKETFH;
71
72
73#ifndef TCPV40HDRS
74
75#pragma pack(4)
76/** OS/2 oddities from the BSD 4.4 stack. */
77typedef struct v5_fd_set {
78 u_short fd_count; /* how many are SET? */
79 int fd_array[V5_FD_SETSIZE];/* an array of SOCKETs */
80} v5_fd_set;
81#pragma pack()
82
83/** internal helper */
84static inline int v5_isset(int fd, const struct v5_fd_set *set)
85{
86 const int *pfd = &set->fd_array[0];
87 int c = set->fd_count;
88 while (c > 0)
89 {
90 if (*pfd == fd)
91 return 1;
92 pfd++;
93 c--;
94 }
95 return 0;
96}
97
98#endif
99
100
101/*******************************************************************************
102* Global Variables *
103*******************************************************************************/
104extern LIBCFHOPS __libsocket_gSocketOps;
105
106
107/*******************************************************************************
108* Internal Functions *
109*******************************************************************************/
110/** @defgroup libsocket_renamed Renamed Imports.
111 * @{ */
112int TCPCALL __libsocket_accept(int, struct sockaddr *, int *);
113int TCPCALL __libsocket_bind(int, __const__ struct sockaddr *, int);
114int TCPCALL __libsocket_connect(int, __const__ struct sockaddr *, int);
115int TCPCALL __libsocket_getpeername(int, struct sockaddr *, int *);
116int TCPCALL __libsocket_getsockname(int, struct sockaddr *, int *);
117int TCPCALL __libsocket_getsockopt(int, int, int, void *, int *);
118int TCPCALL __libsocket_ioctl(int, int, char *);
119int TCPCALL __libsocket_listen(int, int);
120int TCPCALL __libsocket_os2_ioctl(int, unsigned long, char *, int);
121int TCPCALL __libsocket_os2_select(int *, int, int, int, long);
122int TCPCALL __libsocket_recv(int, void *, int, int);
123int TCPCALL __libsocket_recv(int, void *, int, int);
124int TCPCALL __libsocket_recvfrom(int, void *, int, int, struct sockaddr *, int *);
125int TCPCALL __libsocket_recvmsg(int, struct msghdr *, int);
126int TCPCALL __libsocket_send(int, __const__ void *, int, int);
127int TCPCALL __libsocket_send(int, const void *, int, int);
128int TCPCALL __libsocket_sendmsg(int, __const__ struct msghdr *, int);
129int TCPCALL __libsocket_sendto(int, __const__ void *, int, int, __const__ struct sockaddr *, int);
130int TCPCALL __libsocket_setsockopt(int, int, int, __const__ void *, int);
131int TCPCALL __libsocket_shutdown(int, int);
132int TCPCALL __libsocket_sock_errno(void);
133int TCPCALL __libsocket_socket(int, int, int);
134int TCPCALL __libsocket_socket(int, int, int);
135int TCPCALL __libsocket_socketpair(int, int, int, int *);
136int TCPCALL __libsocket_soclose(int);
137int TCPCALL __libsocket_accept_and_recv(long, long*, struct sockaddr *, long*, struct sockaddr*, long*, caddr_t, size_t);
138void TCPCALL __libsocket_addsockettolist(int);
139int TCPCALL __libsocket_removesocketfromlist(int);
140ssize_t TCPCALL __libsocket_so_readv(int, struct iovec *, int);
141ssize_t TCPCALL __libsocket_so_writev(int, struct iovec *, int);
142int TCPCALL __libsocket_so_cancel(int);
143int TCPCALL __libsocket_soabort(int);
144int TCPCALL __libsocket_Raccept(int, struct sockaddr *, int *);
145struct sockaddr_in;
146int TCPCALL __libsocket_tcpip4_Rbind(int, struct sockaddr_in *, int, struct sockaddr_in *);
147int TCPCALL __libsocket_Rbind(int, struct sockaddr *, int, struct sockaddr *);
148int TCPCALL __libsocket_Rconnect(int, const struct sockaddr *, int);
149int TCPCALL __libsocket_Rgetsockname(int, struct sockaddr *, int *);
150int TCPCALL __libsocket_Rlisten(int, int);
151#ifndef TCPV40HDRS
152ssize_t TCPCALL __libsocket_send_file(int *, struct sf_parms *, int );
153#endif
154char * TCPCALL __libsocket_sock_strerror(int);
155int TCPCALL __libsocket_pair(int af, int type, int flags, int *osfd);
156#ifdef TCPV40HDRS
157int TCPCALL __libsocket_bsdselect(int, fd_set *, fd_set *, fd_set *, struct timeval *);
158#else
159int TCPCALL __libsocket_bsdselect(int, v5_fd_set *, v5_fd_set *, v5_fd_set *, struct timeval *);
160#endif
161void TCPCALL __libsocket_set_errno(int);
162/** @} */
163
164
165/** @defgroup libsocket_internal Internal helpers.
166 * @{ */
167/**
168 * Sets the LIBC and socket errno variables to a given error number.
169 */
170static inline void __libsocket_setErrno(int err)
171{
172 errno = err;
173 __libsocket_set_errno(err + EOS2_TCPIP_OFFSET);
174}
175
176/**
177 * Updates the LIBC errno with the latest socket error.
178 */
179static inline void __libsocket_setLibcErrno(void)
180{
181 int err = __libsocket_sock_errno();
182 if (err >= EOS2_TCPIP_OFFSET && err < EOS2_TCPIP_OFFSET + 1000)
183 errno = err - EOS2_TCPIP_OFFSET;
184}
185
186/**
187 * Updates the socket errno with the latest LIBC error.
188 */
189static inline void __libsocket_setSocketErrno(void)
190{
191 __libsocket_set_errno(errno + EOS2_TCPIP_OFFSET);
192}
193
194/**
195 * Gets the socket errno translating it to a LIBC errno.
196 */
197static inline int __libsocket_getSocketErrno(void)
198{
199 int err = __libsocket_sock_errno();
200 if (err >= EOS2_TCPIP_OFFSET && err < EOS2_TCPIP_OFFSET + 1000)
201 return err - EOS2_TCPIP_OFFSET;
202 return EDOOFUS;
203}
204
205
206/**
207 * Retrieve the socket handle structure for a given handle.
208 * @returns Pointer to socket handle structure on success.
209 * @returns NULL on failure with errno set to the appropriate value.
210 * @param socket Socket handle number.
211 */
212static inline PLIBCSOCKETFH __libsocket_FH(int socket)
213{
214 PLIBCSOCKETFH pFHSocket = (PLIBCSOCKETFH)__libc_FH(socket);
215 if (pFHSocket)
216 {
217 if ((pFHSocket->core.fFlags & F_TYPEMASK) == F_SOCKET)
218 return pFHSocket;
219 __libsocket_setErrno(ENOSYS);
220 }
221 else
222 __libsocket_setErrno(EBADF);
223 return NULL;
224}
225
226/** @} */
227
228
229/** @} */
230
231#endif
Note: See TracBrowser for help on using the repository browser.