PdCom  5.0
Process data communication client
PosixProcess.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  *
4  * Copyright (C) 2021 Bjarne von Horn (vh at igh dot de).
5  *
6  * This file is part of the PdCom library.
7  *
8  * The PdCom library is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * The PdCom library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
20  *
21  *****************************************************************************/
22 
25 #ifndef PDCOM5_POSIXPROCESS_H
26 #define PDCOM5_POSIXPROCESS_H
27 
28 #include "Exception.h"
29 #include "visibility.h"
30 
31 #include <algorithm>
32 #include <string>
33 
34 namespace PdCom {
35 
36 
44 class PDCOM5_PUBLIC PosixProcess
45 {
46  public:
47  struct PDCOM5_PUBLIC ConnectionFailed : Exception
48  {
49  ConnectionFailed() : Exception("Connection failed") {}
50  };
51  struct PDCOM5_PUBLIC ReadFailure : Exception
52  {
53  int errno_;
54  ReadFailure(int e) :
55  Exception("Read failure, errno: " + std::to_string(e)), errno_(e)
56  {}
57  };
58  struct PDCOM5_PUBLIC WriteFailure : Exception
59  {
60  int errno_;
61  WriteFailure(int e) :
62  Exception("Write failure, errno: " + std::to_string(e)), errno_(e)
63  {}
64  };
65 
72  PosixProcess(const char *host, unsigned short port);
73 
74 
75  virtual ~PosixProcess();
76 
77  PosixProcess(PosixProcess &&o) noexcept : fd_(-1) { std::swap(o.fd_, fd_); }
78 
79  PosixProcess &operator=(PosixProcess &&o) noexcept
80  {
81  PosixProcess tmp(std::move(o));
82  std::swap(tmp.fd_, fd_);
83  return *this;
84  }
85 
86  protected:
87  int fd_;
88 
97  void posixWrite(const char *buf, size_t count);
105  size_t posixRead(char *buf, size_t count);
106 };
107 
108 } // namespace PdCom
109 
110 #endif // PDCOM5_POSIXPROCESS_H
Definition: Exception.h:33
Definition: PosixProcess.h:47
Wrapper around POSIX socket.
Definition: PosixProcess.h:44
Definition: PosixProcess.h:51
library version string as "major.minor.patch"
Definition: details.h:37
Definition: PosixProcess.h:58