1 // -*- C++ -*-
2 // Module:  Log4CPLUS
3 // File:    socket.h
4 // Created: 1/2010
5 // Author:  Vaclav Haisman
6 //
7 //
8 //  Copyright (C) 2010, Vaclav Haisman. All rights reserved.
9 //
10 //  Redistribution and use in source and binary forms, with or without modifica-
11 //  tion, are permitted provided that the following conditions are met:
12 //
13 //  1. Redistributions of  source code must  retain the above copyright  notice,
14 //     this list of conditions and the following disclaimer.
15 //
16 //  2. Redistributions in binary form must reproduce the above copyright notice,
17 //     this list of conditions and the following disclaimer in the documentation
18 //     and/or other materials provided with the distribution.
19 //
20 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
21 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
23 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
24 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
25 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
27 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
28 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
29 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 /** @file
32  * This header contains declaration internal to log4cplus. They must never be
33  * visible from user accesible headers or exported in DLL/shared libray.
34  */
35 
36 
37 #ifndef DCMTK_LOG4CPLUS_INTERNAL_SOCKET_H_
38 #define DCMTK_LOG4CPLUS_INTERNAL_SOCKET_H_
39 
40 #include "dcmtk/oflog/config.h"
41 
42 #if defined (DCMTK_LOG4CPLUS_HAVE_PRAGMA_ONCE)
43 #pragma once
44 #endif
45 
46 #if ! defined (DCMTK_INSIDE_LOG4CPLUS)
47 #  error "This header must not be be used outside log4cplus' implementation files."
48 #endif
49 
50 #if defined(_WIN32)
51 #include "dcmtk/oflog/config/windowsh.h"
52 #endif
53 #include "dcmtk/oflog/helpers/socket.h"
54 
55 #include <cerrno>
56 #ifdef DCMTK_LOG4CPLUS_HAVE_ERRNO_H
57 #include <errno.h>
58 #endif
59 
60 
61 namespace dcmtk {
62 namespace log4cplus {
63 
64 namespace helpers {
65 
66 
67 #if defined(_WIN32)
68 typedef SOCKET os_socket_type;
69 #else
70 typedef int os_socket_type;
71 #endif
72 
73 
74 os_socket_type const INVALID_OS_SOCKET_VALUE
75 #if defined(_WIN32)
76     = INVALID_SOCKET;
77 #else
78     = -1;
79 #endif
80 
81 
82 static inline
83 os_socket_type
to_os_socket(SOCKET_TYPE const & x)84 to_os_socket (SOCKET_TYPE const & x)
85 {
86     return OFstatic_cast(os_socket_type, x);
87 }
88 
89 
90 static inline
91 SOCKET_TYPE
to_log4cplus_socket(os_socket_type const & x)92 to_log4cplus_socket (os_socket_type const & x)
93 {
94     return OFstatic_cast(SOCKET_TYPE, x);
95 }
96 
97 
98 static inline
99 void
set_last_socket_error(int err)100 set_last_socket_error (int err)
101 {
102     errno = err;
103 }
104 
105 
106 static inline
107 int
get_last_socket_error()108 get_last_socket_error ()
109 {
110     return errno;
111 }
112 
113 
114 } // namespace helpers {
115 
116 } // namespace log4cplus {
117 } // end namespace dcmtk
118 
119 
120 #endif // DCMTK_LOG4CPLUS_INTERNAL_SOCKET_H_
121