flat assembler
Message board for the users of flat assembler.
Index
> Windows > overlapped operations, errors. |
Author |
|
revolution 17 Jul 2010, 15:30
Winsock sends a message to your window to indicate I/O status updates. You set it up like this:
Code: invoke WSAAsyncSelect,[sock],[hwnd],MY_SOCKET_EVENT,FD_READ+FD_WRITE+FD_CONNECT+FD_CLOSE Code: cmp [wmsg],MY_SOCKET_EVENT jz .socket_event For file I/O it is a little bit trickier. You need to use an alertable wait function to receive the callback of I/O status changes. MsgWaitForMultipleObjectsEx and SleepEx are the most commonly used. The former is Win2K+ and the latter is Win95+ if that is important to you. |
|||
17 Jul 2010, 15:30 |
|
b1528932 17 Jul 2010, 19:44
instead of + you mean | ?
im not asking about winsock, but fundamental design of overlapped io. and i dont know why they included this notyfication thing, really. receiving anything other than FD_CONNECT and FD_ACCEPT is useless. and even those 2 can be used in overlapped manner on windows xp and later. |
|||
17 Jul 2010, 19:44 |
|
revolution 17 Jul 2010, 19:55
| is a logical operator in fasm. If you are unsure about overlapping bits then use or for binary operations.
As for the fundamental design of overlapped I/O, it depends upon which sub-system you are using. The sockets operate differently from the files so you have to treat each in a different manner. If you don't have any notifications, then how do you know when a background operation needs attention? I don't understand why you say "anything other than FD_CONNECT and FD_ACCEPT is useless". Why do you think that? When using Overlapped I/O in the proper manner in a single threaded application it is possible to have 1000s of simultaneous open sockets and files without ever blocking just by processing the notifications as they arrive. |
|||
17 Jul 2010, 19:55 |
|
b1528932 17 Jul 2010, 20:10
Quote: I don't understand why you say "anything other than FD_CONNECT and FD_ACCEPT is useless". because non-blocking more is worse than overlapped. in overlapped mode everything is synchronous, you dont have to do arbitary functions upon other data, like whenb you receive fd_close, or fd_obb. i prefer having 1 main thread, and use io completion ports. - *Ex apc method is broken by design - deadlock. - WaitForMultiple - limit 63 handles, each requiring event object. Events are not cheap. So only 63 operations could execute simultaniusly, no matter what - suck. when using iocp i can create worker thread(s) and do all processing there, nothing useless in main thread. main thread could process window messages, and block on waitformultiple. aha, overlapped != nonblocking. perhaps you didnt know that. overlapped is superior, nonblocking is legacy from < win2000 (and from win2000 becaus eit lack overlapped connect/accept) |
|||
17 Jul 2010, 20:10 |
|
revolution 18 Jul 2010, 01:12
b1528932: I don't understand your problem. Do you have some code that you are having trouble with?
|
|||
18 Jul 2010, 01:12 |
|
revolution 18 Jul 2010, 01:27
BTW: You are incorrect about the 63 operation limit. With overlapped I/O the file system uses the APC which has no limit. And winsock used in AsyncSelect mode, which I described above, uses the message queue which also has no limit. The MsgWaitForMultipleEx does not use any event handles, you can wait on a single handle, your own process handle which never signals to yourself, and let the APC complete the file I/O and the message queue receive winsock events. With win95, you use SleepEx with a wait time of zero to allow the APC to complete any outstanding file I/O notifications and can setup a timer, or other method, to periodically break your message loop and trigger more SleepEx's. If, instead, you open separate threads for each operation to do the work then you increase the resource usage dramatically. Plus you have the same problem with synchronisation, you still need to send notifications back to your main thread anyway.
|
|||
18 Jul 2010, 01:27 |
|
Tyler 18 Jul 2010, 02:32
AFAIK, MS always aligns those values on powers of 2 boundaries, so adding is fine.
|
|||
18 Jul 2010, 02:32 |
|
b1528932 18 Jul 2010, 12:51
revolution wrote: BTW: You are incorrect about the 63 operation limit. With overlapped I/O the file system uses the APC which has no limit. And winsock used in AsyncSelect mode, which I described above, uses the message queue which also has no limit. The MsgWaitForMultipleEx does not use any event handles, you can wait on a single handle, your own process handle which never signals to yourself, and let the APC complete the file I/O and the message queue receive winsock events. With win95, you use SleepEx with a wait time of zero to allow the APC to complete any outstanding file I/O notifications and can setup a timer, or other method, to periodically break your message loop and trigger more SleepEx's. If, instead, you open separate threads for each operation to do the work then you increase the resource usage dramatically. Plus you have the same problem with synchronisation, you still need to send notifications back to your main thread anyway. apc and event are diffrent ways of doing this. i wont use apc, because it will deadlock my thread (if i queue apc inside apc, when apc return it will run again instead of code in main thread). And deviceiocontrol cant be done in apc way, so it suck. waitformultipleobjects has a limit of 63 handles, so it can be used on client, but is unacceptable for server. the perfect solution is io completion port. if not avaiable, i can use other methods, like waitformultiple, sleepex, or even threads if os doesnt support anything more. i have to check whats avaiable on windows 95 and 3.11, and then create universal framework for any app i will ever want to write, so i have to care about code. |
|||
18 Jul 2010, 12:51 |
|
f0dder 19 Jul 2010, 07:42
Tyler wrote: AFAIK, MS always aligns those values on powers of 2 boundaries, so adding is fine. revolution: ugh, WSAAsyncSelect? - that's only really suitable for very low-traffic applications. b1528932 wrote: WaitForMultiple - limit 63 handles, each requiring event object. Events are not cheap. So only 63 operations could execute simultaniusly, no matter what - suck. Yup, it requires more processing than IOCP, but it works pretty well in practice - I think most people will agree that µtorrent isn't a bad resource hog |
|||
19 Jul 2010, 07:42 |
|
revolution 19 Jul 2010, 08:48
f0dder wrote: revolution: ugh, WSAAsyncSelect? - that's only really suitable for very low-traffic applications. Actually I've always preferred queues to events. Multiple event detection is always tricky to code efficiently, but queues are simple to understand and code. I can't see the advantage of events, the work still needs to be done whether it comes from a queue or an event. There is no shortcut to reduce the CPU usage. |
|||
19 Jul 2010, 08:48 |
|
rugxulo 19 Jul 2010, 11:08
revolution wrote: So far no problem in single threaded mode. Usually ~80% CPU usage and the UI is nicely responsive. And that is on a slow P4. Kids today. |
|||
19 Jul 2010, 11:08 |
|
revolution 19 Jul 2010, 11:21
rugxulo wrote:
|
|||
19 Jul 2010, 11:21 |
|
f0dder 19 Jul 2010, 12:22
revolution wrote:
revolution wrote: I can't see the advantage of events, the work still needs to be done whether it comes from a queue or an event. There is no shortcut to reduce the CPU usage. _________________ - carpe noctem |
|||
19 Jul 2010, 12:22 |
|
b1528932 19 Jul 2010, 14:58
wsaeventselect require 1 event for everything.
only issue here is calling WSAEnumNetworkEvents for every single socket in my thread. so if i have milion clients and 1 of them sends data, i have to loop milion tmies calling WSAEnumNetworkEvents. wsaasyncselect - i have to call WSAEnumNetworkEvents, check if msg is real, and do other securoty checks. same as event version, and data are unreliable, because user might just use postmessage to send me his own data. |
|||
19 Jul 2010, 14:58 |
|
revolution 19 Jul 2010, 15:12
b1528932 wrote: and data are unreliable, because user might just use postmessage to send me his own data. |
|||
19 Jul 2010, 15:12 |
|
b1528932 19 Jul 2010, 15:17
Quote: Why is your code fighting the user? You appear to be treating the user as a hostile element. user can have access only to desktop on wich i have this queue. and if it does, it can compromise my app if i dont do error checks. using PostMessage is 100% legal, and writing memory is illegal, so if user will behave in documented way, it will crach my app. if i use event version - he can set event ofc, but when i check for events and dont find any i just do nothing. async version doesnt have that capability, and even if it does - its less efficiend because information passed to me in wparam/lparam are useless. when user has access to desktop, i maybe dont want do give him access to socket and my code. using async version is just wrong. |
|||
19 Jul 2010, 15:17 |
|
revolution 19 Jul 2010, 15:23
b1528932 wrote:
b1528932 wrote: using async version is just wrong. But I still don't understand your query here. What do you need help with? Is there something not working that you need to fix? |
|||
19 Jul 2010, 15:23 |
|
revolution 19 Jul 2010, 15:29
f0dder wrote: A quick google turned up this post. |
|||
19 Jul 2010, 15:29 |
|
f0dder 19 Jul 2010, 16:00
b1528932 wrote: wsaeventselect require 1 event for everything. revolution wrote: Interesting. I've never had the need for so many connections. But their data rates are shockingly low. I wonder what packet size they were using? There appears to be a lot of overhead (or something) sucking up the theoretical 100Mb bandwidth. _________________ - carpe noctem |
|||
19 Jul 2010, 16:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.