Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnet_err.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #ifndef VSNET_ERR_H
18 #define VSNET_ERR_H
19 
20 #include <assert.h>
21 #include <sstream>
22 #include <string>
23 
24 inline std::string vsnetLastError()
25 {
26  std::ostringstream ostr;
27 #if defined (_WIN32) && !defined (__CYGWIN__)
28  ostr<<WSAGetLastError()<<std::ends;
29 #else
30  ostr<<strerror( errno )<<std::ends;
31 #endif
32  return ostr.str();
33 }
34 
35 inline bool vsnetEWouldBlock()
36 {
37 #if defined (_WIN32) && !defined (__CYGWIN__)
38  int tmp = WSAGetLastError();
39  return tmp == WSAEWOULDBLOCK;
40 
41 #else
42  return errno == EWOULDBLOCK;
43 #endif
44 }
45 
46 inline bool vsnetEConnAborted()
47 {
48 #if defined (_WIN32) && !defined (__CYGWIN__)
49  int err = WSAGetLastError();
50  return (err == WSAECONNABORTED)
51  || ( err == WSAENETDOWN || (err == WSAENOTCONN) || (err == WSAECONNABORTED) || (err == WSAESHUTDOWN)
52  || (err == WSAETIMEDOUT) ) || (err == WSAECONNRESET);
53 
54 #else
55  return (errno == ECONNABORTED) || (errno == ENETDOWN) || (errno == ENOTCONN) || (errno == ESHUTDOWN)
56  || (errno == ECONNRESET) || (errno == ETIMEDOUT);
57 #endif
58 }
59 
60 inline bool vsnetEConnReset()
61 {
62 #if defined (_WIN32) && !defined (__CYGWIN__)
63  return WSAGetLastError() == WSAECONNRESET;
64 
65 #else
66  return errno == ECONNRESET;
67 #endif
68 }
69 
70 inline int vsnetGetLastError()
71 {
72 #if defined (_WIN32) && !defined (__CYGWIN__)
73  return WSAGetLastError();
74 
75 #else
76  return errno;
77 #endif
78 }
79 
80 #endif /* VSNET_ERR_H */
81