libzypp 17.32.6
linuxhelpers_p.h
Go to the documentation of this file.
1#ifndef ZYPP_BASE_LINUXHELPERS_P_H_DEFINED
2#define ZYPP_BASE_LINUXHELPERS_P_H_DEFINED
3
4#include <string>
5#include <optional>
6#include <zypp-core/zyppng/core/ByteArray>
8#include <errno.h>
9
10namespace zyppng {
11
12 class SockAddr;
13
14 inline std::string strerr_cxx ( const int err = -1 ) {
15 ByteArray strBuf( 1024, '\0' );
16 strerror_r( err == -1 ? errno : err , strBuf.data(), strBuf.size() );
17 return std::string( strBuf.data() );
18 }
19
20
34 template<typename Fun, typename RestartCb, typename... Args >
35 auto eintrSafeCallEx ( const Fun &function, const RestartCb &restartCb, Args&&... args ) {
36 int res = 0;
37 int oerrno = errno;
38 while ( true ) {
39 errno = oerrno;
40 res = std::invoke(function, args... );
41 if ( res == -1 && errno == EINTR ) {
43 continue;
44 }
45 break;
46 };
47 return res;
48 }
49
50 template<typename Fun, typename... Args >
51 auto eintrSafeCall ( Fun &&function, Args&&... args ) {
52 return eintrSafeCallEx( std::forward<Fun>(function), [](){}, std::forward<Args>(args)... );
53 }
54
56
57 bool blockSignalsForCurrentThread ( const std::vector<int> &sigs );
58
59 bool trySocketConnection (int &sockFD, const SockAddr &addr, uint64_t timeout );
60
61 // origfd will be accessible as newfd and closed (unless they were equal)
62 void renumberFd (int origfd, int newfd);
63
68 int64_t bytesAvailableOnFD( int fd );
69
73 struct Pipe {
76 static std::optional<Pipe> create ( int flags = 0 );
77
78 void unrefWrite( ) {
79 writeFd = -1;
80 }
81
82 void unrefRead( ) {
83 readFd = -1;
84 }
85 };
86}
87
88#endif // LINUXHELPERS_P_H
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::typ invoke)(Functor &&f, Args &&... args)
Definition functional.h:32
bool blockAllSignalsForCurrentThread()
bool trySocketConnection(int &sockFD, const SockAddr &addr, uint64_t timeout)
auto eintrSafeCallEx(const Fun &function, const RestartCb &restartCb, Args &&... args)
bool blockSignalsForCurrentThread(const std::vector< int > &sigs)
auto eintrSafeCall(Fun &&function, Args &&... args)
int64_t bytesAvailableOnFD(int fd)
void renumberFd(int origfd, int newfd)
std::string strerr_cxx(const int err=-1)
AutoDispose<int> calling ::close
static std::optional< Pipe > create(int flags=0)
zypp::AutoFD writeFd
zypp::AutoFD readFd