青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

AcceptEx Function[MSDN 做個記錄]

AcceptEx Function

The AcceptEx function accepts a new connection, returns the local and remote address, and receives the first block of data sent by the client application.

Note  This function is a Microsoft-specific extension to the Windows Sockets specification.


引用
BOOL AcceptEx(
  __in   SOCKET sListenSocket,
  __in   SOCKET sAcceptSocket,
  __in   PVOID lpOutputBuffer,
  __in   DWORD dwReceiveDataLength,
  __in   DWORD dwLocalAddressLength,
  __in   DWORD dwRemoteAddressLength,
  __out  LPDWORD lpdwBytesReceived,
  __in   LPOVERLAPPED lpOverlapped
);

Parameters
sListenSocket
A descriptor identifying a socket that has already been called with the listen function. A server application waits for attempts to connect on this socket.

sAcceptSocket
A descriptor identifying a socket on which to accept an incoming connection. This socket must not be bound or connected.

lpOutputBuffer
A pointer to a buffer that receives the first block of data sent on a new connection, the local address of the server, and the remote address of the client. The receive data is written to the first part of the buffer starting at offset zero, while the addresses are written to the latter part of the buffer. This parameter must be specified.

dwReceiveDataLength
The number of bytes in lpOutputBuffer that will be used for actual receive data at the beginning of the buffer. This size should not include the size of the local address of the server, nor the remote address of the client; they are appended to the output buffer. If dwReceiveDataLength is zero, accepting the connection will not result in a receive operation. Instead, AcceptEx completes as soon as a connection arrives, without waiting for any data.

dwLocalAddressLength
The number of bytes reserved for the local address information. This value must be at least 16 bytes more than the maximum address length for the transport protocol in use.

dwRemoteAddressLength
The number of bytes reserved for the remote address information. This value must be at least 16 bytes more than the maximum address length for the transport protocol in use. Cannot be zero.

lpdwBytesReceived
A pointer to a DWORD that receives the count of bytes received. This parameter is set only if the operation completes synchronously. If it returns ERROR_IO_PENDING and is completed later, then this DWORD is never set and you must obtain the number of bytes read from the completion notification mechanism.

lpOverlapped
An OVERLAPPED structure that is used to process the request. This parameter must be specified; it cannot be NULL.

Return Value
If no error occurs, the AcceptEx function completed successfully and a value of TRUE is returned.

If the function fails, AcceptEx returns FALSE. The WSAGetLastError function can then be called to return extended error information. If WSAGetLastError returns ERROR_IO_PENDING, then the operation was successfully initiated and is still in progress. If the error is WSAECONNRESET, an incoming connection was indicated, but was subsequently terminated by the remote peer prior to accepting the call.

Remarks


The AcceptEx function combines several socket functions into a single API/kernel transition. The AcceptEx function, when successful, performs three tasks:

A new connection is accepted.
Both the local and remote addresses for the connection are returned.
The first block of data sent by the remote is received.

Note  The function pointer for the AcceptEx function must be obtained at run time by making a call to the WSAIoctl function with the SIO_GET_EXTENSION_FUNCTION_POINTER opcode specified. The input buffer passed to the WSAIoctl function must contain WSAID_ACCEPTEX, a globally unique identifier (GUID) whose value identifies the AcceptEx extension function. On success, the output returned by the WSAIoctl function contains a pointer to the AcceptEx function. The WSAID_ACCEPTEX GUID is defined in the Mswsock.h header file.

A program can make a connection to a socket more quickly using AcceptEx instead of the accept function.

A single output buffer receives the data, the local socket address (the server), and the remote socket address (the client).

Using a single buffer improves performance. When using AcceptEx, the GetAcceptExSockaddrs function must be called to parse the buffer into its three distinct parts (data, local socket address, and remote socket address). On Windows XP and later, once the AcceptEx function completes and the SO_UPDATE_ACCEPT_CONTEXT option is set on the accepted socket, the local address associated with the accepted socket can also be retrieved using the getsockname function. Likewise, the remote address associated with the accepted socket can be retrieved using the getpeername function.

The buffer size for the local and remote address must be 16 bytes more than the size of the sockaddr structure for the transport protocol in use because the addresses are written in an internal format. For example, the size of a sockaddr_in (the address structure for TCP/IP) is 16 bytes. Therefore, a buffer size of at least 32 bytes must be specified for the local and remote addresses.

The AcceptEx function uses overlapped I/O, unlike the accept function. If your application uses AcceptEx, it can service a large number of clients with a relatively small number of threads. As with all overlapped Windows functions, either Windows events or completion ports can be used as a completion notification mechanism.



Another key difference between the AcceptEx function and the accept function is that AcceptEx requires the caller to already have two sockets:

One that specifies the socket on which to listen.
One that specifies the socket on which to accept the connection.
The sAcceptSocket parameter must be an open socket that is neither bound nor connected.

The lpNumberOfBytesTransferred parameter of the GetQueuedCompletionStatus function or the GetOverlappedResult function indicates the number of bytes received in the request.



When this operation is successfully completed, sAcceptSocket can be passed, but to the following functions only:

ReadFile
WriteFile
send
WSASend
recv
WSARecv
TransmitFile
closesocket
setsockopt (only for SO_UPDATE_ACCEPT_CONTEXT)
Note  If the TransmitFile function is called with both the TF_DISCONNECT and TF_REUSE_SOCKET flags, the specified socket has been returned to a state in which it is neither bound nor connected. The socket handle can then be passed to the AcceptEx function in the sAcceptSocket parameter, but the socket cannot be passed to the ConnectEx function.

When the AcceptEx function returns, the socket sAcceptSocket is in the default state for a connected socket. The socket sAcceptSocket does not inherit the properties of the socket associated with sListenSocket parameter until SO_UPDATE_ACCEPT_CONTEXT is set on the socket. Use the setsockopt function to set the SO_UPDATE_ACCEPT_CONTEXT option, specifying sAcceptSocket as the socket handle and sListenSocket as the option value.


For example:
  1.  err = setsockopt( sAcceptSocket,    
  2.     SOL_SOCKET,    
  3.     SO_UPDATE_ACCEPT_CONTEXT,    
  4.     (char *)&sListenSocket,    
  5.     sizeof(sListenSocket) );   

If a receive buffer is provided, the overlapped operation will not complete until a connection is accepted and data is read. Use the getsockopt function with the SO_CONNECT_TIME option to check whether a connection has been accepted. If it has been accepted, you can determine how long the connection has been established. The return value is the number of seconds that the socket has been connected. If the socket is not connected, the getsockopt returns 0xFFFFFFFF. Applications that check whether the overlapped operation has completed, in combination with the SO_CONNECT_TIME option, can determine that a connection has been accepted but no data has been received. Scrutinizing a connection in this manner enables an application to determine whether connections that have been established for a while have received no data. It is recommended such connections be terminated by closing the accepted socket, which forces the AcceptEx function call to complete with an error.


For example:

  1.  INT seconds;   
  2. INT bytes = sizeof(seconds);   
  3. err = getsockopt( sAcceptSocket, SOL_SOCKET, SO_CONNECT_TIME,   
  4.                       (char *)&seconds, (PINT)&bytes );   
  5. if ( err != NO_ERROR ) {   
  6.     printf( "getsockopt(SO_CONNECT_TIME) failed: %ld\n", WSAGetLastError( ) );   
  7.     exit(1);   
  8. }   

Note   All I/O initiated by a given thread is canceled when that thread exits. For overlapped sockets, pending asynchronous operations can fail if the thread is closed before the operations complete. See ExitThread for more information.

Example Code

The following example uses the AcceptEx function using overlapped I/O and completion ports.

  1.  #include <stdio.h>   
  2. #include "winsock2.h"   
  3. #include "mswsock.h"   
  4.   
  5. void main() {   
  6.   //----------------------------------------   
  7.   // Declare and initialize variables   
  8.   WSADATA wsaData;   
  9.   HANDLE hCompPort;   
  10.   LPFN_ACCEPTEX lpfnAcceptEx = NULL;   
  11.   GUID GuidAcceptEx = WSAID_ACCEPTEX;   
  12.   WSAOVERLAPPED olOverlap;   
  13.      
  14.   SOCKET ListenSocket, AcceptSocket;   
  15.   sockaddr_in service;   
  16.   char lpOutputBuf[1024];   
  17.   int outBufLen = 1024;   
  18.   DWORD dwBytes;   
  19.   
  20.   //----------------------------------------   
  21.   // Initialize Winsock   
  22.   int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );   
  23.   if( iResult != NO_ERROR )   
  24.     printf("Error at WSAStartup\n");   
  25.   
  26.   //----------------------------------------   
  27.   // Create a handle for the completion port   
  28.   hCompPort = CreateIoCompletionPort( INVALID_HANDLE_VALUE, NULL, (u_long)0, 0 );   
  29.   
  30.   //----------------------------------------   
  31.   // Create a listening socket   
  32.   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );   
  33.   if (ListenSocket == INVALID_SOCKET) {   
  34.     printf("Error at socket(): ListenSocket\n");   
  35.     WSACleanup();   
  36.     return;   
  37.   }   
  38.   
  39.   //----------------------------------------   
  40.   // Associate the listening socket with the completion port   
  41.   CreateIoCompletionPort((HANDLE)ListenSocket, hCompPort, (u_long)0, 0);   
  42.   
  43.   //----------------------------------------   
  44.   // Bind the listening socket to the local IP address   
  45.   // and port 27015   
  46.   hostent* thisHost;   
  47.   char* ip;   
  48.   u_short port;   
  49.   port = 27015;   
  50.   thisHost = gethostbyname("");   
  51.   ip = inet_ntoa (*(struct in_addr *)*thisHost->h_addr_list);   
  52.   
  53.   service.sin_family = AF_INET;   
  54.   service.sin_addr.s_addr = inet_addr(ip);  service.sin_port = htons(port);   
  55.   
  56.   if ( bind( ListenSocket,(SOCKADDR*) &service, sizeof(service) )  == SOCKET_ERROR ) {   
  57.     printf("bind failed\n");   
  58.     closesocket(ListenSocket);   
  59.     return;   
  60.   }   
  61.   
  62.   //----------------------------------------   
  63.   // Start listening on the listening socket   
  64.   if (listen( ListenSocket, 100 ) == SOCKET_ERROR) {   
  65.     printf("error listening\n");   
  66.   }    
  67.   printf("Listening on address: %s:%d\n", ip, port);   
  68.   
  69.   //----------------------------------------   
  70.   // Load the AcceptEx function into memory using WSAIoctl.   
  71.   // The WSAIoctl function is an extension of the ioctlsocket()   
  72.   // function that can use overlapped I/O. The function's 3rd   
  73.   // through 6th parameters are input and output buffers where   
  74.   // we pass the pointer to our AcceptEx function. This is used   
  75.   // so that we can call the AcceptEx function directly, rather   
  76.   // than refer to the Mswsock.lib library.   
  77.   WSAIoctl(ListenSocket,    
  78.     SIO_GET_EXTENSION_FUNCTION_POINTER,    
  79.     &GuidAcceptEx,    
  80.     sizeof(GuidAcceptEx),   
  81.     &lpfnAcceptEx,    
  82.     sizeof(lpfnAcceptEx),    
  83.     &dwBytes,    
  84.     NULL,    
  85.     NULL);   
  86.   
  87.   //----------------------------------------   
  88.   // Create an accepting socket   
  89.   AcceptSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);   
  90.   if (AcceptSocket == INVALID_SOCKET) {   
  91.     printf("Error creating accept socket.\n");   
  92.     WSACleanup();   
  93.     return;   
  94.   }   
  95.   
  96.   //----------------------------------------   
  97.   // Empty our overlapped structure and accept connections.   
  98.   memset(&olOverlap, 0, sizeof(olOverlap));   
  99.   
  100.   lpfnAcceptEx(ListenSocket,    
  101.     AcceptSocket,   
  102.     lpOutputBuf,    
  103.     outBufLen - ((sizeof(sockaddr_in) + 16) * 2),   
  104.     sizeof(sockaddr_in) + 16,    
  105.     sizeof(sockaddr_in) + 16,    
  106.     &dwBytes,    
  107.     &olOverlap);   
  108.   
  109.   //----------------------------------------   
  110.   // Associate the accept socket with the completion port   
  111.   CreateIoCompletionPort((HANDLE)AcceptSocket, hCompPort, (u_long)0, 0);   
  112.   
  113.   //----------------------------------------   
  114.   // Continue on to use send, recv, TransmitFile(), etc.,.   
  115.   ...   
  116.   
  117. }   

Notes for QOS
The TransmitFile function allows the setting of two flags, TF_DISCONNECT or TF_REUSE_SOCKET, that return the socket to a "disconnected, reusable" state after the file has been transmitted. These flags should not be used on a socket where quality of service has been requested, since the service provider may immediately delete any quality of service associated with the socket before the file transfer has completed. The best approach for a QOS-enabled socket is to simply call the closesocket function when the file transfer has completed, rather than relying on these flags.

Notes for ATM
There are important issues associated with connection setup when using Asynchronous Transfer Mode (ATM) with Windows Sockets 2. Please see the Remarks section in the accept function documentation for important ATM connection setup information.

Requirements
Client Requires Windows Vista, Windows XP, Windows 2000 Professional, or Windows NT Workstation 3.51 and later.
Server Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.51 and later.
Header Declared in Mswsock.h.

Library Use Mswsock.lib.

DLL Requires Mswsock.dll.


如果你想它連接上就立即提示連接完成,則只須將dwReceiveDataLength賦0就OK.

使用AcceptEx()的一大好處是,
你可以通過一次調用就完成接受客戶端連接請求和接受數據(通過傳送lpOutputBuffer參數)兩件事情。
也就是說,如果客戶端在發出連接的同時傳輸數據,
你的AcceptEx()調用在連接創建并接收了客戶端數據后就可以立刻返回。
這樣可能是很有用的,但是也可能會引發問題,因為AcceptEx()必須等全部客戶端數據都收到了才返回。
具體來說,如果你在發出AcceptEx()調用的同時傳遞了 lpOutputBuffer參數,那么AcceptEx()不再是一項原子型的操作,
而是分成了兩步:接受客戶連接,等待接收數據。當缺少一種機制來通知你的應用程序所發生的這種情況:“連接已經建立了,正在等待客戶端數據”,這將意味著有可能出現客戶端只發出連接請求,但是不發送數據。

posted @ 2008-04-28 14:47 RedLight 閱讀(1245) | 評論 (0)編輯 收藏

解決Linux/Unix下OCI程序動態庫版本的問題

     摘要:   閱讀全文

posted @ 2008-04-17 01:04 RedLight 閱讀(701) | 評論 (0)編輯 收藏

投影矩陣的實現以及如何從投影矩陣中獲取各視裁體平面(教程)

     摘要:   閱讀全文

posted @ 2008-04-16 09:49 RedLight 閱讀(2228) | 評論 (0)編輯 收藏

DirectX 9的坐標系統變換

     摘要:   閱讀全文

posted @ 2008-04-16 09:45 RedLight 閱讀(690) | 評論 (0)編輯 收藏

Direct3D中實現圖元的鼠標拾取

     摘要:   閱讀全文

posted @ 2008-04-16 09:44 RedLight 閱讀(544) | 評論 (0)編輯 收藏

C++/C 試題的答案與評分標準

     摘要:   閱讀全文

posted @ 2008-04-16 09:42 RedLight 閱讀(474) | 評論 (0)編輯 收藏

C++/C 試題 (面試必看)

     摘要:   閱讀全文

posted @ 2008-04-16 09:41 RedLight 閱讀(616) | 評論 (0)編輯 收藏

內存管理----高質量C++

     摘要:   閱讀全文

posted @ 2008-04-16 09:39 RedLight 閱讀(1146) | 評論 (0)編輯 收藏

epoll的優點及epoll學習心得

     摘要:   閱讀全文

posted @ 2008-04-16 09:14 RedLight 閱讀(1763) | 評論 (0)編輯 收藏

pthread庫進行多線程編程

     摘要:   閱讀全文

posted @ 2008-04-16 09:14 RedLight 閱讀(1250) | 評論 (0)編輯 收藏

僅列出標題
共9頁: 1 2 3 4 5 6 7 8 9 
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

導航

統計

公告


Name: Galen
QQ: 88104725

常用鏈接

留言簿(3)

隨筆分類

隨筆檔案

相冊

My Friend

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲视频一区二区在线观看 | 久久国产精品久久久| 久久国产黑丝| 亚洲自拍偷拍网址| 亚洲美女av网站| 国产一区二区中文| 国产伦精品一区二区三区免费| 欧美午夜精品久久久久久浪潮| 欧美精品v日韩精品v韩国精品v| 久久精品人人做人人爽电影蜜月| 亚洲综合激情| 久久国产88| 欧美在线播放| 亚洲一区欧美| 久久久一本精品99久久精品66| 欧美在线综合视频| 欧美成人情趣视频| 亚洲午夜伦理| 久久午夜羞羞影院免费观看| 欧美激情第3页| 国产亚洲欧美一区在线观看| 亚洲第一福利视频| 亚洲免费视频在线观看| 亚洲精品人人| 欧美专区日韩视频| 美女在线一区二区| 亚洲一区久久久| 久久色在线播放| 国产日韩欧美夫妻视频在线观看| 亚洲第一页在线| 久久青草福利网站| 亚洲综合成人在线| 国产精品网站一区| 一本色道久久综合亚洲精品按摩 | 亚洲欧洲一区二区三区在线观看| 亚洲欧洲在线视频| 男男成人高潮片免费网站| 国产精品v欧美精品v日本精品动漫| 国产亚洲欧美一区二区| 久久xxxx精品视频| 欧美亚洲自偷自偷| 国产精品自在在线| 国产精品一区二区三区久久久 | 欧美日韩国产一级| 亚洲精品免费看| 亚洲精品日本| 国产精品久久久久久久久久三级| 一区二区三区免费网站| 亚洲乱码国产乱码精品精| 欧美精品久久99| 国产精品99久久久久久www| 夜夜嗨av色一区二区不卡| 国产精品第13页| 久久国产精品99精品国产| 久久成人一区| 一道本一区二区| 欧美亚洲综合网| 亚洲日本激情| 性色av一区二区三区| 亚洲精品欧美专区| 欧美在线啊v一区| 亚洲精品五月天| 久久久久久尹人网香蕉| 一本色道久久88亚洲综合88| 欧美一级日韩一级| 一本色道久久综合| 老司机午夜精品| 午夜视频在线观看一区| 毛片精品免费在线观看| 欧美一区2区三区4区公司二百| 美女91精品| 蜜桃av一区二区三区| 国产午夜精品久久久久久免费视| 99国产精品私拍| 一区二区不卡在线视频 午夜欧美不卡在| 亚洲欧美精品一区| 免费成人黄色片| 欧美中文日韩| 国产精品福利影院| 亚洲一区二区三区高清| 亚洲视频福利| 欧美视频一区二| 亚洲综合视频网| 午夜精品三级视频福利| 国产精品久久| 欧美大色视频| 国产精品久久国产愉拍| 午夜电影亚洲| 国产精品v日韩精品v欧美精品网站| 亚洲第一视频| 亚洲视频一区二区| 国产女人水真多18毛片18精品视频| 中文国产成人精品| 久久精品一区二区三区四区 | 国产日韩欧美一二三区| 欧美一区二区三区另类| 欧美激情亚洲另类| 99视频精品全部免费在线| 国产精品麻豆成人av电影艾秋| 亚洲午夜日本在线观看| 欧美电影免费观看大全| 欧美一区二区三区久久精品 | 欧美日韩一区二区三区四区在线观看| 亚洲国产一区二区精品专区| 亚洲一区国产精品| 亚洲国产精品成人一区二区| 欧美日韩在线三级| 欧美日韩国产在线播放网站| 午夜在线精品偷拍| 亚洲一区国产视频| 国产综合久久久久影院| 欧美人与性动交α欧美精品济南到| 亚洲综合成人在线| 亚洲免费av观看| 亚洲丰满在线| 欧美成人亚洲成人| 嫩草国产精品入口| 久色成人在线| 欧美a级片网站| 浪潮色综合久久天堂| 久久久亚洲影院你懂的| 久久精品91久久香蕉加勒比| 欧美一区二区黄色| 久久人人爽爽爽人久久久| 久久久久国产精品www| 久久久久久久久蜜桃| 久久蜜臀精品av| 亚洲国产精品精华液网站| 亚洲人成高清| 亚洲午夜精品久久久久久app| 亚洲天堂偷拍| 久久精品中文字幕一区二区三区| 久久精品在线播放| 欧美日韩一区二区三区在线| 国产精品看片资源| 亚洲成人在线免费| 亚洲欧美日韩第一区| 久久久九九九九| 91久久综合| 久久三级福利| 国产欧美亚洲日本| 日韩视频在线你懂得| 久久久久9999亚洲精品| 日韩小视频在线观看| 久久久久久自在自线| 国产精品久久看| 日韩一区二区免费高清| 久久伊人亚洲| 午夜在线精品| 国产网站欧美日韩免费精品在线观看| 亚洲人成在线播放| 91久久综合亚洲鲁鲁五月天| 日韩午夜免费视频| 欧美电影免费观看| 免费成人激情视频| 亚洲日本中文字幕免费在线不卡| 欧美中日韩免费视频| 亚洲免费婷婷| 伊人久久综合| 亚洲第一精品福利| 欧美波霸影院| 亚洲国产精品久久久久秋霞蜜臀 | 久久本道综合色狠狠五月| 欧美日韩综合| 亚洲午夜一二三区视频| 亚洲乱亚洲高清| 欧美日韩一区二区高清| 在线午夜精品自拍| 亚洲一级在线观看| 影音先锋久久| 亚洲精选视频免费看| 欧美午夜精品电影| 久久精品主播| 欧美日韩国产首页| 久久九九热免费视频| 欧美国产日韩亚洲一区| 亚洲一区美女视频在线观看免费| 亚洲一区二区三区视频| 一区视频在线播放| 亚洲欧美精品一区| 日韩一二三在线视频播| 午夜精品久久久久久久久| 亚洲人在线视频| 国产精品高清网站| 欧美激情第六页| 国产亚洲网站| 亚洲一区二区三区激情| 亚洲欧洲精品天堂一级| 亚洲欧美在线一区二区| 99综合视频| 欧美不卡视频一区| 亚洲国产高清在线观看视频| 国产亚洲毛片在线| 好吊妞这里只有精品| 亚洲女同同性videoxma| 亚洲一区三区在线观看| 欧美理论电影网| 一本大道久久a久久精品综合| 午夜在线视频观看日韩17c| 欧美综合国产|