- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 C++ 程序正在创建一个命名管道来写入数据。一些客户报告了客户端连接到命名管道但服务器端无法写入数据(ERROR_NO_DATA
)的情况。
在我能找到的任何 MSDN 页面中都没有真正解释这个错误代码;有没有人对如何解决这个问题有任何想法?或者是什么原因?
ostringstream pipeName;
pipeName << "\\\\.\\pipe\\unique-named-pipe-" << GetCurrentProcessId();
pipeHandle = CreateNamedPipeA(
pipeName.str().c_str(), // pipe name
PIPE_ACCESS_DUPLEX, // open mode
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, // pipe mode
PIPE_UNLIMITED_INSTANCES, // max instances
512, // output buffer size
512, // input buffer size
0, // use default timeouts
NULL); // security attributes
if (INVALID_HANDLE_VALUE == pipeHandle)
{
THROW("Failed to create named pipe", GetLastError());
}
cout << "Pipe ready" << endl;
// Wait for a client to connect to the pipe
BOOL status = ConnectNamedPipe(pipeHandle, NULL);
if (!status)
{
DWORD lastError = GetLastError();
if (ERROR_PIPE_CONNECTED != lastError)
{
THROW("Failed to wait for client to open pipe", lastError);
}
else
{
// Ignore, see MSDN docs for ConnectNamedPipe() for details.
}
}
// response is a std::string
int writeOffset = 0;
int length = response.length();
while ((int) response.length() > writeOffset)
{
DWORD bytesWritten;
BOOL status = WriteFile(
pipeHandle,
response.c_str() + writeOffset,
length - writeOffset,
&bytesWritten,
NULL);
if (!status)
{
// This sometimes fails with ERROR_NO_DATA, why??
THROW("Failed to send via named pipe", GetLastError());
}
writeOffset += bytesWritten;
}
#define THROW(message, errorCode) \
{ \
fprintf(stderr, "%s: line: %d file: %s error:0x%x\n", \
message, __LINE__, __FILE__, errorCode); \
fflush(stderr); \
throw message; \
} \
谢谢!
最佳答案
查看 WinError.h,这是定义此错误代码和其他错误代码的地方:
//
// MessageId: ERROR_NO_DATA
//
// MessageText:
//
// The pipe is being closed.
//
#define ERROR_NO_DATA 232L
听起来客户端已经关闭了他们的管道末端 - 也许客户端代码认为它已经得到了完整的字符串,关闭了他们的末端,而上面的代码继续尝试写入?
关于c++ - 命名管道上的 WriteFile 有时会返回 ERROR_NO_DATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25228378/
我正在尝试使用 C++ 代码将 AT 命令发送到通过 USB 连接的调制解调器。我正在使用“AT+MDN”进行测试,它在这个特定的调制解调器上返回其电话号码,并且在通过连接到其串行端口的 Putty
为了测试并确保我已经把所有东西都放下了,以便以后可以开始扩展,我正在尝试创建一个文件句柄,将给定的字节缓冲区写入该文件句柄,然后读取部分该文件放入新的测试缓冲区。 我有代码: const size_t
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在设计一个将时间序列数据写入文件的系统。数据是 8 字节的 block ,分为两个 4 字节的部分:时间和负载。 根据 MSDN,如果写入的数据大小小于一个扇区,则 WriteFile 函数是原子
我不知道如何在 JSON 文件上写入。我正在开发一个单一应用程序页面,主要使用 AngularJS 和 Node.js 这是我的代码: --index.html-- ... --a
作为学习练习,我正在编写一个在运行时输出 DLL 的程序。 我已经编写了 PE header ,并使用 WriteFile 成功将 DOS header 、NT header 、可选节 header
我正在尝试将参数发送到我的arduino。所以我编写了这段代码: #include #include #include #include HANDLE serialPortHandler;
代码: #include #include #include #include HANDLE creatFile(void); long WriteBuffer(HANDLE); char *
一般来说,我是 node.js 和 javascript 的新手,但我无法理解为什么 writeFile 函数正在写入一个空白文件。我认为 for 循环应该是一个 Promise,但我不确定如何编写它
我正在尝试使用 WriteFile 函数将 wstring 写入 UTF-8 文件。我希望文件包含这些字符“ÑÁ”,但我得到的是“�”。 这是代码 #include #include #inclu
嘿,我的 write 和 readFile 方法有问题。这些方法不做任何事情。该方法应该将动态数组的元素写入名为 C++ 的文件中。然后对于读取文件,该方法应该读取 ArrayList 的元素。 这是
我正在尝试将文件从资源复制到 %localappdata%。我有这样的东西: HINSTANCE hInstance = GetModuleHandle(NULL); HANDLE hFile = I
我正在尝试写入文本文件。我可以写入控制台,但是无法写入文本文件。我注意到的一件事是,如果我只是打印到控制台,则 String data 不包含任何数据,这可能就是我的文本文件中没有出现任何内容的原因。
我遇到了一个很奇怪的问题。 我正在连接到 Xbox 360 上的 Winsock 功能,发送。在我试图从中转储 Http 请求信息的应用程序中多次调用此函数。 首先我将展示代码并解释我的问题: Wri
我正在编写一个 activex 控件,它将访问并行端口并将字节写入其中。我能够成功打开端口,但是当我写入时它卡在 WriteFile 函数上。我在这里错过了什么吗?我正在使用 Windows 7 HA
我正在尝试将 16 字节数据写入串行端口,但我无法将值转换为 lpcvoid,这是我的代码, unsigned char Buffer[16]; for (int i=0; i<16; i++
我想写入一个随机输出,其中STD_OUTPUT_FILE即可。我想用WriteFile,但是好像什么都没写。 HANDLE outH = GetStdHandle ( STD_OUTPUT_HANDL
我正在尝试移植一些使用 read() 和 write() 函数发送套接字的 C。我正在尝试将其移植到 Windows,建议(根据我所阅读的内容)使用 WriteFile 和 ReadFile 来完成我
我正在尝试将 unsigned short 和 unsigned char 数组内容写入 .img 文件。我正在使用 WriteFile 方法来做同样的事情。似乎 WriteFile 函数成功地将数组
我想创建一个包含一些文本的简单文本文件。 import java.io.*; class TextFileWriter{ public static void writeTextFile(String
我是一名优秀的程序员,十分优秀!