-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the file handle errors
- Loading branch information
Showing
7 changed files
with
166 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "stdafx.h" | ||
#include "FilePipe.h" | ||
|
||
#include "SystemError.h" | ||
|
||
Linter::FilePipe::Pipe Linter::FilePipe::create() | ||
{ | ||
SECURITY_ATTRIBUTES security; | ||
|
||
security.nLength = sizeof(SECURITY_ATTRIBUTES); | ||
security.bInheritHandle = TRUE; | ||
security.lpSecurityDescriptor = nullptr; | ||
|
||
HANDLE parent; | ||
HANDLE child; | ||
if (!CreatePipe(&parent, &child, &security, 0)) | ||
{ | ||
throw SystemError(); | ||
} | ||
|
||
//Stop my handle being inherited by the child | ||
if (!SetHandleInformation(parent, HANDLE_FLAG_INHERIT, 0)) | ||
{ | ||
throw SystemError(); | ||
} | ||
|
||
return {HandleWrapper(parent), HandleWrapper(child)}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "HandleWrapper.h" | ||
|
||
namespace Linter | ||
{ | ||
class FilePipe | ||
{ | ||
public: | ||
struct Pipe | ||
{ | ||
HandleWrapper m_reader; | ||
HandleWrapper m_writer; | ||
}; | ||
|
||
static Pipe create(); | ||
}; | ||
} // namespace Linter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,33 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include <wtypes.h> | ||
|
||
namespace Linter | ||
{ | ||
class HandleWrapper | ||
{ | ||
public: | ||
explicit HandleWrapper(HANDLE h); | ||
|
||
HandleWrapper(HandleWrapper const &) = delete; | ||
|
||
HandleWrapper(HandleWrapper &&other) noexcept; | ||
|
||
HandleWrapper &operator=(HandleWrapper const &) = delete; | ||
|
||
HandleWrapper &operator=(HandleWrapper &&other) = delete; | ||
|
||
void close(); | ||
|
||
~HandleWrapper(); | ||
|
||
operator HANDLE() const noexcept | ||
{ | ||
return m_handle; | ||
} | ||
void close() const; | ||
|
||
operator HANDLE() const noexcept; | ||
|
||
/** Write a string to the handle | ||
* | ||
* @param str - string to write | ||
*/ | ||
void write_string(std::string const &str); | ||
* | ||
* @param str - string to write | ||
*/ | ||
void writeFile(std::string const &str) const; | ||
|
||
/** Read the entire file */ | ||
std::string read_file(); | ||
|
||
static std::pair<HandleWrapper, HandleWrapper> create_pipe(); | ||
std::string readFile() const; | ||
|
||
private: | ||
HANDLE m_handle; | ||
mutable HANDLE m_handle; | ||
}; | ||
|
||
} // namespace Linter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.