~vishvananda/nova/network-refactor

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/internet/iocpreactor/iocpsupport/connectex.pxi

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2008 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
 
 
5
def connect(long s, object addr, object obj):
 
6
    cdef int family, rc
 
7
    cdef myOVERLAPPED *ov
 
8
    cdef sockaddr name
 
9
 
 
10
    if not have_connectex:
 
11
        raise ValueError, 'ConnectEx is not available on this system'
 
12
 
 
13
    family = getAddrFamily(s)
 
14
    if family == AF_INET:
 
15
        fillinetaddr(<sockaddr_in *>&name, addr)
 
16
    else:
 
17
        raise ValueError, 'unsupported address family'
 
18
    name.sa_family = family
 
19
 
 
20
    ov = makeOV()
 
21
    if obj is not None:
 
22
        ov.obj = <PyObject *>obj
 
23
 
 
24
    rc = lpConnectEx(s, &name, sizeof(name), NULL, 0, NULL, <OVERLAPPED *>ov)
 
25
 
 
26
    if not rc:
 
27
        rc = WSAGetLastError()
 
28
        if rc != ERROR_IO_PENDING:
 
29
            return rc
 
30
 
 
31
    # operation is in progress
 
32
    Py_XINCREF(obj)
 
33
    return rc
 
34