Where is WSAEnumNetworkEvents???

E

elbertlev

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?
 
R

Roger Upole

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
 
D

Dave Brueck

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
 
T

Thomas Heller

Dave Brueck said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,729
Latest member
taulaju99

Latest Threads

Top