First Commit of my working state
[simh.git] / sim_sock.h
1 /* sim_sock.h: OS-dependent socket routines header file
2
3 Copyright (c) 2001-2009, Robert M Supnik
4
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of Robert M Supnik shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Robert M Supnik.
25
26 04-Jun-08 RMS Addes sim_create_sock, for IBM 1130
27 14-Apr-05 RMS Added WSAEINPROGRESS (from Tim Riker)
28 20-Aug-04 HV Added missing definition for OS/2 (from Holger Veit)
29 22-Oct-03 MP Changed WIN32 winsock include to use winsock2.h to
30 avoid a conflict if sim_sock.h and sim_ether.h get
31 included by the same module.
32 20-Mar-03 RMS Added missing timerclear definition for VMS (from
33 Robert Alan Byer)
34 15-Feb-03 RMS Added time.h for EMX (from Holger Veit)
35 17-Dec-02 RMS Added sim_connect_sock
36 08-Oct-02 RMS Revised for .NET compatibility
37 20-Aug-02 RMS Changed calling sequence for sim_accept_conn
38 30-Apr-02 RMS Changed VMS stropts include to ioctl
39 06-Feb-02 RMS Added VMS support from Robert Alan Byer
40 16-Sep-01 RMS Added Macintosh support from Peter Schorn
41 */
42
43 #ifndef _SIM_SOCK_H_
44 #define _SIM_SOCK_H_ 0
45
46 #if defined (_WIN32) /* Windows */
47 #undef INT_PTR /* hack, hack */
48 #include <winsock2.h>
49
50 #elif !defined (__OS2__) || defined (__EMX__) /* VMS, Mac, Unix, OS/2 EMX */
51 #define WSAGetLastError() errno /* Windows macros */
52 #define SOCKET int32
53 #define WSAEWOULDBLOCK EWOULDBLOCK
54 #define WSAEINPROGRESS EINPROGRESS
55 #define INVALID_SOCKET -1
56 #define SOCKET_ERROR -1
57 #include <sys/types.h> /* for fcntl, getpid */
58 #include <sys/socket.h> /* for sockets */
59 #include <fcntl.h>
60 #include <unistd.h>
61 #include <netinet/in.h> /* for sockaddr_in */
62 #include <netdb.h>
63 #include <sys/time.h> /* for EMX */
64 #endif
65
66 #if defined (VMS) /* VMS unique */
67 #include <ioctl.h> /* for ioctl */
68 #if !defined (timerclear)
69 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
70 #endif
71 #endif
72 #if defined(__EMX__) /* OS/2 unique */
73 #if !defined (timerclear)
74 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
75 #endif
76 #endif
77
78 SOCKET sim_master_sock (int32 port);
79 SOCKET sim_connect_sock (int32 ip, int32 port);
80 SOCKET sim_create_sock (void);
81 SOCKET sim_accept_conn (SOCKET master, uint32 *ipaddr);
82 int32 sim_check_conn (SOCKET sock, t_bool rd);
83 int32 sim_read_sock (SOCKET sock, char *buf, int32 nbytes);
84 int32 sim_write_sock (SOCKET sock, char *msg, int32 nbytes);
85 void sim_close_sock (SOCKET sock, t_bool master);
86 SOCKET sim_setnonblock (SOCKET sock);
87
88 #endif