Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure HAVE_WINSOCK_H is defined even if only version 2 since it's the used sentin...
[simgrid.git] / src / portable.h
1 /* $Id$ */
2
3 /* portable -- header loading to write portable code                         */
4 /* loads much more stuff than sysdep.h since the latter is in public interface*/
5
6 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                   */
7
8 /* This program is free software; you can redistribute it and/or modify it
9   * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_PORTABLE_H
12 #define GRAS_PORTABLE_H
13
14 #include "gras_config.h"
15
16 #include <errno.h>
17 #include <sys/time.h> /* struct timeval */
18 #include <sys/types.h>
19
20 /****
21  **** Networking 
22  ****/
23
24
25 #ifdef HAVE_SYS_SOCKET_H
26 #  include <sys/socket.h>
27 #  include <netinet/in.h>   /* sometimes required for #include <arpa/inet.h> */
28 #  include <netinet/tcp.h>  /* TCP_NODELAY */
29 #  include <netdb.h>        /* getprotobyname() */
30 #  include <arpa/inet.h>    /* inet_ntoa() */
31 # endif
32
33 #ifdef HAVE_WINSOCK2_H
34 #  include <winsock2.h>
35 #  include <ws2tcpip.h>  /* socklen_t, but doubtful */
36 #  ifndef HAVE_WINSOCK_H
37 #    define HAVE_WINSOCK_H
38 #  endif
39 #elif HAVE_WINSOCK_H
40 #  include <winsock.h>
41 #endif
42
43 #ifdef HAVE_WINSOCK_H
44 #       define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
45 #       define tcp_write( s, buf, len ) send( s, buf, len, 0 )
46 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
47 #       define ioctl_t                          u_long
48 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
49
50 #       ifdef SD_BOTH
51 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
52 #       else
53 #               define tcp_close( s )           closesocket( s )
54 #       endif
55
56 #       define EWOULDBLOCK WSAEWOULDBLOCK
57 #       define EINPROGRESS WSAEINPROGRESS
58 #       define ETIMEDOUT   WSAETIMEDOUT
59
60 #       undef  sock_errno
61 #       undef  sock_errstr
62 #       define sock_errno      WSAGetLastError()
63 #       define sock_errstr     gras_wsa_err2string(WSAGetLastError())
64
65 const char *gras_wsa_err2string(int errcode);
66
67 #       define S_IRGRP 0
68 #       define S_IWGRP 0
69
70 #else
71 #       define tcp_read( s, buf, len)   read( s, buf, len )
72 #       define tcp_write( s, buf, len)  write( s, buf, len )
73 #       define sock_errno      errno
74 #       define sock_errstr     strerror(errno)
75
76 #       ifdef SHUT_RDWR
77 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
78 #       else
79 #               define tcp_close( s )   close( s )
80 #       endif
81 #endif /* windows or unix ? */
82
83 /****
84  **** File handling
85  ****/
86
87 #include <fcntl.h>
88
89 #ifdef HAVE_SYS_STAT_H
90 #include <sys/stat.h>
91 #endif
92
93 /****
94  **** Time handling
95  ****/
96
97 #if TIME_WITH_SYS_TIME
98 # include <sys/time.h>
99 # include <time.h>
100 #else
101 # if HAVE_SYS_TIME_H
102 #  include <sys/time.h>
103 # else
104 #  include <time.h>
105 # endif
106 #endif
107
108 #ifdef _WIN32
109 #define sleep _sleep /* else defined in stdlib.h */
110 #endif
111
112
113 #endif /* GRAS_PORTABLE_H */