mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-15 09:27:09 -05:00
Added RsFileUtil for os specific file functions
Added RsFileUtil::set_fd_nonblock to set a file descriptor to non blocking
This commit is contained in:
parent
5b8ac7e49b
commit
085e102ce1
@ -347,6 +347,7 @@ list(
|
||||
util/rsurl.cc
|
||||
util/folderiterator.cc
|
||||
util/rsdir.cc
|
||||
util/rsfile.cc
|
||||
util/dnsresolver.cc
|
||||
util/extaddrfinder.cc
|
||||
util/rsdebug.cc
|
||||
|
@ -487,6 +487,7 @@ HEADERS += util/folderiterator.h \
|
||||
util/rsmemory.h \
|
||||
util/smallobject.h \
|
||||
util/rsdir.h \
|
||||
util/rsfile.h \
|
||||
util/argstream.h \
|
||||
util/rsdiscspace.h \
|
||||
util/rsnet.h \
|
||||
@ -641,6 +642,7 @@ SOURCES += util/folderiterator.cc \
|
||||
util/rsexpr.cc \
|
||||
util/smallobject.cc \
|
||||
util/rsdir.cc \
|
||||
util/rsfile.cc \
|
||||
util/rsdiscspace.cc \
|
||||
util/rsnet.cc \
|
||||
util/rsnet_ss.cc \
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsfile.h"
|
||||
#include "pqi/pqifdbin.h"
|
||||
|
||||
#include "TorProcess.h"
|
||||
@ -270,8 +271,8 @@ void TorProcess::start()
|
||||
return; // stop the control thread
|
||||
}
|
||||
|
||||
unix_fcntl_nonblock(fd[STDOUT_FILENO]);
|
||||
unix_fcntl_nonblock(fd[STDERR_FILENO]);
|
||||
RsFileUtil::set_fd_nonblock(fd[STDOUT_FILENO]);
|
||||
RsFileUtil::set_fd_nonblock(fd[STDERR_FILENO]);
|
||||
|
||||
mStdOutFD = new RsFdBinInterface(fd[STDOUT_FILENO]);
|
||||
mStdErrFD = new RsFdBinInterface(fd[STDERR_FILENO]);
|
||||
|
51
libretroshare/src/util/rsfile.cc
Normal file
51
libretroshare/src/util/rsfile.cc
Normal file
@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/util: rsfile.cc *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2021 Retroshare Team <retroshare.project@gmail.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#include "util/rsfile.h"
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <wtypes.h>
|
||||
#include <io.h>
|
||||
#include <namedpipeapi.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
int RsFileUtil::set_fd_nonblock(int fd)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/******************* OS SPECIFIC PART ******************/
|
||||
#ifdef WINDOWS_SYS
|
||||
DWORD mode = PIPE_NOWAIT;
|
||||
WINBOOL result = SetNamedPipeHandleState((HANDLE) _get_osfhandle(fd), &mode, nullptr, nullptr);
|
||||
|
||||
if (!result) {
|
||||
ret = -1;
|
||||
}
|
||||
#else // ie UNIX
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
29
libretroshare/src/util/rsfile.h
Normal file
29
libretroshare/src/util/rsfile.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/util: rsfile.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2021 Retroshare Team <retroshare.project@gmail.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace RsFileUtil {
|
||||
|
||||
int set_fd_nonblock(int fd);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user