niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
Where is WSAEnumNetworkEvents???
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Thomas Heller
*nix forums Guru Wannabe


Joined: 23 Feb 2005
Posts: 179

PostPosted: Thu Feb 03, 2005 4:51 pm    Post subject: Re: Where is WSAEnumNetworkEvents??? Reply with quote

Dave Brueck <dave@pythonapocrypha.com> writes:

Quote:
elbertlev@hotmail.com wrote:
I was trying to write an asyncronous TCP server for win32 using
WSAEventSelect (which lives if win32file). Such events require
WaitForMultipleObjects (which lives if win32event) and
WSAEnumNetworkEvents WHICH IS NOT EXPOSED. This makes WSAEventSelect
useless. Does somebody know how to add the WSAEnumNetworkEvents and
WSANetwotkEvents structure win32file?
Maybe I'm missing something?

You could both build the structures and call the functions in ctypes
(http://starship.python.net/crew/theller/ctypes/)

[untested code follows]

from ctypes import *
class WSANETWORKEVENTS(Structure):
_fields_ = [('lNetworkEvents', c_long),
('iErrorCode', c_int * 10) # 10 = FD_MAX_EVENTS
]

You'd access the API via windll.ws2_32.WSAEnumNetworkEvents, e.g.

networkEvents = WSANETWORKEVENTS()
i = windll.ws2_32.WSAEnumNetworkEvents(s, hEventObject, byref(networkEvents))
if i != 0:
# Handle an error

Yes. And the day is not too far away (hopefully), that you'll be able to
generate the wrapper code automatically:

<snip>
c:\sf\ctypes\sandbox\tools\codegen>h2xml winsock2.h -o winsock2.xml -q
skipped #define SNDMSG ::SendMessage FunctionType
c:\sf\ctypes\sandbox\tools\codegen>xml2py winsock2.xml -q -w -d -s WSAEnumNetworkEvents
# generated by 'xml2py'
# flags 'winsock2.xml -w -d -s WSAEnumNetworkEvents'
from ctypes import *
from ctypes import decorators

class _WSANETWORKEVENTS(Structure):
# C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/winsock2.h 1041
pass
ws2_32 = CDLL('ws2_32')

@ decorators.stdcall(c_int, ws2_32, [c_uint, c_void_p, POINTER(_WSANETWORKEVENTS)])
def WSAEnumNetworkEvents(p1, p2, p3):
# C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/winsock2.h 2706
return WSAEnumNetworkEvents._api_(p1, p2, p3)

_WSANETWORKEVENTS._fields_ = [
# C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/winsock2.h 1041
('lNetworkEvents', c_long),
('iErrorCode', c_int * 10),
]
assert sizeof(_WSANETWORKEVENTS) == 44, sizeof(_WSANETWORKEVENTS)
assert alignment(_WSANETWORKEVENTS) == 4, alignment(_WSANETWORKEVENTS)

c:\sf\ctypes\sandbox\tools\codegen>
<snip/>


Thomas
Back to top
Dave Brueck
*nix forums beginner


Joined: 23 Feb 2005
Posts: 49

PostPosted: Thu Feb 03, 2005 2:59 pm    Post subject: Re: Where is WSAEnumNetworkEvents??? Reply with quote

elbertlev@hotmail.com wrote:
Quote:
I was trying to write an asyncronous TCP server for win32 using
WSAEventSelect (which lives if win32file). Such events require
WaitForMultipleObjects (which lives if win32event) and
WSAEnumNetworkEvents WHICH IS NOT EXPOSED. This makes WSAEventSelect
useless. Does somebody know how to add the WSAEnumNetworkEvents and
WSANetwotkEvents structure win32file?

Maybe I'm missing something?

You could both build the structures and call the functions in ctypes
(http://starship.python.net/crew/theller/ctypes/)

[untested code follows]

from ctypes import *
class WSANETWORKEVENTS(Structure):
_fields_ = [('lNetworkEvents', c_long),
('iErrorCode', c_int * 10) # 10 = FD_MAX_EVENTS
]

You'd access the API via windll.ws2_32.WSAEnumNetworkEvents, e.g.

networkEvents = WSANETWORKEVENTS()
i = windll.ws2_32.WSAEnumNetworkEvents(s, hEventObject, byref(networkEvents))
if i != 0:
# Handle an error

HTH,
Dave
Back to top
Roger Upole
*nix forums Guru Wannabe


Joined: 24 Feb 2005
Posts: 139

PostPosted: Thu Feb 03, 2005 2:32 pm    Post subject: Re: Where is WSAEnumNetworkEvents??? Reply with quote

From a quick look, it wouldn't be too difficult to wrap this function.
Both the input arguments can be already be handled by Swig,
and the outputs would just be an int and a fixed size tuple of ints.

Roger

<elbertlev@hotmail.com> wrote in message
news:1107376894.420724.260230@c13g2000cwb.googlegroups.com...
Quote:
I was trying to write an asyncronous TCP server for win32 using
WSAEventSelect (which lives if win32file). Such events require
WaitForMultipleObjects (which lives if win32event) and
WSAEnumNetworkEvents WHICH IS NOT EXPOSED. This makes WSAEventSelect
useless. Does somebody know how to add the WSAEnumNetworkEvents and
WSANetwotkEvents structure win32file?

Maybe I'm missing something?





----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Back to top
elbertlev@hotmail.com
*nix forums beginner


Joined: 02 Feb 2005
Posts: 16

PostPosted: Wed Feb 02, 2005 7:41 pm    Post subject: Where is WSAEnumNetworkEvents??? Reply with quote

I was trying to write an asyncronous TCP server for win32 using
WSAEventSelect (which lives if win32file). Such events require
WaitForMultipleObjects (which lives if win32event) and
WSAEnumNetworkEvents WHICH IS NOT EXPOSED. This makes WSAEventSelect
useless. Does somebody know how to add the WSAEnumNetworkEvents and
WSANetwotkEvents structure win32file?

Maybe I'm missing something?
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 12:46 am | All times are GMT
navigation Forum index » Programming » python
Jump to:  


Problem Mortgage | Auto Loan | Credit Cards | Just Holden Commodores | Credit Card
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1874s ][ Queries: 15 (0.0820s) ][ GZIP on - Debug on ]