Async network design considerations
I''m implmenting an asynchronous network manager and haven''t really used it before. I understand how to use it (read the tutorials) but I''m more having trouble with a design that works. Currently I have an AsyncNetworkManager that makes an invisible window to handle network communication and is responsible for tracking AsyncSocket objects. However in some cases the AsyncSockets need to talk to the Manager, and in others, the Manager needs to talk to the AsyncSockets. What sort of techniques work well here?
> ...invisible window...
Is that the way you want to go? I guess you''re using Windows(?). Use winsock2, open the socket and use ReadFile/WriteFile with an overlapped struct to do async reads/writes. That''s a much more stable approach than dealing with hidden windows. The design is cleaner as it''s easier to separate UI from your logic. It also works in services.
Is that the way you want to go? I guess you''re using Windows(?). Use winsock2, open the socket and use ReadFile/WriteFile with an overlapped struct to do async reads/writes. That''s a much more stable approach than dealing with hidden windows. The design is cleaner as it''s easier to separate UI from your logic. It also works in services.
quote:Original post by Anonymous Poster
> ...invisible window...
Is that the way you want to go? I guess you''re using Windows(?). Use winsock2, open the socket and use ReadFile/WriteFile with an overlapped struct to do async reads/writes. That''s a much more stable approach than dealing with hidden windows. The design is cleaner as it''s easier to separate UI from your logic. It also works in services.
Interesting, I will look up overlapped I/O with sockets now.
Looks sweet and puts the old method to shame. Not that it took much to do that anyway .
Most people have Winsock 2 I assume? And 9x emulates the overlapped I/O okay? Also, any words of wisdom?
Most people have Winsock 2 I assume? And 9x emulates the overlapped I/O okay? Also, any words of wisdom?
quote:Original post by antareus
Looks sweet and puts the old method to shame. Not that it took much to do that anyway .
Most people have Winsock 2 I assume? And 9x emulates the overlapped I/O okay? Also, any words of wisdom?
Found a MSKB article that shows how 9x loses callback events under stress. Is this worth worrying about?
I excel at talking to myself.
I can''t use overlapped I/O because my design is inherently asynchronous, and you either have to poll the sockets using WSAWaitForMultipleObjects every x milliseconds (yuck) or use completion callbacks, which have issues on 9x, which I''d like to be able to run on.
I can''t use overlapped I/O because my design is inherently asynchronous, and you either have to poll the sockets using WSAWaitForMultipleObjects every x milliseconds (yuck) or use completion callbacks, which have issues on 9x, which I''d like to be able to run on.
quote:Original post by antareus I can''t use overlapped I/O because my design is inherently asynchronous, and you either have to poll the sockets using WSAWaitForMultipleObjects every x milliseconds (yuck) or use completion callbacks, which have issues on 9x, which I''d like to be able to run on.I haven''t used sockets on Windows 95 much, and don''t know all differences so I may be wrong. But why can''t you wait for WSA_INFINITE time rather than polling?
quote:Original post by Anonymous Poster
I haven't used sockets on Windows 95 much, and don't know all differences so I may be wrong. But why can't you wait for WSA_INFINITE time rather than polling?
I don't really have a main window in my application - or not yet. My confusion on how to use overlapped I/O stems from where I'd place the call to WSAWaitForMultipleObjects - I am aiming for a single threaded design. I don't really have a place to put the call. I have a single message loop running, and windows will be created and destroyed, but it seems like I'd need a thread to use overlapped I/O.
[edited by - antareus on December 24, 2002 2:22:12 PM]
[edited by - antareus on December 24, 2002 2:23:03 PM]
I think you can use this approach to stay single-threaded:
setup initially:
OVERLAPPED g_overlappedRead = {0};
g_overlappedRead.hEvent=CreateEvent(...)
HANDLE g_handles[] = {g_overlappedRead.hEvent};
issue read:
ReadFile(g_hSocket, ..., &g_overlappedRead);
in message loop, wait for message OR socket data arrival:
MsgWaitForMultipleObjects(g_handles, ...)
setup initially:
OVERLAPPED g_overlappedRead = {0};
g_overlappedRead.hEvent=CreateEvent(...)
HANDLE g_handles[] = {g_overlappedRead.hEvent};
issue read:
ReadFile(g_hSocket, ..., &g_overlappedRead);
in message loop, wait for message OR socket data arrival:
MsgWaitForMultipleObjects(g_handles, ...)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement