At 11:58 PM 08/14/2004, you wrote:

> from which device the information is coming.  When I am preparing to use
> WSASend, do I need to allocate a separate OVERLAPPED struct or can I use
the
> existing one by adding a send buffer to my already present receive buffer?


*Every IO* should have it's own overlapped. Not just one overlapped for all writes and one overlapped for all reads. You probably already knew this, but just in case. :-)

For the writes you can use the same outbound buffer if you are sending the
same data to all the sockets.  In your overlapped derived instances have
them use all the same buffer object and increment it's counter once for each
write, then do your writes, as each write completes decrement the counter
(wrapped by a crit section), upon zero, free the write buffer object.

Of course this doesn't work for reads because you'd have all the sockets
overwriting the same buffer.

While I'm at it, another "trick" is *don't* keep track of any outstanding
IOs.  You won't need to.  When you close the socket (or it closes from the
other end or from network failure) all the outstanding IOs will hit the IOCP
queue as errors, giving you the chance to clean them up.  Keeping track of
all of them is a waste of your coding time and your system's memory.

/dev

You sure are right again Dev, I took your advice long ago and derived a custom OVERLAPPED. One of the members of my derived class a pointer to the class that represents the device that is receiving the data. With this arrangement, I have successfully had multiple devices all sending asynchronously and don't have to keep up with any of the IO myself. I just handle whatever number of bytes the IOCP hands me at any given time until I get an entire message, then I process it.


Based on the answers to my question about the separate overlapped, I created another of these derived overlapped with an additional bool indicating that I am sending, now I get a notification on my send that allows me to log a successfully sent message. I won't know for certain that all is well until I get my hands on the hardware next week, but my tests look very positive. Unfortunately, I can't share the send buffer data as again each device has some different requirements, but I will have to implement a common request for status message that this probably fits nicely into.

A question on the notification that I get on send: Do I get this notification when I send or when the send is completed? Will I get one when the data is successfully received at the device?

Thanks again all!

David


_______________________________________________ msvc mailing list [EMAIL PROTECTED] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.

Reply via email to