网站首页  词典首页

请输入您要查询的函数:

 

术语 connectnamedpipe
释义 ConnectNamedPipe
语法:
C++
BOOL WINAPI ConnectNamedPipe(
__in HANDLE hNamedPipe,
__inout_opt LPOVERLAPPED lpOverlapped
);
ConnectNamedPipe功能
启用命名管道服务器进程为客户端进程等待连接到一个命名管道实例。连接客户端进程通过调用了CreateFile或CallNamedPipe功能。
参数
hNamedPipe [in]
句柄到一个命名管道实例服务器端。这种处理是由CreateNamedPipe函数返回。
lpOverlapped [中,指出,可选]
一个OVERLAPPED结构的指针。
如果hNamedPipe开幕时FILE_FLAG_OVERLAPPED的lpOverlapped参数必须是NULL。它必须指向一个有效的OVERLAPPED结构。如果hNamedPipe开幕时FILE_FLAG_OVERLAPPED和lpOverlapped为NULL,函数可以错误地报告说,连接操作完成。
如果hNamedPipe创造了与FILE_FLAG_OVERLAPPED和lpOverlapped不为NULL,OVERLAPPED结构应包含的句柄手动重置事件对象(该服务器可以通过使用CreateEvent函数)。
如果hNamedPipe不符合FILE_FLAG_OVERLAPPED打开,该函数不返回到客户端连接或发生错误。成功的同步操作导致返回一个非零值的功能,如果客户端连接后,调用函数。
返回值
如果操作是同步的,ConnectNamedPipe不会返回,直到操作完成。如果函数成功,返回值为非零。如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
如果操作是异步的,ConnectNamedPipe立即返回。如果操作仍悬而未决,返回值是零和GetLastError返回ERROR_IO_PENDING。 (您可以使用GetOverlappedResult函数检索手术后完成的结果。)如果函数失败,返回值为零,GetLastError返回值大于或ERROR_PIPE_CONNECTED其他ERROR_IO_PENDING。
If a client connects before the function is called, the function returns zero and GetLastError returns ERROR_PIPE_CONNECTED.发生这种情况如果客户端在CreateNamedPipe之间的调用和调用的ConnectNamedPipe间隔连接。在这种情况下,有一个客户端和服务器之间的良好关系,即使该函数返回零。
备注
命名管道服务器进程可以使用新创建的管道实例ConnectNamedPipe。它也可以用于与先前连接到另一端进程的实例,在这种情况下,服务器进程必须首先调用DisconnectNamedPipe函数断开从以前的客户端处理前处理,可以重新连接到新客户。否则,ConnectNamedPipe返回零,并GetLastError返回ERROR_NO_DATA如果以前的客户端已关闭了其处理或ERROR_PIPE_CONNECTED如果没有关闭其句柄。
在ConnectNamedPipe行为取决于设置为阻塞或非阻塞和功能是否被设置为执行同步或重叠模式在两个条件:是否管处理的等待模式。最初的服务器指定了一个管道句柄的等待在CreateNamedPipe功能模式,它可以通过使用SetNamedPipeHandleState功能改变。
服务器进程可以使用等待函数或SleepEx任何-以决定何时事件对象的状态信号,它可以使用GetOverlappedResult函数来确定的ConnectNamedPipe操作的结果。
如果指定的管道处理非阻塞模式,ConnectNamedPipe总是立即返回。在非阻塞模式,ConnectNamedPipe返回非零值第一次是一个管道实例是从以前的客户端断开调用。这表明该管道现在可以连接到一个新的客户端进程。在所有其他情况下,当管道处理非阻塞模式,ConnectNamedPipe返回零。在这种情况下,GetLastError返回ERROR_PIPE_LISTENING如果没有客户端连接,ERROR_PIPE_CONNECTED如果客户端连接,并ERROR_NO_DATA如果以前的客户端已关闭了管道句柄但服务器并没有断开。请注意,客户端和服务器之间的良好连接存在后,才收到ERROR_PIPE_CONNECTED错误。
注意:非阻塞模式支持与Microsoft LAN Manager版本2.0的兼容性,它不应该用来实现异步输入和输出(I / O的命名管道)。
实例
有关示例,请参见多线程管道服务器。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CallNamedPipe
CreateEvent
CreateFile
CreateNamedPipe
DisconnectNamedPipe
GetOverlappedResult
管功能
管概述
SetNamedPipeHandleState
SleepEx
的OVERLAPPED
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月30日
==英文原文==ConnectNamedPipe Function
Enables a named pipe server process to wait for a client process to connect to an instance of a named pipe. A client process connects by calling either the CreateFile or CallNamedPipe function.
Syntax
C++
BOOL WINAPI ConnectNamedPipe(
__in HANDLE hNamedPipe,
__inout_opt LPOVERLAPPED lpOverlapped
);
Parameters
hNamedPipe [in]
A handle to the server end of a named pipe instance. This handle is returned by the CreateNamedPipe function.
lpOverlapped [in, out, optional]
A pointer to an OVERLAPPED structure.
If hNamedPipe was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hNamedPipe was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the connect operation is complete.
If hNamedPipe was created with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the OVERLAPPED structure should contain a handle to a manual-reset event object (which the server can create by using the CreateEvent function).
If hNamedPipe was not opened with FILE_FLAG_OVERLAPPED, the function does not return until a client is connected or an error occurs. Successful synchronous operations result in the function returning a nonzero value if a client connects after the function is called.
Return Value
If the operation is synchronous, ConnectNamedPipe does not return until the operation has completed. If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError .
If the operation is asynchronous, ConnectNamedPipe returns immediately. If the operation is still pending, the return value is zero and GetLastError returns ERROR_IO_PENDING. (You can use the GetOverlappedResult function to retrieve the results after the operation has finished.) If the function fails, the return value is zero and GetLastError returns a value other than ERROR_IO_PENDING or ERROR_PIPE_CONNECTED.
If a client connects before the function is called, the function returns zero and GetLastError returns ERROR_PIPE_CONNECTED. This can happen if a client connects in the interval between the call to CreateNamedPipe and the call to ConnectNamedPipe. In this situation, there is a good connection between client and server, even though the function returns zero.
Remarks
A named pipe server process can use ConnectNamedPipe with a newly created pipe instance. It can also be used with an instance that was previously connected to another client process; in this case, the server process must first call the DisconnectNamedPipe function to disconnect the handle from the previous client before the handle can be reconnected to a new client. Otherwise, ConnectNamedPipe returns zero, and GetLastError returns ERROR_NO_DATA if the previous client has closed its handle or ERROR_PIPE_CONNECTED if it has not closed its handle.
The behavior of ConnectNamedPipe depends on two conditions: whether the pipe handle's wait mode is set to blocking or nonblocking and whether the function is set to execute synchronously or in overlapped mode. A server initially specifies a pipe handle's wait mode in the CreateNamedPipe function, and it can be changed by using the SetNamedPipeHandleState function.
The server process can use any of the wait functions or SleepEx — to determine when the state of the event object is signaled, and it can then use the GetOverlappedResult function to determine the results of the ConnectNamedPipe operation.
If the specified pipe handle is in nonblocking mode, ConnectNamedPipe always returns immediately. In nonblocking mode, ConnectNamedPipe returns a nonzero value the first time it is called for a pipe instance that is disconnected from a previous client. This indicates that the pipe is now available to be connected to a new client process. In all other situations when the pipe handle is in nonblocking mode, ConnectNamedPipe returns zero. In these situations, GetLastError returns ERROR_PIPE_LISTENING if no client is connected, ERROR_PIPE_CONNECTED if a client is connected, and ERROR_NO_DATA if a previous client has closed its pipe handle but the server has not disconnected. Note that a good connection between client and server exists only after the ERROR_PIPE_CONNECTED error is received.
Note Nonblocking mode is supported for compatibility with Microsoft LAN Manager version 2.0, and it should not be used to achieve asynchronous input and output (I/O) with named pipes.
Examples
For an example, see Multithreaded Pipe Server .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CallNamedPipe
CreateEvent
CreateFile
CreateNamedPipe
DisconnectNamedPipe
GetOverlappedResult
Pipe Functions
Pipes Overview
SetNamedPipeHandleState
SleepEx
OVERLAPPED
Send comments about this topic to Microsoft
Build date: 7/30/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365146(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:27:44