Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fd-utils.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Contact: Jan Olszak <j.olszak@samsung.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
17 */
18 
25 #ifndef COMMON_UTILS_FD_HPP
26 #define COMMON_UTILS_FD_HPP
27 
28 #include <string>
29 #include <cstddef>
30 #include <sys/types.h>
31 
32 namespace utils {
33 
37 int open(const std::string &path, int flags, mode_t mode = -1);
38 
42 void close(int fd);
43 
47 void shutdown(int fd);
48 
52 int ioctl(int fd, unsigned long request, void *argp);
53 
57 int dup2(int olfFD, int newFD, bool closeOnExec = false);
58 
67 void write(int fd, const void* bufferPtr, const size_t size, int timeoutMS = 5000);
68 
77 void read(int fd, void* bufferPtr, const size_t size, int timeoutMS = 5000);
78 
82 unsigned int getMaxFDNumber();
83 
89 void setMaxFDNumber(unsigned int limit);
90 
94 unsigned int getFDNumber();
95 
99 bool fdSend(int socket, int fd, const unsigned int timeoutMS = 5000);
100 
104 int fdRecv(int socket, const unsigned int timeoutMS = 5000);
105 
109 void setCloseOnExec(int fd, bool closeOnExec);
110 
114 void setNonBlocking(int fd, bool nonBlocking);
115 
116 } // namespace utils
117 
118 #endif // COMMON_UTILS_FD_HPP
void setNonBlocking(int fd, bool nonBlocking)
Set or remove NONBLOCK on a file descriptor.
Definition: fd-utils.cpp:435
int open(const std::string &path, int flags, mode_t mode)
Open a file.
Definition: fd-utils.cpp:127
void close(int fd)
Close the file descriptor.
Definition: fd-utils.cpp:151
unsigned int getMaxFDNumber()
Definition: fd-utils.cpp:271
bool fdSend(int socket, int fd, const unsigned int timeoutMS)
Send Socket via Unix Domain socket.
Definition: fd-utils.cpp:368
void write(int fd, const void *bufferPtr, const size_t size, int timeoutMS)
Write to a file descriptor, throw on error.
Definition: fd-utils.cpp:208
int ioctl(int fd, unsigned long request, void *argp)
Operation on a special file.
Definition: fd-utils.cpp:182
int dup2(int oldFD, int newFD, bool closeOnExec)
Duplicate one file desciptor onto another.
Definition: fd-utils.cpp:193
void setCloseOnExec(int fd, bool closeOnExec)
Set or remove CLOEXEC on a file descriptor.
Definition: fd-utils.cpp:430
void shutdown(int fd)
Shut down part of a full-duplex connection.
Definition: fd-utils.cpp:169
int fdRecv(int socket, const unsigned int timeoutMS)
Receive fd via Unix Domain socket.
Definition: fd-utils.cpp:301
unsigned int getFDNumber()
Definition: fd-utils.cpp:294
void read(int fd, void *bufferPtr, const size_t size, int timeoutMS)
Read from a file descriptor, throw on error.
Definition: fd-utils.cpp:237
void setMaxFDNumber(unsigned int limit)
Set the software and hardware limit of file descriptors for this process.
Definition: fd-utils.cpp:282