Commit 89f3eed9 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Support NetworkSocket in FileUtil

Summary: As-per title, these functions need NetworkSocket support.

Reviewed By: yfeldblum

Differential Revision: D12813114

fbshipit-source-id: cc49aa9478d728ff3d1bd4fcb8957083066f7d8a
parent 350de5c9
......@@ -22,6 +22,7 @@
#include <vector>
#include <folly/detail/FileUtilDetail.h>
#include <folly/net/NetOps.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Stdlib.h>
......@@ -36,8 +37,7 @@ int openNoInt(const char* name, int flags, mode_t mode) {
return int(wrapNoInt(open, name, flags, mode));
}
int closeNoInt(int fd) {
int r = close(fd);
static int filterCloseReturn(int r) {
// Ignore EINTR. On Linux, close() may only return EINTR after the file
// descriptor has been closed, so you must not retry close() on EINTR --
// in the best case, you'll get EBADF, and in the worst case, you'll end up
......@@ -48,11 +48,19 @@ int closeNoInt(int fd) {
// case, the safe thing to do is also not to retry close() -- leaking a file
// descriptor is definitely better than closing the wrong file.
if (r == -1 && errno == EINTR) {
r = 0;
return 0;
}
return r;
}
int closeNoInt(int fd) {
return filterCloseReturn(close(fd));
}
int closeNoInt(NetworkSocket fd) {
return filterCloseReturn(netops::close(fd));
}
int fsyncNoInt(int fd) {
return int(wrapNoInt(fsync, fd));
}
......@@ -87,8 +95,8 @@ int flockNoInt(int fd, int operation) {
return int(wrapNoInt(flock, fd, operation));
}
int shutdownNoInt(int fd, int how) {
return int(wrapNoInt(portability::sockets::shutdown, fd, how));
int shutdownNoInt(NetworkSocket fd, int how) {
return int(wrapNoInt(netops::shutdown, fd, how));
}
ssize_t readNoInt(int fd, void* buf, size_t count) {
......
......@@ -25,6 +25,7 @@
#include <folly/Portability.h>
#include <folly/Range.h>
#include <folly/ScopeGuard.h>
#include <folly/net/NetworkSocket.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/SysUio.h>
#include <folly/portability/Unistd.h>
......@@ -38,7 +39,9 @@ namespace folly {
* semantics of underlying system calls.
*/
int openNoInt(const char* name, int flags, mode_t mode = 0666);
// Two overloads, as we may be closing either a file or a socket.
int closeNoInt(int fd);
int closeNoInt(NetworkSocket fd);
int dupNoInt(int fd);
int dup2NoInt(int oldfd, int newfd);
int fsyncNoInt(int fd);
......@@ -46,7 +49,10 @@ int fdatasyncNoInt(int fd);
int ftruncateNoInt(int fd, off_t len);
int truncateNoInt(const char* path, off_t len);
int flockNoInt(int fd, int operation);
int shutdownNoInt(int fd, int how);
int shutdownNoInt(NetworkSocket fd, int how);
inline int shutdownNoInt(int fd, int how) {
return shutdownNoInt(NetworkSocket::fromFd(fd), how);
}
ssize_t readNoInt(int fd, void* buf, size_t n);
ssize_t preadNoInt(int fd, void* buf, size_t n, off_t offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment