summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/named_pipe_windows.cpp
diff options
context:
space:
mode:
authorYoonsoo Kim <yoonsoo.kim@mongodb.com>2022-12-28 18:17:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-28 19:03:37 +0000
commit8d81f75155a9f82e4f9de742ac1ab548a162ba70 (patch)
tree1484d9454ddec6229e512f0afdc67af8b2451eab /src/mongo/db/storage/named_pipe_windows.cpp
parent07b5f334c547b5ab254e2952ae7b653fa9a8bcb4 (diff)
downloadmongo-8d81f75155a9f82e4f9de742ac1ab548a162ba70.tar.gz
SERVER-72393 Add more test cases for external data source
Diffstat (limited to 'src/mongo/db/storage/named_pipe_windows.cpp')
-rw-r--r--src/mongo/db/storage/named_pipe_windows.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/mongo/db/storage/named_pipe_windows.cpp b/src/mongo/db/storage/named_pipe_windows.cpp
index 045090d5697..3c9a0b4ec4d 100644
--- a/src/mongo/db/storage/named_pipe_windows.cpp
+++ b/src/mongo/db/storage/named_pipe_windows.cpp
@@ -39,12 +39,11 @@
#include "mongo/stdx/thread.h"
#include "mongo/util/errno_util.h"
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage
-
-
namespace mongo {
using namespace fmt::literals;
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
// On Windows, 'externalPipeDir' parameter is not supported and so the first argument is ignored and
// instead, 'kDefultPipePath' is used.
NamedPipeOutput::NamedPipeOutput(const std::string&, const std::string& pipeRelativePath)
@@ -72,12 +71,16 @@ void NamedPipeOutput::open() {
if (_isOpen) {
return;
}
- auto res = ConnectNamedPipe(_pipe, nullptr);
- if (!res) {
- LOGV2_ERROR(7005007,
- "Failed to connect a named pipe",
- "error"_attr = getErrorMessage("ConnectNamedPipe", _pipeAbsolutePath));
- return;
+ bool succeeded = ConnectNamedPipe(_pipe, nullptr);
+ if (!succeeded) {
+ // ERROR_PIPE_CONNECTED means that the client has arrived faster and the connection has been
+ // established. It does not count as an error.
+ if (auto ec = lastSystemError().value(); ec != ERROR_PIPE_CONNECTED) {
+ LOGV2_ERROR(7005007,
+ "Failed to connect a named pipe",
+ "error"_attr = getErrorMessage("ConnectNamedPipe", _pipeAbsolutePath));
+ return;
+ }
}
_isOpen = true;
}
@@ -86,16 +89,16 @@ int NamedPipeOutput::write(const char* data, int size) {
uassert(7005012, "Output must have been opened before writing", _isOpen);
DWORD nWritten = 0;
// Write the reply to the pipe.
- auto res = WriteFile(_pipe, // handle to pipe
- data, // buffer to write from
- size, // number of bytes to write
- &nWritten, // number of bytes written
- nullptr); // not overlapped I/O
-
- if (!res || size != nWritten) {
- LOGV2_ERROR(7005008,
- "Failed to write to a named pipe",
- "error"_attr = getErrorMessage("write", _pipeAbsolutePath));
+ bool succeeded = WriteFile(_pipe, // handle to pipe
+ data, // buffer to write from
+ size, // number of bytes to write
+ &nWritten, // number of bytes written
+ nullptr); // not overlapped I/O
+
+ if (!succeeded || size != nWritten) {
+ uasserted(7239301,
+ "Failed to write to a named pipe, error: {}"_format(
+ getErrorMessage("write", _pipeAbsolutePath)));
return -1;
}
@@ -114,6 +117,9 @@ void NamedPipeOutput::close() {
}
}
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage
+
NamedPipeInput::NamedPipeInput(const std::string& pipeRelativePath)
: _pipeAbsolutePath(kDefaultPipePath + pipeRelativePath),
_pipe(INVALID_HANDLE_VALUE),