PR_Connect 编辑
Initiates a connection on a specified socket.
Syntax
#include <prio.h> /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRStatus PR_Connect( /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc *fd, const /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRNetAddr *addr, /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntervalTime timeout);
Parameters
The function has the following parameters:
fd
- A pointer to a
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc
object representing a socket. addr
- A pointer to the address of the peer to which the socket is to be connected.
timeout
- A value of type
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntervalTime
specifying the time limit for completion of the connect operation.
Returns
The function returns one of the following values:
- Upon successful completion of connection setup,
PR_SUCCESS
. - If unsuccessful,
PR_FAILURE
. Further information can be obtained by calling/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_GetError
.
Description
PR_Connect
is usually invoked on a TCP socket, but it may also be invoked on a UDP socket. Both cases are discussed here.
If the socket is a TCP socket, PR_Connect
establishes a TCP connection to the peer. If the socket is not bound, it will be bound to an arbitrary local address.
PR_Connect
blocks until either the connection is successfully established or an error occurs. The function uses the lesser of the provided timeout and the OS's connect timeout. In particular, if you specify PR_INTERVAL_NO_TIMEOUT
as the timeout, the OS's connection time limit will be used.
If the socket is a UDP socket, there is no connection setup to speak of, since UDP is connectionless. If PR_Connect
is invoked on a UDP socket, it has an overloaded meaning: PR_Connect
merely saves the specified address as the default peer address for the socket, so that subsequently one can send and receive datagrams from the socket using /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Send
and /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Recv
instead of the usual /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_SendTo
and /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_RecvFrom
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论