I've prepared a very small test program to demonstrate my problem. Just a basic form with 2 buttons, Listen and connect. Listen creates a listening socket and client socket for the AcceptEx() function, adds the listening socket to an IOCP and begins listening. On connect, we receive an IOCP message from AcceptEx(), now we call GetAcceptExSockaddrs() and pass it the same buffer as the AcceptEx() function bla bla bla ... exactly as MSDN tells me to ... this function returns the size of the sockaddr_in function (16) but doesn't write the IP or Port to the relative structure areas! Anyway, a small messagebox appears which is supposed to display this address in dot notation, instead it just displays 0.0.0.0 as if nothing was written to the structure. The real problem is that GetAcceptExSockaddrs() has no return values so I can't tell if there were any errors! Everything is working as normal except the GetAcceptExSockaddrs() function. Maybe someone can test it over a small lan as I've only tested via loopback! Has anyone done something like this???

Please test and see if you can spot anything!

Thanx in advance!
Posted on 2003-10-19 01:32:59 by SubEvil
Hi!

The local Variables LocalSockaddr and RemoveSockaddr arguments in your worker thread should be DWORD's.
Pass address to these to GetAcceptExSockaddrs, when it returns, they will point to sockaddr_in structs.
Like so:


LOCAL pLocalSockaddr :DWORD
LOCAL pRemoteSockaddr :DWORD

...... call GetAcceptExSockaddrs ...

mov eax, pRemoteSockaddr
mov eax, (sockaddr_in ptr [eax]).sin_addr
invoke inet_ntoa, eax
invoke MessageBoxEx, NULL, eax, sz("inet_ntoa"), NULL, NULL


edit: RemoveSockaddr = RemoteSockaddr, sorry :) haha
Posted on 2003-10-21 17:41:44 by david
David ... Thank you so much for taking the time to help!
You are a life saver!

So this function actually allocates the memory for you and sends you a pointer to the allocated memory! Any idea how the memory gets allocated or freed, and how long this data stays memory resident? Will it stay in memory for the duration of the application? If you get lots of connections and disconnections, will it not consume lots of memory over time? Is it possible to free this memory? And this should deffinately have been made more clear in the MSDN! ... Anyway ... just some thoughts I had!

Thanx again David for taking the time to read my code and help out!
Posted on 2003-10-22 12:42:04 by SubEvil
thanks yourself, happy i could help!! :) I'm struggling with iocompletionports myself now too.

I don't know how long the memory is valid, ... I never messed with it, and documentation about this api says nothing about this.
But with inet_ntoa for instance, which returns a pointer to a string, the documentation says
"The data is guaranteed to be valid until the next Windows Sockets function call within the same thread, but no longer."
So I copy the memory to my programs memory to be safe.
Posted on 2003-10-22 19:26:30 by david