Where is WSAEnumNetworkEvents???
Thomas Heller
theller at python.net
Thu Feb 3 12:51:51 EST 2005
Dave Brueck <dave at pythonapocrypha.com> writes:
> elbertlev at 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
More information about the Python-list
mailing list