libzypp 17.37.17
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 while ( true ) {
38 errno = 0;
39 res = std::invoke(function, args... );
40 if ( res == -1 && errno == EINTR ) {
41 std::invoke( restartCb );
42 continue;
43 }
44 break;
45 };
46 return res;
47 }
48
49 template<typename Fun, typename... Args >
50 auto eintrSafeCall ( Fun &&function, Args&&... args ) {
51 return eintrSafeCallEx( std::forward<Fun>(function), [](){}, std::forward<Args>(args)... );
52 }
53
55
56 bool blockSignalsForCurrentThread ( const std::vector<int> &sigs );
57
58 bool trySocketConnection (int &sockFD, const SockAddr &addr, uint64_t timeout );
59
60 // origfd will be accessible as newfd and closed (unless they were equal)
61 void renumberFd (int origfd, int newfd);
62
67 int64_t bytesAvailableOnFD( int fd );
68
72 struct Pipe {
75 static std::optional<Pipe> create ( int flags = 0 );
76
77 void unrefWrite( ) {
78 writeFd = -1;
79 }
80
81 void unrefRead( ) {
82 readFd = -1;
83 }
84 };
85}
86
87#endif // LINUXHELPERS_P_H
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type 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