aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/iocpreactor/iocpsupport/wsasend.pxi
blob: 4ad59ca8bd9fb93e9b4f2f614ba3ef6b703f4229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


def send(long s, object buff, object obj, unsigned long flags = 0):
    cdef int rc
    cdef myOVERLAPPED *ov
    cdef WSABUF ws_buf
    cdef unsigned long bytes
    cdef Py_ssize_t size

    PyObject_AsReadBuffer(buff, <void **>&ws_buf.buf, &size)
    ws_buf.len = <DWORD>size

    ov = makeOV()
    if obj is not None:
        ov.obj = <PyObject *>obj

    rc = WSASend(s, &ws_buf, 1, &bytes, flags, <OVERLAPPED *>ov, NULL)

    if rc == SOCKET_ERROR:
        rc = WSAGetLastError()
        if rc != ERROR_IO_PENDING:
            PyMem_Free(ov)
            return rc, bytes

    Py_XINCREF(obj)
    return rc, bytes