summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Network.h
blob: 60362a24ef01499e5a209d06f9e4ee52df833f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// **********************************************************************
//
// Copyright (c) 2003
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************

#ifndef ICE_NETWORK_H
#define ICE_NETWORK_H

#ifdef __hpux
#   define _XOPEN_SOURCE_EXTENDED
#endif

#include <Ice/Config.h>

#ifdef _WIN32
#   include <winsock.h>
typedef int ssize_t;
#else
#   include <unistd.h>
#   include <fcntl.h>
#   include <sys/socket.h>

#   if defined(__hpux)
#      include <sys/time.h>
#   else   
#      include <sys/select.h>
#   endif

#   include <netinet/in.h>
#   include <netinet/tcp.h>
#   include <arpa/inet.h>
#   include <netdb.h>
#endif

#ifdef _WIN32
typedef int socklen_t;
#endif

#ifndef _WIN32
#   define SOCKET int
#   define SOCKET_ERROR -1
#   define INVALID_SOCKET -1
#endif

#ifndef SHUT_RD
#   define SHUT_RD 0
#endif

#ifndef SHUT_WR
#   define SHUT_WR 1
#endif

#ifndef SHUT_RDWR
#   define SHUT_RDWR 2
#endif

#ifndef NETDB_INTERNAL
#   define NETDB_INTERNAL -1
#endif

#ifndef NETDB_SUCCESS
#   define NETDB_SUCCESS 0
#endif

namespace IceInternal
{

ICE_PROTOCOL_API bool interrupted();
ICE_PROTOCOL_API bool acceptInterrupted();
ICE_PROTOCOL_API bool noBuffers();
ICE_PROTOCOL_API bool wouldBlock();
ICE_PROTOCOL_API bool connectFailed();
ICE_PROTOCOL_API bool connectionRefused();
ICE_PROTOCOL_API bool connectInProgress();
ICE_PROTOCOL_API bool connectionLost();
ICE_PROTOCOL_API bool notConnected();
ICE_PROTOCOL_API bool recvTruncated();

ICE_PROTOCOL_API SOCKET createSocket(bool);
ICE_PROTOCOL_API void closeSocket(SOCKET);
ICE_PROTOCOL_API void shutdownSocket(SOCKET);

ICE_PROTOCOL_API void setBlock(SOCKET, bool);
ICE_PROTOCOL_API void setTcpNoDelay(SOCKET);
ICE_PROTOCOL_API void setKeepAlive(SOCKET);
ICE_PROTOCOL_API void setSendBufferSize(SOCKET, int);
ICE_PROTOCOL_API int getSendBufferSize(SOCKET);
ICE_PROTOCOL_API void setRecvBufferSize(SOCKET, int);
ICE_PROTOCOL_API int getRecvBufferSize(SOCKET);

ICE_PROTOCOL_API void doBind(SOCKET, struct sockaddr_in&);
ICE_PROTOCOL_API void doListen(SOCKET, int);
ICE_PROTOCOL_API void doConnect(SOCKET, struct sockaddr_in&, int);
ICE_PROTOCOL_API SOCKET doAccept(SOCKET, int);

ICE_PROTOCOL_API void getAddress(const std::string&, int, struct sockaddr_in&);
ICE_PROTOCOL_API std::string getLocalHost(bool);
ICE_PROTOCOL_API bool compareAddress(const struct sockaddr_in&, const struct sockaddr_in&);

ICE_PROTOCOL_API void createPipe(SOCKET fds[2]);

ICE_PROTOCOL_API std::string errorToString(int);
ICE_PROTOCOL_API std::string errorToStringDNS(int);
ICE_PROTOCOL_API std::string lastErrorToString();

ICE_PROTOCOL_API std::string fdToString(SOCKET);
ICE_PROTOCOL_API std::string addrToString(const struct sockaddr_in&);

}

#endif