SEDNL  .
Simple Event Driven Network Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SocketInterface.ipp
1 // SEDNL - Copyright (c) 2013 Jeremy S. Cochoy
2 //
3 // This software is provided 'as-is', without any express or implied warranty.
4 // In no event will the authors be held liable for any damages arising from
5 // the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 //
11 // 1. The origin of this software must not be misrepresented; you must not
12 // claim that you wrote the original software. If you use this software
13 // in a product, an acknowledgment in the product documentation would
14 // be appreciated but is not required.
15 //
16 // 2. Altered source versions must be plainly marked as such, and must not
17 // be misrepresented as being the original software.
18 //
19 // 3. This notice may not be removed or altered from any source
20 // distribution.
21 
22 #ifndef SOCKET_INTERFACE_IPP_
23 #define SOCKET_INTERFACE_IPP_
24 
25 #include "Export.hpp"
26 
27 #include <iostream>
28 
29 namespace SedNL
30 {
31 
33  :m_connected(false), m_fd(-1)
34 {}
35 
36 bool SocketInterface::is_connected() const noexcept
37 {
38  return m_connected;
39 }
40 
41 SocketInterface::operator bool() const noexcept
42 {
43  return is_connected();
44 }
45 
46 inline
47 FileDescriptor SocketInterface::get_fd() noexcept
48 {
49  try
50  {
51  std::lock_guard<std::mutex> lock(m_mutex);
52  return m_fd;
53  }
54  catch(std::exception &e)
55  {
56 #ifndef SEDNL_NOWARN
57  std::cerr << "Error: "
58  << "std::mutex::lock failed in Connection::get_fd" << std::endl;
59  std::cerr << " " << e.what() << std::endl;
60 #endif /* !SEDNL_NOWARN */
61  return m_fd;
62  }
63 }
64 
65 } // namespace Sednl
66 
67 #endif /* !SOCKET_INTERFACE_IPP_ */