libDwmAuth-0.3.6
DwmAuthUtils.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwmAuth/tags/libDwmAuth-0.3.6/include/DwmAuthUtils.hh 10973 $
3 // @(#) $Id: DwmAuthUtils.hh 10973 2020-08-25 02:48:22Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2020
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
42 
43 #ifndef _DWMAUTHUTILS_HH_
44 #define _DWMAUTHUTILS_HH_
45 
46 #include <chrono>
47 #include <cstdint>
48 #include <iostream>
49 #include <string>
50 
51 #include <boost/asio.hpp>
52 
53 namespace Dwm {
54 
55  namespace Auth {
56 
57  //------------------------------------------------------------------------
59  //------------------------------------------------------------------------
60  class Utils
61  {
62  public:
63  using Clock = std::chrono::system_clock;
64  using TimePoint = std::chrono::time_point<Clock>;
65 
66  static int BytesReady(int fd);
67 
68  static std::size_t BytesReady(boost::asio::ip::tcp::socket & sck);
69 
70  static bool
71  WaitUntilBytesReady(int fd, uint32_t numBytes, TimePoint endTime);
72 
73  static bool WaitUntilBytesReady(boost::asio::ip::tcp::socket & sck,
74  uint32_t numBytes, TimePoint endTime);
75 
76  static bool WaitForBytesReady(int fd, uint32_t numBytes,
77  std::chrono::milliseconds timeout);
78 
79  static bool WaitForBytesReady(boost::asio::ip::tcp::socket & sck,
80  uint32_t numBytes,
81  std::chrono::milliseconds timeout);
82 
83  static ssize_t ReadLengthRestrictedString(int fd, std::string & s,
84  uint32_t maxLen);
85 
86  static ssize_t
87  ReadLengthRestrictedString(boost::asio::ip::tcp::socket & sck,
88  std::string & s, uint32_t maxLen);
89 
90  static std::istream & ReadLengthRestrictedString(std::istream & is,
91  std::string & s,
92  uint32_t maxLen);
93 
94  static ssize_t
95  ReadLengthRestrictedString(int fd, std::string & s, uint32_t maxLen,
96  std::chrono::milliseconds timeout);
97 
98  static ssize_t
99  ReadLengthRestrictedString(int fd, std::string & s,
100  uint32_t maxLen, TimePoint endTime);
101 
102  static ssize_t
103  ReadLengthRestrictedString(boost::asio::ip::tcp::socket & sck,
104  std::string & s, uint32_t maxLen,
105  TimePoint endTime);
106  };
107 
108  } // namespace Auth
109 
110 } // namespace Dwm
111 
112 #endif // _DWMAUTHUTILS_HH_
Collection of utility functions.
Definition: DwmAuthUtils.hh:60