#83 win32file.ConnectEx patch

closed-fixed
nobody
None
5
2009-02-07
2008-04-08
ionel
No

A patch for ConnectEx.

called as follows:
win32file.ConnectEx(sock, (host, port), overlappedobj [, bufferobj])

here's an example:
import socket, win32file, pywintypes
s = socket.socket()
ol = pywintypes.OVERLAPPED()
s.bind(('0.0.0.0', 0)) # connectex requires the socket be bound beforehand

print win32file.ConnectEx(s, ("google.com", 80), ol, "GET / HTTP/1.1\r\n\r\n")
print win32file.GetOverlappedResult(s.fileno(), ol, 1)
ol = pywintypes.OVERLAPPED()
buff = win32file.AllocateReadBuffer(20480)
print win32file.WSARecv(s, buff, ol, 0)
print win32file.GetOverlappedResult(s.fileno(), ol, 1)
print buff

I've tested this on win xp.
I use getaddrinfo to process the (host, port) tuple.

Please review.

Discussion

  • ionel

    ionel - 2008-04-08

    patch for win32file.i

     
  • ionel

    ionel - 2008-04-24

    second version

     
  • ionel

    ionel - 2008-04-24

    Logged In: YES
    user_id=1189761
    Originator: YES

    ok i've made some changes:
    i've moved the wsaioctl in the function body
    - the msdn docs didn't say if the pointer i'm getting is always the same
    - wsaioctl requires a wsainit before, i feel win32file is the wrong place to do that and i don't want to force users to import the socket module (for wsainit) before win32file
    still looking for some feedback on this one though.

    i've changed the buffer handling parts to use the 'buffer api'

    File Added: win32file.i-3.patch

     
  • ionel

    ionel - 2008-04-24

    Logged In: YES
    user_id=1189761
    Originator: YES

    ok i've made some changes:
    i've moved the wsaioctl in the function body
    - the msdn docs didn't say if the pointer i'm getting is always the same
    - wsaioctl requires a wsainit before, i feel win32file is the wrong place to do that and i don't want to force users to import the socket module (for wsainit) before win32file
    still looking for some feedback on this one though.

    i've changed the buffer handling parts to use the 'buffer api'

    File Added: win32file.i-3.patch

     
  • ionel

    ionel - 2008-04-24

    second version

     
  • ionel

    ionel - 2008-04-24

    Logged In: YES
    user_id=1189761
    Originator: YES

    wops, forgot something
    File Added: win32file.i-4.patch

     
  • ionel

    ionel - 2008-04-24
     
  • ionel

    ionel - 2008-04-24

    Logged In: YES
    user_id=1189761
    Originator: YES

    wops, forgot something
    File Added: win32file.i-4.patch

     
  • ionel

    ionel - 2008-04-24
     
  • Mark Hammond

    Mark Hammond - 2008-05-05

    Logged In: YES
    user_id=14198
    Originator: NO

    This looks pretty good. I'd probably prefer for getaddrinfo() to be called by the user of this function, and the necessary info passed in - is there a reason not to do that? Also, would you be so kind as to add something to the win32\test directory (and maybe even the win32\Demos directory :) that covers this?

    Thanks!

     
  • ionel

    ionel - 2008-05-09
     
  • ionel

    ionel - 2008-05-09

    Logged In: YES
    user_id=1189761
    Originator: YES

    File Added: test_connectex.py

     
  • ionel

    ionel - 2008-05-09

    Logged In: YES
    user_id=1189761
    Originator: YES

    To be completely honest I don't really know how to use the tuples returned from the socket.getaddrinfo - since they are very far from the C addrinfo struct I need to use in the ConnectEx call, also, i don't think the python function call overhead to get that addrinfo and make whatever conversions back to the struct is worth it.

    I would add some sort of demo but i need some suggestions (it seems I lack imagination right now).

    I don't cover the corner cases (like bad params) in the test_connectex.

     
  • Mark Hammond

    Mark Hammond - 2009-02-07

    Roger has this in his py3k branch so its now merged to the trunk - thanks for your patience.

     
  • Mark Hammond

    Mark Hammond - 2009-02-07
    • status: open --> closed-fixed
     
  • Mark Hammond

    Mark Hammond - 2009-02-07

    Roger has this in his py3k branch so its now merged to the trunk - thanks for your patience.

     
  • ionel

    ionel - 2009-02-07

    this patch is included in #1962146 (the TransmitFile + ConnectEx patch) and that was applied

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks