question

bongsujeon-3793 avatar image
0 Votes"
bongsujeon-3793 asked Viorel-1 commented

What does callback function mean in mswsock?

I read the MSDN for AcceptEx and LPFN_CONNECTEX(ConnectEx).
According to MSDN, AcceptEx is a function but LPFN_CONNECTEX is a callback function.
Is it just related to using WSAIoctl to get a function pointer?
If it is, Is LPFN_ACCEPTEX a callback function?

windows-api
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Your question is not related with windows-paltform-network and I will remove the tag. Thank you!

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 commented

I think that ConnectEx is a function that can be called by you, not a callback, however, in contrast to AcceptEx, it is not available directly. You must obtain a pointer to this function as explained in documentation. Probably like this:

 LPFN_CONNECTEX lpfnConnectex;
 GUID b = WSAID_CONNECTEX;
 DWORD n;
 WSAIoctl( s, SIO_GET_EXTENSION_FUNCTION_POINTER, &b, sizeof(b), &lpfnConnectex, sizeof(lpfnConnectex), &n, NULL, NULL);
    
 // call ConnectEx:
 lpfnConnectex(s, …..);


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer.
I think that a callback function isn't usually called directly.
But MSDN divides the mswsock functions into a function and callback function.
I agree to you answer about it.

I saw the explanation about AcceptEx with LPFN_ACCEPTEX.
there is a note for AcceptEx usage as below.
"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. ..."
So, I'm curious about whether LPFN_ACCEPTEX is a callback function as LPFN_CONNECTEX or not.

0 Votes 0 ·

It seems that both of AcceptEx and ConnectEx represents calleable functions, and both must be used via function pointers. For AcceptEx there is a LPFN_ACCEPTEX, although it is not mentioned immediately in documentation like LPFN_CONNECTEX, therefore the previous supposition about direct call of AcceptEx is not true (maybe it was in the past; however the MSWSock.h contains the definition of AcceptEx as a function, suggesting direct calls, maybe at least in certain circumstances). I am not sure why ConnectEx is called “callback”. Maybe this means calling via function pointers instead of direct linking with DLLs. (Usually "callback" means a function that is provided by you but is called by system).


0 Votes 0 ·