Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / iocpreactor / iocpsupport / wsasend.pxi
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4
5 def send(long s, object buff, object obj, unsigned long flags = 0):
6     cdef int rc
7     cdef myOVERLAPPED *ov
8     cdef WSABUF ws_buf
9     cdef unsigned long bytes
10     cdef Py_ssize_t size
11
12     PyObject_AsReadBuffer(buff, <void **>&ws_buf.buf, &size)
13     ws_buf.len = <DWORD>size
14
15     ov = makeOV()
16     if obj is not None:
17         ov.obj = <PyObject *>obj
18
19     rc = WSASend(s, &ws_buf, 1, &bytes, flags, <OVERLAPPED *>ov, NULL)
20
21     if rc == SOCKET_ERROR:
22         rc = WSAGetLastError()
23         if rc != ERROR_IO_PENDING:
24             PyMem_Free(ov)
25             return rc, bytes
26
27     Py_XINCREF(obj)
28     return rc, bytes
29
30