Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AcceptEx without WSAIoctl

Tags:

c++

sockets

Is there any difference between using AcceptEx direct call or using function pointer obtained by WSAIoctl.

MSDN doesn't fully covers this question regarding performance issue and other problems that can be faced using AcceptEx as direct call.

And other question is: If I have for example 4 listening sockets in my program, do I need to call WSAIoctl for each listening socket and of course store function pointer for every socket? Or it is enough to call it once for any socket and than use with other ones.

Thank in advance.

like image 949
Valentin Avatar asked Feb 21 '26 06:02

Valentin


2 Answers

Calling the function without previously obtaining a function pointer (that is, by linking with mswsock.lib and calling AcceptEx directly) is costly because AcceptEx sits outside the layered architecture of Winsock2. AcceptEx must request a function pointer using WSAIoctl for every call on the off chance that the application is actually trying to invoke AcceptEx from a provider layered on top of mswsock (see Figure 3). To avoid this significant performance penalty on each call, an application that intends to use these APIs should obtain the pointers to these functions directly from the layered provider by calling WSAIoctl.

From http://msdn.microsoft.com/en-us/magazine/cc302334.aspx

like image 114
RocketR Avatar answered Feb 23 '26 20:02

RocketR


WSAIoctl. It's an extension provider that you use for new functions/additions to the winsock functionality, each new windows version usually add a couple of new extensions.

AcceptEx function pointer: Using the AcceptEx directly binds the application to the Microsoft provider with the need for MSWsock.dll. As for correctness you probably should do it the msdn way and use the functions through the extension.

Just set it up once and use as you would have with the MSWsock-AcceptEx (you will still be using the same thing)

As for speed/performance I would suggest concentrating on the pooling of sockets instead.

Edit: Should clarify the (msdn) reason for separating - Extensions are Microsoft specific functions that other providers should not be forced to implement.

like image 25
Simon Avatar answered Feb 23 '26 20:02

Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!