~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

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

  • 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
/* Generated by Pyrex 0.9.6.4 on Tue Mar 18 10:18:51 2008 */
 
2
 
 
3
#define PY_SSIZE_T_CLEAN
 
4
#include "Python.h"
 
5
#include "structmember.h"
 
6
#ifndef PY_LONG_LONG
 
7
  #define PY_LONG_LONG LONG_LONG
 
8
#endif
 
9
#if PY_VERSION_HEX < 0x02050000
 
10
  typedef int Py_ssize_t;
 
11
  #define PY_SSIZE_T_MAX INT_MAX
 
12
  #define PY_SSIZE_T_MIN INT_MIN
 
13
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
 
14
  #define PyInt_AsSsize_t(o)    PyInt_AsLong(o)
 
15
#endif
 
16
#ifndef WIN32
 
17
  #ifndef __stdcall
 
18
    #define __stdcall
 
19
  #endif
 
20
  #ifndef __cdecl
 
21
    #define __cdecl
 
22
  #endif
 
23
#endif
 
24
#ifdef __cplusplus
 
25
#define __PYX_EXTERN_C extern "C"
 
26
#else
 
27
#define __PYX_EXTERN_C extern
 
28
#endif
 
29
#include <math.h>
 
30
#include "io.h"
 
31
#include "errno.h"
 
32
#include "winsock2.h"
 
33
#include "windows.h"
 
34
#include "python.h"
 
35
#include "string.h"
 
36
#include "winsock_pointers.h"
 
37
 
 
38
 
 
39
typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
 
40
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
 
41
 
 
42
static PyObject *__pyx_m;
 
43
static PyObject *__pyx_b;
 
44
static int __pyx_lineno;
 
45
static char *__pyx_filename;
 
46
static char **__pyx_f;
 
47
 
 
48
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
 
49
 
 
50
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[],     Py_ssize_t nargs, PyObject **args2, PyObject **kwds2, char rqd_kwds[]); /*proto*/
 
51
 
 
52
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
 
53
 
 
54
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
 
55
 
 
56
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
 
57
 
 
58
static PyObject *__Pyx_UnpackItem(PyObject *); /*proto*/
 
59
static int __Pyx_EndUnpack(PyObject *); /*proto*/
 
60
 
 
61
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
 
62
 
 
63
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
 
64
 
 
65
static void __Pyx_AddTraceback(char *funcname); /*proto*/
 
66
 
 
67
/* Declarations from iocpsupport */
 
68
 
 
69
typedef int __pyx_t_11iocpsupport_size_t;
 
70
 
 
71
typedef unsigned long __pyx_t_11iocpsupport_HANDLE;
 
72
 
 
73
typedef unsigned long __pyx_t_11iocpsupport_SOCKET;
 
74
 
 
75
typedef unsigned long __pyx_t_11iocpsupport_DWORD;
 
76
 
 
77
typedef unsigned long __pyx_t_11iocpsupport_ULONG_PTR;
 
78
 
 
79
typedef int __pyx_t_11iocpsupport_BOOL;
 
80
 
 
81
struct __pyx_t_11iocpsupport_myOVERLAPPED {
 
82
  OVERLAPPED ov;
 
83
  struct PyObject *obj;
 
84
};
 
85
 
 
86
struct __pyx_obj_11iocpsupport_CompletionPort {
 
87
  PyObject_HEAD
 
88
  __pyx_t_11iocpsupport_HANDLE port;
 
89
};
 
90
 
 
91
 
 
92
static PyTypeObject *__pyx_ptype_11iocpsupport_CompletionPort = 0;
 
93
static long __pyx_k2;
 
94
static unsigned long __pyx_k5;
 
95
static unsigned long __pyx_k6;
 
96
static unsigned long __pyx_k7;
 
97
static struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_f_11iocpsupport_makeOV(void); /*proto*/
 
98
static void __pyx_f_11iocpsupport_raise_error(int,PyObject *); /*proto*/
 
99
static PyObject *__pyx_f_11iocpsupport__makesockaddr(struct sockaddr *,int); /*proto*/
 
100
static PyObject *__pyx_f_11iocpsupport_fillinetaddr(struct sockaddr_in *,PyObject *); /*proto*/
 
101
static int __pyx_f_11iocpsupport_getAddrFamily(__pyx_t_11iocpsupport_SOCKET); /*proto*/
 
102
 
 
103
 
 
104
/* Implementation of iocpsupport */
 
105
 
 
106
static char __pyx_k4[] = "Failed to initialize Winsock function vectors";
 
107
 
 
108
static PyObject *__pyx_n_Event;
 
109
static PyObject *__pyx_n___init__;
 
110
static PyObject *__pyx_n_socket;
 
111
static PyObject *__pyx_n_ValueError;
 
112
static PyObject *__pyx_n_have_connectex;
 
113
 
 
114
static PyObject *__pyx_k4p;
 
115
 
 
116
static PyObject *__pyx_n_MemoryError;
 
117
 
 
118
static struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_f_11iocpsupport_makeOV(void) {
 
119
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_res;
 
120
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_r;
 
121
  void *__pyx_1;
 
122
  int __pyx_2;
 
123
  PyObject *__pyx_3 = 0;
 
124
 
 
125
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":110 */
 
126
  __pyx_1 = PyMem_Malloc((sizeof(struct __pyx_t_11iocpsupport_myOVERLAPPED))); if (__pyx_1 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
 
127
  __pyx_v_res = ((struct __pyx_t_11iocpsupport_myOVERLAPPED *)__pyx_1);
 
128
 
 
129
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":111 */
 
130
  __pyx_2 = (!(__pyx_v_res != 0));
 
131
  if (__pyx_2) {
 
132
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_MemoryError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
 
133
    __Pyx_Raise(__pyx_3, 0, 0);
 
134
    Py_DECREF(__pyx_3); __pyx_3 = 0;
 
135
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
 
136
    goto __pyx_L2;
 
137
  }
 
138
  __pyx_L2:;
 
139
 
 
140
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":113 */
 
141
  memset(__pyx_v_res,0,(sizeof(struct __pyx_t_11iocpsupport_myOVERLAPPED)));
 
142
 
 
143
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":114 */
 
144
  __pyx_r = __pyx_v_res;
 
145
  goto __pyx_L0;
 
146
 
 
147
  __pyx_r = 0;
 
148
  goto __pyx_L0;
 
149
  __pyx_L1:;
 
150
  Py_XDECREF(__pyx_3);
 
151
  __Pyx_AddTraceback("iocpsupport.makeOV");
 
152
  __pyx_r = NULL;
 
153
  __pyx_L0:;
 
154
  return __pyx_r;
 
155
}
 
156
 
 
157
static PyObject *__pyx_n_WindowsError;
 
158
 
 
159
static void __pyx_f_11iocpsupport_raise_error(int __pyx_v_err,PyObject *__pyx_v_message) {
 
160
  int __pyx_1;
 
161
  PyObject *__pyx_2 = 0;
 
162
  PyObject *__pyx_3 = 0;
 
163
  PyObject *__pyx_4 = 0;
 
164
  Py_INCREF(__pyx_v_message);
 
165
 
 
166
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":117 */
 
167
  __pyx_1 = (!__pyx_v_err);
 
168
  if (__pyx_1) {
 
169
    __pyx_v_err = GetLastError();
 
170
    goto __pyx_L2;
 
171
  }
 
172
  __pyx_L2:;
 
173
 
 
174
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":119 */
 
175
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_WindowsError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
 
176
  __pyx_3 = PyInt_FromLong(__pyx_v_err); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
 
177
  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
 
178
  Py_INCREF(__pyx_v_message);
 
179
  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_message);
 
180
  PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
 
181
  __pyx_3 = 0;
 
182
  __pyx_3 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
 
183
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
184
  Py_DECREF(__pyx_4); __pyx_4 = 0;
 
185
  __Pyx_Raise(__pyx_3, 0, 0);
 
186
  Py_DECREF(__pyx_3); __pyx_3 = 0;
 
187
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
 
188
 
 
189
  goto __pyx_L0;
 
190
  __pyx_L1:;
 
191
  Py_XDECREF(__pyx_2);
 
192
  Py_XDECREF(__pyx_3);
 
193
  Py_XDECREF(__pyx_4);
 
194
  __Pyx_AddTraceback("iocpsupport.raise_error");
 
195
  __pyx_L0:;
 
196
  Py_DECREF(__pyx_v_message);
 
197
}
 
198
 
 
199
static PyObject *__pyx_n_callback;
 
200
static PyObject *__pyx_n_owner;
 
201
static PyObject *__pyx_n_False;
 
202
static PyObject *__pyx_n_ignore;
 
203
static PyObject *__pyx_n_items;
 
204
 
 
205
static PyObject *__pyx_f_11iocpsupport_5Event___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
206
static PyMethodDef __pyx_mdef_11iocpsupport_5Event___init__ = {"__init__", (PyCFunction)__pyx_f_11iocpsupport_5Event___init__, METH_VARARGS|METH_KEYWORDS, 0};
 
207
static PyObject *__pyx_f_11iocpsupport_5Event___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
208
  PyObject *__pyx_v_self = 0;
 
209
  PyObject *__pyx_v_callback = 0;
 
210
  PyObject *__pyx_v_owner = 0;
 
211
  PyObject *__pyx_v_kw = 0;
 
212
  PyObject *__pyx_v_k;
 
213
  PyObject *__pyx_v_v;
 
214
  PyObject *__pyx_r;
 
215
  PyObject *__pyx_1 = 0;
 
216
  PyObject *__pyx_2 = 0;
 
217
  PyObject *__pyx_3 = 0;
 
218
  int __pyx_4;
 
219
  static char *__pyx_argnames[] = {"self","callback","owner",0};
 
220
  if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 3, 0, &__pyx_v_kw, 0) < 0) return 0;
 
221
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_self, &__pyx_v_callback, &__pyx_v_owner)) {
 
222
    Py_XDECREF(__pyx_args);
 
223
    Py_XDECREF(__pyx_kwds);
 
224
    Py_XDECREF(__pyx_v_kw);
 
225
    return 0;
 
226
  }
 
227
  Py_INCREF(__pyx_v_self);
 
228
  Py_INCREF(__pyx_v_callback);
 
229
  Py_INCREF(__pyx_v_owner);
 
230
  __pyx_v_k = Py_None; Py_INCREF(Py_None);
 
231
  __pyx_v_v = Py_None; Py_INCREF(Py_None);
 
232
 
 
233
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":123 */
 
234
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_callback, __pyx_v_callback) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
 
235
 
 
236
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":124 */
 
237
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_owner, __pyx_v_owner) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; goto __pyx_L1;}
 
238
 
 
239
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":125 */
 
240
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
 
241
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_ignore, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
 
242
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
243
 
 
244
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":126 */
 
245
  __pyx_1 = PyObject_GetAttr(__pyx_v_kw, __pyx_n_items); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
246
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
247
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
248
  __pyx_1 = PyObject_GetIter(__pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
249
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
250
  for (;;) {
 
251
    __pyx_2 = PyIter_Next(__pyx_1);
 
252
    if (!__pyx_2) {
 
253
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
254
      break;
 
255
    }
 
256
    __pyx_3 = PyObject_GetIter(__pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
257
    Py_DECREF(__pyx_2); __pyx_2 = 0;
 
258
    __pyx_2 = __Pyx_UnpackItem(__pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
259
    Py_DECREF(__pyx_v_k);
 
260
    __pyx_v_k = __pyx_2;
 
261
    __pyx_2 = 0;
 
262
    __pyx_2 = __Pyx_UnpackItem(__pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
263
    Py_DECREF(__pyx_v_v);
 
264
    __pyx_v_v = __pyx_2;
 
265
    __pyx_2 = 0;
 
266
    if (__Pyx_EndUnpack(__pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
 
267
    Py_DECREF(__pyx_3); __pyx_3 = 0;
 
268
    __pyx_4 = PyObject_SetAttr(__pyx_v_self,__pyx_v_k,__pyx_v_v); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
 
269
  }
 
270
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
271
 
 
272
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
273
  goto __pyx_L0;
 
274
  __pyx_L1:;
 
275
  Py_XDECREF(__pyx_1);
 
276
  Py_XDECREF(__pyx_2);
 
277
  Py_XDECREF(__pyx_3);
 
278
  __Pyx_AddTraceback("iocpsupport.Event.__init__");
 
279
  __pyx_r = 0;
 
280
  __pyx_L0:;
 
281
  Py_XDECREF(__pyx_v_kw);
 
282
  Py_DECREF(__pyx_v_k);
 
283
  Py_DECREF(__pyx_v_v);
 
284
  Py_DECREF(__pyx_v_self);
 
285
  Py_DECREF(__pyx_v_callback);
 
286
  Py_DECREF(__pyx_v_owner);
 
287
  Py_XDECREF(__pyx_args);
 
288
  Py_XDECREF(__pyx_kwds);
 
289
  return __pyx_r;
 
290
}
 
291
 
 
292
static PyObject *__pyx_n_CreateIoCompletionPort;
 
293
 
 
294
 
 
295
static int __pyx_f_11iocpsupport_14CompletionPort___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
296
static int __pyx_f_11iocpsupport_14CompletionPort___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
297
  __pyx_t_11iocpsupport_HANDLE __pyx_v_res;
 
298
  int __pyx_r;
 
299
  int __pyx_1;
 
300
  static char *__pyx_argnames[] = {0};
 
301
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return -1;
 
302
  Py_INCREF(__pyx_v_self);
 
303
 
 
304
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":133 */
 
305
  __pyx_v_res = CreateIoCompletionPort(INVALID_HANDLE_VALUE,0,0,0);
 
306
 
 
307
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":134 */
 
308
  __pyx_1 = (!__pyx_v_res);
 
309
  if (__pyx_1) {
 
310
    __pyx_f_11iocpsupport_raise_error(0,__pyx_n_CreateIoCompletionPort); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; goto __pyx_L1;}
 
311
    goto __pyx_L2;
 
312
  }
 
313
  __pyx_L2:;
 
314
 
 
315
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":136 */
 
316
  ((struct __pyx_obj_11iocpsupport_CompletionPort *)__pyx_v_self)->port = __pyx_v_res;
 
317
 
 
318
  __pyx_r = 0;
 
319
  goto __pyx_L0;
 
320
  __pyx_L1:;
 
321
  __Pyx_AddTraceback("iocpsupport.CompletionPort.__init__");
 
322
  __pyx_r = -1;
 
323
  __pyx_L0:;
 
324
  Py_DECREF(__pyx_v_self);
 
325
  return __pyx_r;
 
326
}
 
327
 
 
328
 
 
329
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_addHandle(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
330
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_addHandle(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
331
  long __pyx_v_handle;
 
332
  long __pyx_v_key;
 
333
  __pyx_t_11iocpsupport_HANDLE __pyx_v_res;
 
334
  PyObject *__pyx_r;
 
335
  int __pyx_1;
 
336
  static char *__pyx_argnames[] = {"handle","key",0};
 
337
  __pyx_v_key = __pyx_k2;
 
338
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "l|l", __pyx_argnames, &__pyx_v_handle, &__pyx_v_key)) return 0;
 
339
  Py_INCREF(__pyx_v_self);
 
340
 
 
341
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":140 */
 
342
  __pyx_v_res = CreateIoCompletionPort(__pyx_v_handle,((struct __pyx_obj_11iocpsupport_CompletionPort *)__pyx_v_self)->port,__pyx_v_key,0);
 
343
 
 
344
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":141 */
 
345
  __pyx_1 = (!__pyx_v_res);
 
346
  if (__pyx_1) {
 
347
    __pyx_f_11iocpsupport_raise_error(0,__pyx_n_CreateIoCompletionPort); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;}
 
348
    goto __pyx_L2;
 
349
  }
 
350
  __pyx_L2:;
 
351
 
 
352
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
353
  goto __pyx_L0;
 
354
  __pyx_L1:;
 
355
  __Pyx_AddTraceback("iocpsupport.CompletionPort.addHandle");
 
356
  __pyx_r = 0;
 
357
  __pyx_L0:;
 
358
  Py_DECREF(__pyx_v_self);
 
359
  return __pyx_r;
 
360
}
 
361
 
 
362
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_getEvent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
363
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_getEvent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
364
  long __pyx_v_timeout;
 
365
  struct PyThreadState *__pyx_v__save;
 
366
  unsigned long __pyx_v_bytes;
 
367
  unsigned long __pyx_v_key;
 
368
  unsigned long __pyx_v_rc;
 
369
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
370
  PyObject *__pyx_v_obj;
 
371
  PyObject *__pyx_r;
 
372
  int __pyx_1;
 
373
  PyObject *__pyx_2 = 0;
 
374
  PyObject *__pyx_3 = 0;
 
375
  PyObject *__pyx_4 = 0;
 
376
  PyObject *__pyx_5 = 0;
 
377
  static char *__pyx_argnames[] = {"timeout",0};
 
378
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "l", __pyx_argnames, &__pyx_v_timeout)) return 0;
 
379
  Py_INCREF(__pyx_v_self);
 
380
  __pyx_v_obj = Py_None; Py_INCREF(Py_None);
 
381
 
 
382
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":149 */
 
383
  __pyx_v__save = PyEval_SaveThread();
 
384
 
 
385
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":150 */
 
386
  __pyx_v_rc = GetQueuedCompletionStatus(((struct __pyx_obj_11iocpsupport_CompletionPort *)__pyx_v_self)->port,(&__pyx_v_bytes),(&__pyx_v_key),((OVERLAPPED **)(&__pyx_v_ov)),__pyx_v_timeout);
 
387
 
 
388
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":151 */
 
389
  PyEval_RestoreThread(__pyx_v__save);
 
390
 
 
391
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":153 */
 
392
  __pyx_1 = (!__pyx_v_rc);
 
393
  if (__pyx_1) {
 
394
    __pyx_v_rc = GetLastError();
 
395
    goto __pyx_L2;
 
396
  }
 
397
  /*else*/ {
 
398
    __pyx_v_rc = 0;
 
399
  }
 
400
  __pyx_L2:;
 
401
 
 
402
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":158 */
 
403
  Py_INCREF(Py_None);
 
404
  Py_DECREF(__pyx_v_obj);
 
405
  __pyx_v_obj = Py_None;
 
406
 
 
407
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":159 */
 
408
  __pyx_1 = (__pyx_v_ov != 0);
 
409
  if (__pyx_1) {
 
410
 
 
411
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":160 */
 
412
    __pyx_1 = (__pyx_v_ov->obj != 0);
 
413
    if (__pyx_1) {
 
414
 
 
415
      /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":161 */
 
416
      __pyx_2 = (PyObject *)__pyx_v_ov->obj;
 
417
      Py_INCREF(__pyx_2);
 
418
      Py_DECREF(__pyx_v_obj);
 
419
      __pyx_v_obj = __pyx_2;
 
420
      __pyx_2 = 0;
 
421
 
 
422
      /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":162 */
 
423
      Py_DECREF(__pyx_v_obj);
 
424
      goto __pyx_L4;
 
425
    }
 
426
    __pyx_L4:;
 
427
 
 
428
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":163 */
 
429
    PyMem_Free(__pyx_v_ov);
 
430
    goto __pyx_L3;
 
431
  }
 
432
  __pyx_L3:;
 
433
 
 
434
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":165 */
 
435
  __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_rc); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; goto __pyx_L1;}
 
436
  __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_bytes); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; goto __pyx_L1;}
 
437
  __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_key); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; goto __pyx_L1;}
 
438
  __pyx_5 = PyTuple_New(4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; goto __pyx_L1;}
 
439
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
 
440
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
 
441
  PyTuple_SET_ITEM(__pyx_5, 2, __pyx_4);
 
442
  Py_INCREF(__pyx_v_obj);
 
443
  PyTuple_SET_ITEM(__pyx_5, 3, __pyx_v_obj);
 
444
  __pyx_2 = 0;
 
445
  __pyx_3 = 0;
 
446
  __pyx_4 = 0;
 
447
  __pyx_r = __pyx_5;
 
448
  __pyx_5 = 0;
 
449
  goto __pyx_L0;
 
450
 
 
451
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
452
  goto __pyx_L0;
 
453
  __pyx_L1:;
 
454
  Py_XDECREF(__pyx_2);
 
455
  Py_XDECREF(__pyx_3);
 
456
  Py_XDECREF(__pyx_4);
 
457
  Py_XDECREF(__pyx_5);
 
458
  __Pyx_AddTraceback("iocpsupport.CompletionPort.getEvent");
 
459
  __pyx_r = 0;
 
460
  __pyx_L0:;
 
461
  Py_DECREF(__pyx_v_obj);
 
462
  Py_DECREF(__pyx_v_self);
 
463
  return __pyx_r;
 
464
}
 
465
 
 
466
static PyObject *__pyx_n_PostQueuedCompletionStatus;
 
467
 
 
468
 
 
469
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_postEvent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
470
static PyObject *__pyx_f_11iocpsupport_14CompletionPort_postEvent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
471
  unsigned long __pyx_v_bytes;
 
472
  unsigned long __pyx_v_key;
 
473
  PyObject *__pyx_v_obj = 0;
 
474
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
475
  unsigned long __pyx_v_rc;
 
476
  PyObject *__pyx_r;
 
477
  int __pyx_1;
 
478
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_2;
 
479
  static char *__pyx_argnames[] = {"bytes","key","obj",0};
 
480
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkO", __pyx_argnames, &__pyx_v_bytes, &__pyx_v_key, &__pyx_v_obj)) return 0;
 
481
  Py_INCREF(__pyx_v_self);
 
482
  Py_INCREF(__pyx_v_obj);
 
483
 
 
484
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":171 */
 
485
  __pyx_1 = __pyx_v_obj != Py_None;
 
486
  if (__pyx_1) {
 
487
 
 
488
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":172 */
 
489
    __pyx_2 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; goto __pyx_L1;}
 
490
    __pyx_v_ov = __pyx_2;
 
491
 
 
492
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":173 */
 
493
    Py_INCREF(__pyx_v_obj);
 
494
 
 
495
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":174 */
 
496
    __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
497
    goto __pyx_L2;
 
498
  }
 
499
  /*else*/ {
 
500
    __pyx_v_ov = NULL;
 
501
  }
 
502
  __pyx_L2:;
 
503
 
 
504
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":178 */
 
505
  __pyx_v_rc = PostQueuedCompletionStatus(((struct __pyx_obj_11iocpsupport_CompletionPort *)__pyx_v_self)->port,__pyx_v_bytes,__pyx_v_key,((OVERLAPPED *)__pyx_v_ov));
 
506
 
 
507
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":179 */
 
508
  __pyx_1 = (!__pyx_v_rc);
 
509
  if (__pyx_1) {
 
510
    __pyx_f_11iocpsupport_raise_error(0,__pyx_n_PostQueuedCompletionStatus); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;}
 
511
    goto __pyx_L3;
 
512
  }
 
513
  __pyx_L3:;
 
514
 
 
515
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
516
  goto __pyx_L0;
 
517
  __pyx_L1:;
 
518
  __Pyx_AddTraceback("iocpsupport.CompletionPort.postEvent");
 
519
  __pyx_r = 0;
 
520
  __pyx_L0:;
 
521
  Py_DECREF(__pyx_v_self);
 
522
  Py_DECREF(__pyx_v_obj);
 
523
  return __pyx_r;
 
524
}
 
525
 
 
526
static PyObject *__pyx_f_11iocpsupport_14CompletionPort___del__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
527
static PyObject *__pyx_f_11iocpsupport_14CompletionPort___del__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
528
  PyObject *__pyx_r;
 
529
  static char *__pyx_argnames[] = {0};
 
530
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
 
531
  Py_INCREF(__pyx_v_self);
 
532
  CloseHandle(((struct __pyx_obj_11iocpsupport_CompletionPort *)__pyx_v_self)->port);
 
533
 
 
534
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
535
  Py_DECREF(__pyx_v_self);
 
536
  return __pyx_r;
 
537
}
 
538
 
 
539
static PyObject *__pyx_f_11iocpsupport_makesockaddr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
540
static PyObject *__pyx_f_11iocpsupport_makesockaddr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
541
  PyObject *__pyx_v_buff = 0;
 
542
  void *__pyx_v_mem_buffer;
 
543
  int __pyx_v_size;
 
544
  PyObject *__pyx_r;
 
545
  int __pyx_1;
 
546
  PyObject *__pyx_2 = 0;
 
547
  static char *__pyx_argnames[] = {"buff",0};
 
548
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_buff)) return 0;
 
549
  Py_INCREF(__pyx_v_buff);
 
550
 
 
551
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":189 */
 
552
  __pyx_1 = PyObject_AsReadBuffer(__pyx_v_buff,(&__pyx_v_mem_buffer),(&__pyx_v_size)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; goto __pyx_L1;}
 
553
 
 
554
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":191 */
 
555
  __pyx_2 = __pyx_f_11iocpsupport__makesockaddr(((struct sockaddr *)__pyx_v_mem_buffer),__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
 
556
  __pyx_r = __pyx_2;
 
557
  __pyx_2 = 0;
 
558
  goto __pyx_L0;
 
559
 
 
560
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
561
  goto __pyx_L0;
 
562
  __pyx_L1:;
 
563
  Py_XDECREF(__pyx_2);
 
564
  __Pyx_AddTraceback("iocpsupport.makesockaddr");
 
565
  __pyx_r = 0;
 
566
  __pyx_L0:;
 
567
  Py_DECREF(__pyx_v_buff);
 
568
  return __pyx_r;
 
569
}
 
570
 
 
571
static PyObject *__pyx_f_11iocpsupport__makesockaddr(struct sockaddr *__pyx_v_addr,int __pyx_v_len) {
 
572
  struct sockaddr_in *__pyx_v_sin;
 
573
  PyObject *__pyx_r;
 
574
  int __pyx_1;
 
575
  PyObject *__pyx_2 = 0;
 
576
  PyObject *__pyx_3 = 0;
 
577
  PyObject *__pyx_4 = 0;
 
578
 
 
579
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":195 */
 
580
  __pyx_1 = (!__pyx_v_len);
 
581
  if (__pyx_1) {
 
582
    Py_INCREF(Py_None);
 
583
    __pyx_r = Py_None;
 
584
    goto __pyx_L0;
 
585
    goto __pyx_L2;
 
586
  }
 
587
  __pyx_L2:;
 
588
 
 
589
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":197 */
 
590
  __pyx_1 = (__pyx_v_addr->sa_family == AF_INET);
 
591
  if (__pyx_1) {
 
592
 
 
593
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":198 */
 
594
    __pyx_v_sin = ((struct sockaddr_in *)__pyx_v_addr);
 
595
 
 
596
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":199 */
 
597
    __pyx_2 = PyString_FromString(inet_ntoa(__pyx_v_sin->sin_addr)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
 
598
    __pyx_3 = PyInt_FromLong(ntohs(__pyx_v_sin->sin_port)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
 
599
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
 
600
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
 
601
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
 
602
    __pyx_2 = 0;
 
603
    __pyx_3 = 0;
 
604
    __pyx_r = __pyx_4;
 
605
    __pyx_4 = 0;
 
606
    goto __pyx_L0;
 
607
    goto __pyx_L3;
 
608
  }
 
609
  /*else*/ {
 
610
    __pyx_2 = PyString_FromStringAndSize(__pyx_v_addr->sa_data,(sizeof(__pyx_v_addr->sa_data))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; goto __pyx_L1;}
 
611
    __pyx_r = __pyx_2;
 
612
    __pyx_2 = 0;
 
613
    goto __pyx_L0;
 
614
  }
 
615
  __pyx_L3:;
 
616
 
 
617
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
618
  goto __pyx_L0;
 
619
  __pyx_L1:;
 
620
  Py_XDECREF(__pyx_2);
 
621
  Py_XDECREF(__pyx_3);
 
622
  Py_XDECREF(__pyx_4);
 
623
  __Pyx_AddTraceback("iocpsupport._makesockaddr");
 
624
  __pyx_r = 0;
 
625
  __pyx_L0:;
 
626
  return __pyx_r;
 
627
}
 
628
 
 
629
static PyObject *__pyx_k11p;
 
630
 
 
631
static char __pyx_k11[] = "invalid IP address";
 
632
 
 
633
static PyObject *__pyx_f_11iocpsupport_fillinetaddr(struct sockaddr_in *__pyx_v_dest,PyObject *__pyx_v_addr) {
 
634
  short __pyx_v_port;
 
635
  unsigned long __pyx_v_res;
 
636
  char *__pyx_v_hoststr;
 
637
  PyObject *__pyx_v_host;
 
638
  PyObject *__pyx_r;
 
639
  PyObject *__pyx_1 = 0;
 
640
  PyObject *__pyx_2 = 0;
 
641
  short __pyx_3;
 
642
  char *__pyx_4;
 
643
  int __pyx_5;
 
644
  Py_INCREF(__pyx_v_addr);
 
645
  __pyx_v_host = Py_None; Py_INCREF(Py_None);
 
646
 
 
647
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":207 */
 
648
  __pyx_1 = PyObject_GetIter(__pyx_v_addr); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
 
649
  __pyx_2 = __Pyx_UnpackItem(__pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
 
650
  Py_DECREF(__pyx_v_host);
 
651
  __pyx_v_host = __pyx_2;
 
652
  __pyx_2 = 0;
 
653
  __pyx_2 = __Pyx_UnpackItem(__pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
 
654
  __pyx_3 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
 
655
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
656
  __pyx_v_port = __pyx_3;
 
657
  if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
 
658
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
659
 
 
660
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":209 */
 
661
  __pyx_4 = PyString_AsString(__pyx_v_host); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; goto __pyx_L1;}
 
662
  __pyx_v_hoststr = __pyx_4;
 
663
 
 
664
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":210 */
 
665
  __pyx_v_res = inet_addr(__pyx_v_hoststr);
 
666
 
 
667
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":211 */
 
668
  __pyx_5 = (__pyx_v_res == INADDR_ANY);
 
669
  if (__pyx_5) {
 
670
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
 
671
    __Pyx_Raise(__pyx_2, __pyx_k11p, 0);
 
672
    Py_DECREF(__pyx_2); __pyx_2 = 0;
 
673
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
 
674
    goto __pyx_L2;
 
675
  }
 
676
  __pyx_L2:;
 
677
 
 
678
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":213 */
 
679
  __pyx_v_dest->sin_addr.s_addr = __pyx_v_res;
 
680
 
 
681
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":215 */
 
682
  __pyx_v_dest->sin_port = htons(__pyx_v_port);
 
683
 
 
684
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
685
  goto __pyx_L0;
 
686
  __pyx_L1:;
 
687
  Py_XDECREF(__pyx_1);
 
688
  Py_XDECREF(__pyx_2);
 
689
  __Pyx_AddTraceback("iocpsupport.fillinetaddr");
 
690
  __pyx_r = 0;
 
691
  __pyx_L0:;
 
692
  Py_DECREF(__pyx_v_host);
 
693
  Py_DECREF(__pyx_v_addr);
 
694
  return __pyx_r;
 
695
}
 
696
 
 
697
static PyObject *__pyx_f_11iocpsupport_AllocateReadBuffer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
698
static PyObject *__pyx_f_11iocpsupport_AllocateReadBuffer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
699
  int __pyx_v_size;
 
700
  PyObject *__pyx_r;
 
701
  PyObject *__pyx_1 = 0;
 
702
  static char *__pyx_argnames[] = {"size",0};
 
703
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "i", __pyx_argnames, &__pyx_v_size)) return 0;
 
704
  __pyx_1 = PyBuffer_New(__pyx_v_size); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; goto __pyx_L1;}
 
705
  __pyx_r = __pyx_1;
 
706
  __pyx_1 = 0;
 
707
  goto __pyx_L0;
 
708
 
 
709
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
710
  goto __pyx_L0;
 
711
  __pyx_L1:;
 
712
  Py_XDECREF(__pyx_1);
 
713
  __Pyx_AddTraceback("iocpsupport.AllocateReadBuffer");
 
714
  __pyx_r = 0;
 
715
  __pyx_L0:;
 
716
  return __pyx_r;
 
717
}
 
718
 
 
719
static PyObject *__pyx_n_getsockopt;
 
720
 
 
721
 
 
722
static PyObject *__pyx_f_11iocpsupport_maxAddrLen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
723
static PyObject *__pyx_f_11iocpsupport_maxAddrLen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
724
  long __pyx_v_s;
 
725
  WSAPROTOCOL_INFO __pyx_v_wsa_pi;
 
726
  int __pyx_v_size;
 
727
  int __pyx_v_rc;
 
728
  PyObject *__pyx_r;
 
729
  int __pyx_1;
 
730
  PyObject *__pyx_2 = 0;
 
731
  static char *__pyx_argnames[] = {"s",0};
 
732
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "l", __pyx_argnames, &__pyx_v_s)) return 0;
 
733
 
 
734
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":224 */
 
735
  __pyx_v_size = (sizeof(__pyx_v_wsa_pi));
 
736
 
 
737
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":225 */
 
738
  __pyx_v_rc = getsockopt(__pyx_v_s,SOL_SOCKET,SO_PROTOCOL_INFO,((char *)(&__pyx_v_wsa_pi)),(&__pyx_v_size));
 
739
 
 
740
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":226 */
 
741
  __pyx_1 = (__pyx_v_rc == SOCKET_ERROR);
 
742
  if (__pyx_1) {
 
743
    __pyx_f_11iocpsupport_raise_error(WSAGetLastError(),__pyx_n_getsockopt); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
 
744
    goto __pyx_L2;
 
745
  }
 
746
  __pyx_L2:;
 
747
 
 
748
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":228 */
 
749
  __pyx_2 = PyInt_FromLong(__pyx_v_wsa_pi.iMaxSockAddr); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; goto __pyx_L1;}
 
750
  __pyx_r = __pyx_2;
 
751
  __pyx_2 = 0;
 
752
  goto __pyx_L0;
 
753
 
 
754
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
755
  goto __pyx_L0;
 
756
  __pyx_L1:;
 
757
  Py_XDECREF(__pyx_2);
 
758
  __Pyx_AddTraceback("iocpsupport.maxAddrLen");
 
759
  __pyx_r = 0;
 
760
  __pyx_L0:;
 
761
  return __pyx_r;
 
762
}
 
763
 
 
764
 
 
765
static int __pyx_f_11iocpsupport_getAddrFamily(__pyx_t_11iocpsupport_SOCKET __pyx_v_s) {
 
766
  WSAPROTOCOL_INFO __pyx_v_wsa_pi;
 
767
  int __pyx_v_size;
 
768
  int __pyx_v_rc;
 
769
  int __pyx_r;
 
770
  int __pyx_1;
 
771
 
 
772
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":234 */
 
773
  __pyx_v_size = (sizeof(__pyx_v_wsa_pi));
 
774
 
 
775
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":235 */
 
776
  __pyx_v_rc = getsockopt(__pyx_v_s,SOL_SOCKET,SO_PROTOCOL_INFO,((char *)(&__pyx_v_wsa_pi)),(&__pyx_v_size));
 
777
 
 
778
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":236 */
 
779
  __pyx_1 = (__pyx_v_rc == SOCKET_ERROR);
 
780
  if (__pyx_1) {
 
781
    __pyx_f_11iocpsupport_raise_error(WSAGetLastError(),__pyx_n_getsockopt); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
 
782
    goto __pyx_L2;
 
783
  }
 
784
  __pyx_L2:;
 
785
 
 
786
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":238 */
 
787
  __pyx_r = __pyx_v_wsa_pi.iAddressFamily;
 
788
  goto __pyx_L0;
 
789
 
 
790
  __pyx_r = 0;
 
791
  goto __pyx_L0;
 
792
  __pyx_L1:;
 
793
  __Pyx_AddTraceback("iocpsupport.getAddrFamily");
 
794
  __pyx_L0:;
 
795
  return __pyx_r;
 
796
}
 
797
 
 
798
static PyObject *__pyx_f_11iocpsupport_accept(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
799
static PyObject *__pyx_f_11iocpsupport_accept(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
800
  long __pyx_v_listening;
 
801
  long __pyx_v_accepting;
 
802
  PyObject *__pyx_v_buff = 0;
 
803
  PyObject *__pyx_v_obj = 0;
 
804
  unsigned long __pyx_v_bytes;
 
805
  int __pyx_v_size;
 
806
  int __pyx_v_rc;
 
807
  void *__pyx_v_mem_buffer;
 
808
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
809
  PyObject *__pyx_r;
 
810
  int __pyx_1;
 
811
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_2;
 
812
  PyObject *__pyx_3 = 0;
 
813
  static char *__pyx_argnames[] = {"listening","accepting","buff","obj",0};
 
814
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "llOO", __pyx_argnames, &__pyx_v_listening, &__pyx_v_accepting, &__pyx_v_buff, &__pyx_v_obj)) return 0;
 
815
  Py_INCREF(__pyx_v_buff);
 
816
  Py_INCREF(__pyx_v_obj);
 
817
 
 
818
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":11 */
 
819
  __pyx_1 = PyObject_AsWriteBuffer(__pyx_v_buff,(&__pyx_v_mem_buffer),(&__pyx_v_size)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; goto __pyx_L1;}
 
820
 
 
821
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":13 */
 
822
  __pyx_2 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; goto __pyx_L1;}
 
823
  __pyx_v_ov = __pyx_2;
 
824
 
 
825
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":14 */
 
826
  __pyx_1 = __pyx_v_obj != Py_None;
 
827
  if (__pyx_1) {
 
828
    __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
829
    goto __pyx_L2;
 
830
  }
 
831
  __pyx_L2:;
 
832
 
 
833
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":17 */
 
834
  __pyx_v_rc = lpAcceptEx(__pyx_v_listening,__pyx_v_accepting,__pyx_v_mem_buffer,0,(__pyx_v_size / 2),(__pyx_v_size / 2),(&__pyx_v_bytes),((OVERLAPPED *)__pyx_v_ov));
 
835
 
 
836
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":19 */
 
837
  __pyx_1 = (!__pyx_v_rc);
 
838
  if (__pyx_1) {
 
839
 
 
840
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":20 */
 
841
    __pyx_v_rc = WSAGetLastError();
 
842
 
 
843
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":21 */
 
844
    __pyx_1 = (__pyx_v_rc != ERROR_IO_PENDING);
 
845
    if (__pyx_1) {
 
846
      __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; goto __pyx_L1;}
 
847
      __pyx_r = __pyx_3;
 
848
      __pyx_3 = 0;
 
849
      goto __pyx_L0;
 
850
      goto __pyx_L4;
 
851
    }
 
852
    __pyx_L4:;
 
853
    goto __pyx_L3;
 
854
  }
 
855
  __pyx_L3:;
 
856
 
 
857
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":25 */
 
858
  Py_XINCREF(__pyx_v_obj);
 
859
 
 
860
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":26 */
 
861
  __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; goto __pyx_L1;}
 
862
  __pyx_r = __pyx_3;
 
863
  __pyx_3 = 0;
 
864
  goto __pyx_L0;
 
865
 
 
866
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
867
  goto __pyx_L0;
 
868
  __pyx_L1:;
 
869
  Py_XDECREF(__pyx_3);
 
870
  __Pyx_AddTraceback("iocpsupport.accept");
 
871
  __pyx_r = 0;
 
872
  __pyx_L0:;
 
873
  Py_DECREF(__pyx_v_buff);
 
874
  Py_DECREF(__pyx_v_obj);
 
875
  return __pyx_r;
 
876
}
 
877
 
 
878
static PyObject *__pyx_f_11iocpsupport_get_accept_addrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
879
static PyObject *__pyx_f_11iocpsupport_get_accept_addrs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
880
  long __pyx_v_s;
 
881
  PyObject *__pyx_v_buff = 0;
 
882
  int __pyx_v_size;
 
883
  int __pyx_v_locallen;
 
884
  int __pyx_v_remotelen;
 
885
  void *__pyx_v_mem_buffer;
 
886
  struct sockaddr *__pyx_v_localaddr;
 
887
  struct sockaddr *__pyx_v_remoteaddr;
 
888
  PyObject *__pyx_r;
 
889
  int __pyx_1;
 
890
  PyObject *__pyx_2 = 0;
 
891
  PyObject *__pyx_3 = 0;
 
892
  PyObject *__pyx_4 = 0;
 
893
  PyObject *__pyx_5 = 0;
 
894
  static char *__pyx_argnames[] = {"s","buff",0};
 
895
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "lO", __pyx_argnames, &__pyx_v_s, &__pyx_v_buff)) return 0;
 
896
  Py_INCREF(__pyx_v_buff);
 
897
 
 
898
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":34 */
 
899
  __pyx_1 = PyObject_AsReadBuffer(__pyx_v_buff,(&__pyx_v_mem_buffer),(&__pyx_v_size)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; goto __pyx_L1;}
 
900
 
 
901
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":36 */
 
902
  lpGetAcceptExSockaddrs(__pyx_v_mem_buffer,0,(__pyx_v_size / 2),(__pyx_v_size / 2),(&__pyx_v_localaddr),(&__pyx_v_locallen),(&__pyx_v_remoteaddr),(&__pyx_v_remotelen));
 
903
 
 
904
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\acceptex.pxi":37 */
 
905
  __pyx_2 = PyInt_FromLong(__pyx_v_remoteaddr->sa_family); if (!__pyx_2) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; goto __pyx_L1;}
 
906
  __pyx_3 = __pyx_f_11iocpsupport__makesockaddr(__pyx_v_localaddr,__pyx_v_locallen); if (!__pyx_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; goto __pyx_L1;}
 
907
  __pyx_4 = __pyx_f_11iocpsupport__makesockaddr(__pyx_v_remoteaddr,__pyx_v_remotelen); if (!__pyx_4) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; goto __pyx_L1;}
 
908
  __pyx_5 = PyTuple_New(3); if (!__pyx_5) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; goto __pyx_L1;}
 
909
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
 
910
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
 
911
  PyTuple_SET_ITEM(__pyx_5, 2, __pyx_4);
 
912
  __pyx_2 = 0;
 
913
  __pyx_3 = 0;
 
914
  __pyx_4 = 0;
 
915
  __pyx_r = __pyx_5;
 
916
  __pyx_5 = 0;
 
917
  goto __pyx_L0;
 
918
 
 
919
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
920
  goto __pyx_L0;
 
921
  __pyx_L1:;
 
922
  Py_XDECREF(__pyx_2);
 
923
  Py_XDECREF(__pyx_3);
 
924
  Py_XDECREF(__pyx_4);
 
925
  Py_XDECREF(__pyx_5);
 
926
  __Pyx_AddTraceback("iocpsupport.get_accept_addrs");
 
927
  __pyx_r = 0;
 
928
  __pyx_L0:;
 
929
  Py_DECREF(__pyx_v_buff);
 
930
  return __pyx_r;
 
931
}
 
932
 
 
933
static PyObject *__pyx_k14p;
 
934
static PyObject *__pyx_k15p;
 
935
 
 
936
static char __pyx_k14[] = "ConnectEx is not available on this system";
 
937
static char __pyx_k15[] = "unsupported address family";
 
938
 
 
939
static PyObject *__pyx_f_11iocpsupport_connect(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
940
static PyObject *__pyx_f_11iocpsupport_connect(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
941
  long __pyx_v_s;
 
942
  PyObject *__pyx_v_addr = 0;
 
943
  PyObject *__pyx_v_obj = 0;
 
944
  int __pyx_v_family;
 
945
  int __pyx_v_rc;
 
946
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
947
  struct sockaddr __pyx_v_name;
 
948
  PyObject *__pyx_r;
 
949
  PyObject *__pyx_1 = 0;
 
950
  int __pyx_2;
 
951
  int __pyx_3;
 
952
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_4;
 
953
  static char *__pyx_argnames[] = {"s","addr","obj",0};
 
954
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "lOO", __pyx_argnames, &__pyx_v_s, &__pyx_v_addr, &__pyx_v_obj)) return 0;
 
955
  Py_INCREF(__pyx_v_addr);
 
956
  Py_INCREF(__pyx_v_obj);
 
957
 
 
958
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":10 */
 
959
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_have_connectex); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; goto __pyx_L1;}
 
960
  __pyx_2 = PyObject_IsTrue(__pyx_1); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; goto __pyx_L1;}
 
961
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
962
  __pyx_3 = (!__pyx_2);
 
963
  if (__pyx_3) {
 
964
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; goto __pyx_L1;}
 
965
    __Pyx_Raise(__pyx_1, __pyx_k14p, 0);
 
966
    Py_DECREF(__pyx_1); __pyx_1 = 0;
 
967
    {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; goto __pyx_L1;}
 
968
    goto __pyx_L2;
 
969
  }
 
970
  __pyx_L2:;
 
971
 
 
972
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":13 */
 
973
  __pyx_2 = __pyx_f_11iocpsupport_getAddrFamily(__pyx_v_s); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 13; goto __pyx_L1;}
 
974
  __pyx_v_family = __pyx_2;
 
975
 
 
976
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":14 */
 
977
  __pyx_3 = (__pyx_v_family == AF_INET);
 
978
  if (__pyx_3) {
 
979
    __pyx_1 = __pyx_f_11iocpsupport_fillinetaddr(((struct sockaddr_in *)(&__pyx_v_name)),__pyx_v_addr); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; goto __pyx_L1;}
 
980
    Py_DECREF(__pyx_1); __pyx_1 = 0;
 
981
    goto __pyx_L3;
 
982
  }
 
983
  /*else*/ {
 
984
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; goto __pyx_L1;}
 
985
    __Pyx_Raise(__pyx_1, __pyx_k15p, 0);
 
986
    Py_DECREF(__pyx_1); __pyx_1 = 0;
 
987
    {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; goto __pyx_L1;}
 
988
  }
 
989
  __pyx_L3:;
 
990
 
 
991
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":18 */
 
992
  __pyx_v_name.sa_family = __pyx_v_family;
 
993
 
 
994
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":20 */
 
995
  __pyx_4 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; goto __pyx_L1;}
 
996
  __pyx_v_ov = __pyx_4;
 
997
 
 
998
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":21 */
 
999
  __pyx_2 = __pyx_v_obj != Py_None;
 
1000
  if (__pyx_2) {
 
1001
    __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
1002
    goto __pyx_L4;
 
1003
  }
 
1004
  __pyx_L4:;
 
1005
 
 
1006
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":24 */
 
1007
  __pyx_v_rc = lpConnectEx(__pyx_v_s,(&__pyx_v_name),(sizeof(__pyx_v_name)),NULL,0,NULL,((OVERLAPPED *)__pyx_v_ov));
 
1008
 
 
1009
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":26 */
 
1010
  __pyx_3 = (!__pyx_v_rc);
 
1011
  if (__pyx_3) {
 
1012
 
 
1013
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":27 */
 
1014
    __pyx_v_rc = WSAGetLastError();
 
1015
 
 
1016
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":28 */
 
1017
    __pyx_2 = (__pyx_v_rc != ERROR_IO_PENDING);
 
1018
    if (__pyx_2) {
 
1019
      __pyx_1 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; goto __pyx_L1;}
 
1020
      __pyx_r = __pyx_1;
 
1021
      __pyx_1 = 0;
 
1022
      goto __pyx_L0;
 
1023
      goto __pyx_L6;
 
1024
    }
 
1025
    __pyx_L6:;
 
1026
    goto __pyx_L5;
 
1027
  }
 
1028
  __pyx_L5:;
 
1029
 
 
1030
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":32 */
 
1031
  Py_XINCREF(__pyx_v_obj);
 
1032
 
 
1033
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\connectex.pxi":33 */
 
1034
  __pyx_1 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; goto __pyx_L1;}
 
1035
  __pyx_r = __pyx_1;
 
1036
  __pyx_1 = 0;
 
1037
  goto __pyx_L0;
 
1038
 
 
1039
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
1040
  goto __pyx_L0;
 
1041
  __pyx_L1:;
 
1042
  Py_XDECREF(__pyx_1);
 
1043
  __Pyx_AddTraceback("iocpsupport.connect");
 
1044
  __pyx_r = 0;
 
1045
  __pyx_L0:;
 
1046
  Py_DECREF(__pyx_v_addr);
 
1047
  Py_DECREF(__pyx_v_obj);
 
1048
  return __pyx_r;
 
1049
}
 
1050
 
 
1051
static char __pyx_k16[] = "second argument needs to be a list";
 
1052
 
 
1053
static PyObject *__pyx_f_11iocpsupport_recv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
1054
static PyObject *__pyx_f_11iocpsupport_recv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
1055
  long __pyx_v_s;
 
1056
  PyObject *__pyx_v_bufflist = 0;
 
1057
  PyObject *__pyx_v_obj = 0;
 
1058
  unsigned long __pyx_v_flags;
 
1059
  int __pyx_v_rc;
 
1060
  int __pyx_v_buffcount;
 
1061
  int __pyx_v_i;
 
1062
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
1063
  WSABUF *__pyx_v_ws_buf;
 
1064
  unsigned long __pyx_v_bytes;
 
1065
  struct PyObject **__pyx_v_buffers;
 
1066
  PyObject *__pyx_r;
 
1067
  PyObject *__pyx_1 = 0;
 
1068
  void *__pyx_2;
 
1069
  int __pyx_3;
 
1070
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_4;
 
1071
  PyObject *__pyx_5 = 0;
 
1072
  PyObject *__pyx_6 = 0;
 
1073
  static char *__pyx_argnames[] = {"s","bufflist","obj","flags",0};
 
1074
  __pyx_v_flags = __pyx_k5;
 
1075
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "lOO|k", __pyx_argnames, &__pyx_v_s, &__pyx_v_bufflist, &__pyx_v_obj, &__pyx_v_flags)) return 0;
 
1076
  Py_INCREF(__pyx_v_bufflist);
 
1077
  Py_INCREF(__pyx_v_obj);
 
1078
 
 
1079
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":12 */
 
1080
  __pyx_1 = PySequence_Fast(__pyx_v_bufflist,__pyx_k16); if (!__pyx_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 12; goto __pyx_L1;}
 
1081
  Py_DECREF(__pyx_v_bufflist);
 
1082
  __pyx_v_bufflist = __pyx_1;
 
1083
  __pyx_1 = 0;
 
1084
 
 
1085
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":13 */
 
1086
  __pyx_v_buffcount = PySequence_Fast_GET_SIZE(__pyx_v_bufflist);
 
1087
 
 
1088
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":14 */
 
1089
  __pyx_v_buffers = PySequence_Fast_ITEMS(__pyx_v_bufflist);
 
1090
 
 
1091
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":16 */
 
1092
  __pyx_2 = PyMem_Malloc((__pyx_v_buffcount * (sizeof(WSABUF)))); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 16; goto __pyx_L1;}
 
1093
  __pyx_v_ws_buf = ((WSABUF *)__pyx_2);
 
1094
 
 
1095
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":18 */
 
1096
  /*try:*/ {
 
1097
 
 
1098
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":19 */
 
1099
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_buffcount; ++__pyx_v_i) {
 
1100
      __pyx_1 = (PyObject *)(__pyx_v_buffers[__pyx_v_i]);
 
1101
      Py_INCREF(__pyx_1);
 
1102
      __pyx_3 = PyObject_AsWriteBuffer(__pyx_1,((void **)(&(__pyx_v_ws_buf[__pyx_v_i]).buf)),((int *)(&(__pyx_v_ws_buf[__pyx_v_i]).len))); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; goto __pyx_L3;}
 
1103
      Py_DECREF(__pyx_1); __pyx_1 = 0;
 
1104
    }
 
1105
 
 
1106
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":22 */
 
1107
    __pyx_4 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; goto __pyx_L3;}
 
1108
    __pyx_v_ov = __pyx_4;
 
1109
 
 
1110
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":23 */
 
1111
    __pyx_3 = __pyx_v_obj != Py_None;
 
1112
    if (__pyx_3) {
 
1113
      __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
1114
      goto __pyx_L7;
 
1115
    }
 
1116
    __pyx_L7:;
 
1117
 
 
1118
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":26 */
 
1119
    __pyx_v_rc = WSARecv(__pyx_v_s,__pyx_v_ws_buf,__pyx_v_buffcount,(&__pyx_v_bytes),(&__pyx_v_flags),((OVERLAPPED *)__pyx_v_ov),NULL);
 
1120
 
 
1121
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":28 */
 
1122
    __pyx_3 = (__pyx_v_rc == SOCKET_ERROR);
 
1123
    if (__pyx_3) {
 
1124
 
 
1125
      /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":29 */
 
1126
      __pyx_v_rc = WSAGetLastError();
 
1127
 
 
1128
      /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":30 */
 
1129
      __pyx_3 = (__pyx_v_rc != ERROR_IO_PENDING);
 
1130
      if (__pyx_3) {
 
1131
        __pyx_1 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; goto __pyx_L3;}
 
1132
        __pyx_5 = PyInt_FromLong(0); if (!__pyx_5) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; goto __pyx_L3;}
 
1133
        __pyx_6 = PyTuple_New(2); if (!__pyx_6) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; goto __pyx_L3;}
 
1134
        PyTuple_SET_ITEM(__pyx_6, 0, __pyx_1);
 
1135
        PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
 
1136
        __pyx_1 = 0;
 
1137
        __pyx_5 = 0;
 
1138
        __pyx_r = __pyx_6;
 
1139
        __pyx_6 = 0;
 
1140
        goto __pyx_L2;
 
1141
        goto __pyx_L9;
 
1142
      }
 
1143
      __pyx_L9:;
 
1144
      goto __pyx_L8;
 
1145
    }
 
1146
    __pyx_L8:;
 
1147
 
 
1148
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":33 */
 
1149
    Py_XINCREF(__pyx_v_obj);
 
1150
 
 
1151
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":34 */
 
1152
    __pyx_1 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; goto __pyx_L3;}
 
1153
    __pyx_5 = PyLong_FromUnsignedLong(__pyx_v_bytes); if (!__pyx_5) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; goto __pyx_L3;}
 
1154
    __pyx_6 = PyTuple_New(2); if (!__pyx_6) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; goto __pyx_L3;}
 
1155
    PyTuple_SET_ITEM(__pyx_6, 0, __pyx_1);
 
1156
    PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
 
1157
    __pyx_1 = 0;
 
1158
    __pyx_5 = 0;
 
1159
    __pyx_r = __pyx_6;
 
1160
    __pyx_6 = 0;
 
1161
    goto __pyx_L2;
 
1162
  }
 
1163
  /*finally:*/ {
 
1164
    int __pyx_why;
 
1165
    PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
 
1166
    int __pyx_exc_lineno;
 
1167
    __pyx_why = 0; goto __pyx_L4;
 
1168
    __pyx_L2: __pyx_why = 3; goto __pyx_L4;
 
1169
    __pyx_L3: {
 
1170
      __pyx_why = 4;
 
1171
      Py_XDECREF(__pyx_1); __pyx_1 = 0;
 
1172
      Py_XDECREF(__pyx_5); __pyx_5 = 0;
 
1173
      Py_XDECREF(__pyx_6); __pyx_6 = 0;
 
1174
      PyErr_Fetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
 
1175
      __pyx_exc_lineno = __pyx_lineno;
 
1176
      goto __pyx_L4;
 
1177
    }
 
1178
    __pyx_L4:;
 
1179
    PyMem_Free(__pyx_v_ws_buf);
 
1180
    switch (__pyx_why) {
 
1181
      case 3: goto __pyx_L0;
 
1182
      case 4: {
 
1183
        PyErr_Restore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
 
1184
        __pyx_lineno = __pyx_exc_lineno;
 
1185
        __pyx_exc_type = 0;
 
1186
        __pyx_exc_value = 0;
 
1187
        __pyx_exc_tb = 0;
 
1188
        goto __pyx_L1;
 
1189
      }
 
1190
    }
 
1191
  }
 
1192
 
 
1193
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
1194
  goto __pyx_L0;
 
1195
  __pyx_L1:;
 
1196
  Py_XDECREF(__pyx_1);
 
1197
  Py_XDECREF(__pyx_5);
 
1198
  Py_XDECREF(__pyx_6);
 
1199
  __Pyx_AddTraceback("iocpsupport.recv");
 
1200
  __pyx_r = 0;
 
1201
  __pyx_L0:;
 
1202
  Py_DECREF(__pyx_v_bufflist);
 
1203
  Py_DECREF(__pyx_v_obj);
 
1204
  return __pyx_r;
 
1205
}
 
1206
 
 
1207
static PyObject *__pyx_f_11iocpsupport_recvfrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
1208
static PyObject *__pyx_f_11iocpsupport_recvfrom(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
1209
  long __pyx_v_s;
 
1210
  PyObject *__pyx_v_buff = 0;
 
1211
  PyObject *__pyx_v_addr_buff = 0;
 
1212
  PyObject *__pyx_v_obj = 0;
 
1213
  unsigned long __pyx_v_flags;
 
1214
  int __pyx_v_rc;
 
1215
  int __pyx_v_fromlen;
 
1216
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
1217
  WSABUF __pyx_v_ws_buf;
 
1218
  unsigned long __pyx_v_bytes;
 
1219
  struct sockaddr *__pyx_v_fromaddr;
 
1220
  PyObject *__pyx_r;
 
1221
  int __pyx_1;
 
1222
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_2;
 
1223
  PyObject *__pyx_3 = 0;
 
1224
  PyObject *__pyx_4 = 0;
 
1225
  PyObject *__pyx_5 = 0;
 
1226
  static char *__pyx_argnames[] = {"s","buff","addr_buff","obj","flags",0};
 
1227
  __pyx_v_flags = __pyx_k6;
 
1228
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "lOOO|k", __pyx_argnames, &__pyx_v_s, &__pyx_v_buff, &__pyx_v_addr_buff, &__pyx_v_obj, &__pyx_v_flags)) return 0;
 
1229
  Py_INCREF(__pyx_v_buff);
 
1230
  Py_INCREF(__pyx_v_addr_buff);
 
1231
  Py_INCREF(__pyx_v_obj);
 
1232
 
 
1233
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":45 */
 
1234
  __pyx_1 = PyObject_AsWriteBuffer(__pyx_v_buff,((void **)(&__pyx_v_ws_buf.buf)),((int *)(&__pyx_v_ws_buf.len))); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; goto __pyx_L1;}
 
1235
 
 
1236
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":46 */
 
1237
  __pyx_1 = PyObject_AsWriteBuffer(__pyx_v_addr_buff,((void **)(&__pyx_v_fromaddr)),(&__pyx_v_fromlen)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 46; goto __pyx_L1;}
 
1238
 
 
1239
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":48 */
 
1240
  __pyx_2 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; goto __pyx_L1;}
 
1241
  __pyx_v_ov = __pyx_2;
 
1242
 
 
1243
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":49 */
 
1244
  __pyx_1 = __pyx_v_obj != Py_None;
 
1245
  if (__pyx_1) {
 
1246
    __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
1247
    goto __pyx_L2;
 
1248
  }
 
1249
  __pyx_L2:;
 
1250
 
 
1251
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":52 */
 
1252
  __pyx_v_rc = WSARecvFrom(__pyx_v_s,(&__pyx_v_ws_buf),1,(&__pyx_v_bytes),(&__pyx_v_flags),__pyx_v_fromaddr,(&__pyx_v_fromlen),((OVERLAPPED *)__pyx_v_ov),NULL);
 
1253
 
 
1254
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":54 */
 
1255
  __pyx_1 = (__pyx_v_rc == SOCKET_ERROR);
 
1256
  if (__pyx_1) {
 
1257
 
 
1258
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":55 */
 
1259
    __pyx_v_rc = WSAGetLastError();
 
1260
 
 
1261
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":56 */
 
1262
    __pyx_1 = (__pyx_v_rc != ERROR_IO_PENDING);
 
1263
    if (__pyx_1) {
 
1264
      __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; goto __pyx_L1;}
 
1265
      __pyx_4 = PyInt_FromLong(0); if (!__pyx_4) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; goto __pyx_L1;}
 
1266
      __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; goto __pyx_L1;}
 
1267
      PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
 
1268
      PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
 
1269
      __pyx_3 = 0;
 
1270
      __pyx_4 = 0;
 
1271
      __pyx_r = __pyx_5;
 
1272
      __pyx_5 = 0;
 
1273
      goto __pyx_L0;
 
1274
      goto __pyx_L4;
 
1275
    }
 
1276
    __pyx_L4:;
 
1277
    goto __pyx_L3;
 
1278
  }
 
1279
  __pyx_L3:;
 
1280
 
 
1281
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":59 */
 
1282
  Py_XINCREF(__pyx_v_obj);
 
1283
 
 
1284
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":60 */
 
1285
  __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; goto __pyx_L1;}
 
1286
  __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_bytes); if (!__pyx_4) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; goto __pyx_L1;}
 
1287
  __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; goto __pyx_L1;}
 
1288
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
 
1289
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
 
1290
  __pyx_3 = 0;
 
1291
  __pyx_4 = 0;
 
1292
  __pyx_r = __pyx_5;
 
1293
  __pyx_5 = 0;
 
1294
  goto __pyx_L0;
 
1295
 
 
1296
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
1297
  goto __pyx_L0;
 
1298
  __pyx_L1:;
 
1299
  Py_XDECREF(__pyx_3);
 
1300
  Py_XDECREF(__pyx_4);
 
1301
  Py_XDECREF(__pyx_5);
 
1302
  __Pyx_AddTraceback("iocpsupport.recvfrom");
 
1303
  __pyx_r = 0;
 
1304
  __pyx_L0:;
 
1305
  Py_DECREF(__pyx_v_buff);
 
1306
  Py_DECREF(__pyx_v_addr_buff);
 
1307
  Py_DECREF(__pyx_v_obj);
 
1308
  return __pyx_r;
 
1309
}
 
1310
 
 
1311
static PyObject *__pyx_f_11iocpsupport_send(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
1312
static PyObject *__pyx_f_11iocpsupport_send(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
1313
  long __pyx_v_s;
 
1314
  PyObject *__pyx_v_buff = 0;
 
1315
  PyObject *__pyx_v_obj = 0;
 
1316
  unsigned long __pyx_v_flags;
 
1317
  int __pyx_v_rc;
 
1318
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_v_ov;
 
1319
  WSABUF __pyx_v_ws_buf;
 
1320
  unsigned long __pyx_v_bytes;
 
1321
  PyObject *__pyx_r;
 
1322
  int __pyx_1;
 
1323
  struct __pyx_t_11iocpsupport_myOVERLAPPED *__pyx_2;
 
1324
  PyObject *__pyx_3 = 0;
 
1325
  PyObject *__pyx_4 = 0;
 
1326
  PyObject *__pyx_5 = 0;
 
1327
  static char *__pyx_argnames[] = {"s","buff","obj","flags",0};
 
1328
  __pyx_v_flags = __pyx_k7;
 
1329
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "lOO|k", __pyx_argnames, &__pyx_v_s, &__pyx_v_buff, &__pyx_v_obj, &__pyx_v_flags)) return 0;
 
1330
  Py_INCREF(__pyx_v_buff);
 
1331
  Py_INCREF(__pyx_v_obj);
 
1332
 
 
1333
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":11 */
 
1334
  __pyx_1 = PyObject_AsReadBuffer(__pyx_v_buff,((void **)(&__pyx_v_ws_buf.buf)),((int *)(&__pyx_v_ws_buf.len))); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; goto __pyx_L1;}
 
1335
 
 
1336
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":13 */
 
1337
  __pyx_2 = __pyx_f_11iocpsupport_makeOV(); if (__pyx_2 == NULL) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; goto __pyx_L1;}
 
1338
  __pyx_v_ov = __pyx_2;
 
1339
 
 
1340
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":14 */
 
1341
  __pyx_1 = __pyx_v_obj != Py_None;
 
1342
  if (__pyx_1) {
 
1343
    __pyx_v_ov->obj = ((struct PyObject *)__pyx_v_obj);
 
1344
    goto __pyx_L2;
 
1345
  }
 
1346
  __pyx_L2:;
 
1347
 
 
1348
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":17 */
 
1349
  __pyx_v_rc = WSASend(__pyx_v_s,(&__pyx_v_ws_buf),1,(&__pyx_v_bytes),__pyx_v_flags,((OVERLAPPED *)__pyx_v_ov),NULL);
 
1350
 
 
1351
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":19 */
 
1352
  __pyx_1 = (__pyx_v_rc == SOCKET_ERROR);
 
1353
  if (__pyx_1) {
 
1354
 
 
1355
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":20 */
 
1356
    __pyx_v_rc = WSAGetLastError();
 
1357
 
 
1358
    /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":21 */
 
1359
    __pyx_1 = (__pyx_v_rc != ERROR_IO_PENDING);
 
1360
    if (__pyx_1) {
 
1361
      __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; goto __pyx_L1;}
 
1362
      __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_bytes); if (!__pyx_4) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; goto __pyx_L1;}
 
1363
      __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; goto __pyx_L1;}
 
1364
      PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
 
1365
      PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
 
1366
      __pyx_3 = 0;
 
1367
      __pyx_4 = 0;
 
1368
      __pyx_r = __pyx_5;
 
1369
      __pyx_5 = 0;
 
1370
      goto __pyx_L0;
 
1371
      goto __pyx_L4;
 
1372
    }
 
1373
    __pyx_L4:;
 
1374
    goto __pyx_L3;
 
1375
  }
 
1376
  __pyx_L3:;
 
1377
 
 
1378
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":24 */
 
1379
  Py_XINCREF(__pyx_v_obj);
 
1380
 
 
1381
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":25 */
 
1382
  __pyx_3 = PyInt_FromLong(__pyx_v_rc); if (!__pyx_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 25; goto __pyx_L1;}
 
1383
  __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_bytes); if (!__pyx_4) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 25; goto __pyx_L1;}
 
1384
  __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 25; goto __pyx_L1;}
 
1385
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
 
1386
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
 
1387
  __pyx_3 = 0;
 
1388
  __pyx_4 = 0;
 
1389
  __pyx_r = __pyx_5;
 
1390
  __pyx_5 = 0;
 
1391
  goto __pyx_L0;
 
1392
 
 
1393
  __pyx_r = Py_None; Py_INCREF(Py_None);
 
1394
  goto __pyx_L0;
 
1395
  __pyx_L1:;
 
1396
  Py_XDECREF(__pyx_3);
 
1397
  Py_XDECREF(__pyx_4);
 
1398
  Py_XDECREF(__pyx_5);
 
1399
  __Pyx_AddTraceback("iocpsupport.send");
 
1400
  __pyx_r = 0;
 
1401
  __pyx_L0:;
 
1402
  Py_DECREF(__pyx_v_buff);
 
1403
  Py_DECREF(__pyx_v_obj);
 
1404
  return __pyx_r;
 
1405
}
 
1406
 
 
1407
static __Pyx_InternTabEntry __pyx_intern_tab[] = {
 
1408
  {&__pyx_n_CreateIoCompletionPort, "CreateIoCompletionPort"},
 
1409
  {&__pyx_n_Event, "Event"},
 
1410
  {&__pyx_n_False, "False"},
 
1411
  {&__pyx_n_MemoryError, "MemoryError"},
 
1412
  {&__pyx_n_PostQueuedCompletionStatus, "PostQueuedCompletionStatus"},
 
1413
  {&__pyx_n_ValueError, "ValueError"},
 
1414
  {&__pyx_n_WindowsError, "WindowsError"},
 
1415
  {&__pyx_n___init__, "__init__"},
 
1416
  {&__pyx_n_callback, "callback"},
 
1417
  {&__pyx_n_getsockopt, "getsockopt"},
 
1418
  {&__pyx_n_have_connectex, "have_connectex"},
 
1419
  {&__pyx_n_ignore, "ignore"},
 
1420
  {&__pyx_n_items, "items"},
 
1421
  {&__pyx_n_owner, "owner"},
 
1422
  {&__pyx_n_socket, "socket"},
 
1423
  {0, 0}
 
1424
};
 
1425
 
 
1426
static __Pyx_StringTabEntry __pyx_string_tab[] = {
 
1427
  {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)},
 
1428
  {&__pyx_k11p, __pyx_k11, sizeof(__pyx_k11)},
 
1429
  {&__pyx_k14p, __pyx_k14, sizeof(__pyx_k14)},
 
1430
  {&__pyx_k15p, __pyx_k15, sizeof(__pyx_k15)},
 
1431
  {0, 0, 0}
 
1432
};
 
1433
 
 
1434
static PyObject *__pyx_tp_new_11iocpsupport_CompletionPort(PyTypeObject *t, PyObject *a, PyObject *k) {
 
1435
  PyObject *o = (*t->tp_alloc)(t, 0);
 
1436
  if (!o) return 0;
 
1437
  return o;
 
1438
}
 
1439
 
 
1440
static void __pyx_tp_dealloc_11iocpsupport_CompletionPort(PyObject *o) {
 
1441
  (*o->ob_type->tp_free)(o);
 
1442
}
 
1443
 
 
1444
static int __pyx_tp_traverse_11iocpsupport_CompletionPort(PyObject *o, visitproc v, void *a) {
 
1445
  return 0;
 
1446
}
 
1447
 
 
1448
static int __pyx_tp_clear_11iocpsupport_CompletionPort(PyObject *o) {
 
1449
  return 0;
 
1450
}
 
1451
 
 
1452
static struct PyMethodDef __pyx_methods_11iocpsupport_CompletionPort[] = {
 
1453
  {"addHandle", (PyCFunction)__pyx_f_11iocpsupport_14CompletionPort_addHandle, METH_VARARGS|METH_KEYWORDS, 0},
 
1454
  {"getEvent", (PyCFunction)__pyx_f_11iocpsupport_14CompletionPort_getEvent, METH_VARARGS|METH_KEYWORDS, 0},
 
1455
  {"postEvent", (PyCFunction)__pyx_f_11iocpsupport_14CompletionPort_postEvent, METH_VARARGS|METH_KEYWORDS, 0},
 
1456
  {"__del__", (PyCFunction)__pyx_f_11iocpsupport_14CompletionPort___del__, METH_VARARGS|METH_KEYWORDS, 0},
 
1457
  {0, 0, 0, 0}
 
1458
};
 
1459
 
 
1460
static PyNumberMethods __pyx_tp_as_number_CompletionPort = {
 
1461
  0, /*nb_add*/
 
1462
  0, /*nb_subtract*/
 
1463
  0, /*nb_multiply*/
 
1464
  0, /*nb_divide*/
 
1465
  0, /*nb_remainder*/
 
1466
  0, /*nb_divmod*/
 
1467
  0, /*nb_power*/
 
1468
  0, /*nb_negative*/
 
1469
  0, /*nb_positive*/
 
1470
  0, /*nb_absolute*/
 
1471
  0, /*nb_nonzero*/
 
1472
  0, /*nb_invert*/
 
1473
  0, /*nb_lshift*/
 
1474
  0, /*nb_rshift*/
 
1475
  0, /*nb_and*/
 
1476
  0, /*nb_xor*/
 
1477
  0, /*nb_or*/
 
1478
  0, /*nb_coerce*/
 
1479
  0, /*nb_int*/
 
1480
  0, /*nb_long*/
 
1481
  0, /*nb_float*/
 
1482
  0, /*nb_oct*/
 
1483
  0, /*nb_hex*/
 
1484
  0, /*nb_inplace_add*/
 
1485
  0, /*nb_inplace_subtract*/
 
1486
  0, /*nb_inplace_multiply*/
 
1487
  0, /*nb_inplace_divide*/
 
1488
  0, /*nb_inplace_remainder*/
 
1489
  0, /*nb_inplace_power*/
 
1490
  0, /*nb_inplace_lshift*/
 
1491
  0, /*nb_inplace_rshift*/
 
1492
  0, /*nb_inplace_and*/
 
1493
  0, /*nb_inplace_xor*/
 
1494
  0, /*nb_inplace_or*/
 
1495
  0, /*nb_floor_divide*/
 
1496
  0, /*nb_true_divide*/
 
1497
  0, /*nb_inplace_floor_divide*/
 
1498
  0, /*nb_inplace_true_divide*/
 
1499
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
 
1500
  0, /*nb_index*/
 
1501
  #endif
 
1502
};
 
1503
 
 
1504
static PySequenceMethods __pyx_tp_as_sequence_CompletionPort = {
 
1505
  0, /*sq_length*/
 
1506
  0, /*sq_concat*/
 
1507
  0, /*sq_repeat*/
 
1508
  0, /*sq_item*/
 
1509
  0, /*sq_slice*/
 
1510
  0, /*sq_ass_item*/
 
1511
  0, /*sq_ass_slice*/
 
1512
  0, /*sq_contains*/
 
1513
  0, /*sq_inplace_concat*/
 
1514
  0, /*sq_inplace_repeat*/
 
1515
};
 
1516
 
 
1517
static PyMappingMethods __pyx_tp_as_mapping_CompletionPort = {
 
1518
  0, /*mp_length*/
 
1519
  0, /*mp_subscript*/
 
1520
  0, /*mp_ass_subscript*/
 
1521
};
 
1522
 
 
1523
static PyBufferProcs __pyx_tp_as_buffer_CompletionPort = {
 
1524
  0, /*bf_getreadbuffer*/
 
1525
  0, /*bf_getwritebuffer*/
 
1526
  0, /*bf_getsegcount*/
 
1527
  0, /*bf_getcharbuffer*/
 
1528
};
 
1529
 
 
1530
PyTypeObject __pyx_type_11iocpsupport_CompletionPort = {
 
1531
  PyObject_HEAD_INIT(0)
 
1532
  0, /*ob_size*/
 
1533
  "iocpsupport.CompletionPort", /*tp_name*/
 
1534
  sizeof(struct __pyx_obj_11iocpsupport_CompletionPort), /*tp_basicsize*/
 
1535
  0, /*tp_itemsize*/
 
1536
  __pyx_tp_dealloc_11iocpsupport_CompletionPort, /*tp_dealloc*/
 
1537
  0, /*tp_print*/
 
1538
  0, /*tp_getattr*/
 
1539
  0, /*tp_setattr*/
 
1540
  0, /*tp_compare*/
 
1541
  0, /*tp_repr*/
 
1542
  &__pyx_tp_as_number_CompletionPort, /*tp_as_number*/
 
1543
  &__pyx_tp_as_sequence_CompletionPort, /*tp_as_sequence*/
 
1544
  &__pyx_tp_as_mapping_CompletionPort, /*tp_as_mapping*/
 
1545
  0, /*tp_hash*/
 
1546
  0, /*tp_call*/
 
1547
  0, /*tp_str*/
 
1548
  0, /*tp_getattro*/
 
1549
  0, /*tp_setattro*/
 
1550
  &__pyx_tp_as_buffer_CompletionPort, /*tp_as_buffer*/
 
1551
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
 
1552
  0, /*tp_doc*/
 
1553
  __pyx_tp_traverse_11iocpsupport_CompletionPort, /*tp_traverse*/
 
1554
  __pyx_tp_clear_11iocpsupport_CompletionPort, /*tp_clear*/
 
1555
  0, /*tp_richcompare*/
 
1556
  0, /*tp_weaklistoffset*/
 
1557
  0, /*tp_iter*/
 
1558
  0, /*tp_iternext*/
 
1559
  __pyx_methods_11iocpsupport_CompletionPort, /*tp_methods*/
 
1560
  0, /*tp_members*/
 
1561
  0, /*tp_getset*/
 
1562
  0, /*tp_base*/
 
1563
  0, /*tp_dict*/
 
1564
  0, /*tp_descr_get*/
 
1565
  0, /*tp_descr_set*/
 
1566
  0, /*tp_dictoffset*/
 
1567
  __pyx_f_11iocpsupport_14CompletionPort___init__, /*tp_init*/
 
1568
  0, /*tp_alloc*/
 
1569
  __pyx_tp_new_11iocpsupport_CompletionPort, /*tp_new*/
 
1570
  0, /*tp_free*/
 
1571
  0, /*tp_is_gc*/
 
1572
  0, /*tp_bases*/
 
1573
  0, /*tp_mro*/
 
1574
  0, /*tp_cache*/
 
1575
  0, /*tp_subclasses*/
 
1576
  0, /*tp_weaklist*/
 
1577
};
 
1578
 
 
1579
static struct PyMethodDef __pyx_methods[] = {
 
1580
  {"makesockaddr", (PyCFunction)__pyx_f_11iocpsupport_makesockaddr, METH_VARARGS|METH_KEYWORDS, 0},
 
1581
  {"AllocateReadBuffer", (PyCFunction)__pyx_f_11iocpsupport_AllocateReadBuffer, METH_VARARGS|METH_KEYWORDS, 0},
 
1582
  {"maxAddrLen", (PyCFunction)__pyx_f_11iocpsupport_maxAddrLen, METH_VARARGS|METH_KEYWORDS, 0},
 
1583
  {"accept", (PyCFunction)__pyx_f_11iocpsupport_accept, METH_VARARGS|METH_KEYWORDS, 0},
 
1584
  {"get_accept_addrs", (PyCFunction)__pyx_f_11iocpsupport_get_accept_addrs, METH_VARARGS|METH_KEYWORDS, 0},
 
1585
  {"connect", (PyCFunction)__pyx_f_11iocpsupport_connect, METH_VARARGS|METH_KEYWORDS, 0},
 
1586
  {"recv", (PyCFunction)__pyx_f_11iocpsupport_recv, METH_VARARGS|METH_KEYWORDS, 0},
 
1587
  {"recvfrom", (PyCFunction)__pyx_f_11iocpsupport_recvfrom, METH_VARARGS|METH_KEYWORDS, 0},
 
1588
  {"send", (PyCFunction)__pyx_f_11iocpsupport_send, METH_VARARGS|METH_KEYWORDS, 0},
 
1589
  {0, 0, 0, 0}
 
1590
};
 
1591
 
 
1592
static void __pyx_init_filenames(void); /*proto*/
 
1593
 
 
1594
PyMODINIT_FUNC initiocpsupport(void); /*proto*/
 
1595
PyMODINIT_FUNC initiocpsupport(void) {
 
1596
  PyObject *__pyx_1 = 0;
 
1597
  PyObject *__pyx_2 = 0;
 
1598
  PyObject *__pyx_3 = 0;
 
1599
  PyObject *__pyx_4 = 0;
 
1600
  int __pyx_5;
 
1601
  __pyx_init_filenames();
 
1602
  __pyx_m = Py_InitModule4("iocpsupport", __pyx_methods, 0, 0, PYTHON_API_VERSION);
 
1603
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
 
1604
  Py_INCREF(__pyx_m);
 
1605
  __pyx_b = PyImport_AddModule("__builtin__");
 
1606
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
 
1607
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
 
1608
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
 
1609
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
 
1610
  if (PyType_Ready(&__pyx_type_11iocpsupport_CompletionPort) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
 
1611
  if (PyObject_SetAttrString(__pyx_m, "CompletionPort", (PyObject *)&__pyx_type_11iocpsupport_CompletionPort) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
 
1612
  __pyx_ptype_11iocpsupport_CompletionPort = &__pyx_type_11iocpsupport_CompletionPort;
 
1613
 
 
1614
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":121 */
 
1615
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; goto __pyx_L1;}
 
1616
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; goto __pyx_L1;}
 
1617
  __pyx_3 = __Pyx_CreateClass(__pyx_2, __pyx_1, __pyx_n_Event, "iocpsupport"); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; goto __pyx_L1;}
 
1618
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
1619
  __pyx_2 = PyCFunction_New(&__pyx_mdef_11iocpsupport_5Event___init__, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L1;}
 
1620
  __pyx_4 = PyMethod_New(__pyx_2, 0, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L1;}
 
1621
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
1622
  if (PyObject_SetAttr(__pyx_3, __pyx_n___init__, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L1;}
 
1623
  Py_DECREF(__pyx_4); __pyx_4 = 0;
 
1624
  if (PyObject_SetAttr(__pyx_m, __pyx_n_Event, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; goto __pyx_L1;}
 
1625
  Py_DECREF(__pyx_3); __pyx_3 = 0;
 
1626
  Py_DECREF(__pyx_1); __pyx_1 = 0;
 
1627
 
 
1628
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":138 */
 
1629
  __pyx_k2 = 0;
 
1630
 
 
1631
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":240 */
 
1632
  __pyx_2 = __Pyx_Import(__pyx_n_socket, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; goto __pyx_L1;}
 
1633
  if (PyObject_SetAttr(__pyx_m, __pyx_n_socket, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; goto __pyx_L1;}
 
1634
  Py_DECREF(__pyx_2); __pyx_2 = 0;
 
1635
 
 
1636
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":241 */
 
1637
  __pyx_5 = (!initWinsockPointers());
 
1638
  if (__pyx_5) {
 
1639
    __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; goto __pyx_L1;}
 
1640
    __Pyx_Raise(__pyx_4, __pyx_k4p, 0);
 
1641
    Py_DECREF(__pyx_4); __pyx_4 = 0;
 
1642
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; goto __pyx_L1;}
 
1643
    goto __pyx_L5;
 
1644
  }
 
1645
  __pyx_L5:;
 
1646
 
 
1647
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport/iocpsupport.pyx":244 */
 
1648
  __pyx_3 = PyInt_FromLong((lpConnectEx != NULL)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
 
1649
  if (PyObject_SetAttr(__pyx_m, __pyx_n_have_connectex, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
 
1650
  Py_DECREF(__pyx_3); __pyx_3 = 0;
 
1651
 
 
1652
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":5 */
 
1653
  __pyx_k5 = 0;
 
1654
 
 
1655
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsarecv.pxi":38 */
 
1656
  __pyx_k6 = 0;
 
1657
 
 
1658
  /* "X:\projects\Twisted\trunk\twisted\internet\iocpreactor\iocpsupport\wsasend.pxi":5 */
 
1659
  __pyx_k7 = 0;
 
1660
  return;
 
1661
  __pyx_L1:;
 
1662
  Py_XDECREF(__pyx_1);
 
1663
  Py_XDECREF(__pyx_2);
 
1664
  Py_XDECREF(__pyx_3);
 
1665
  Py_XDECREF(__pyx_4);
 
1666
  __Pyx_AddTraceback("iocpsupport");
 
1667
}
 
1668
 
 
1669
static char *__pyx_filenames[] = {
 
1670
  "iocpsupport.pyx",
 
1671
  "acceptex.pxi",
 
1672
  "connectex.pxi",
 
1673
  "wsarecv.pxi",
 
1674
  "wsasend.pxi",
 
1675
};
 
1676
 
 
1677
/* Runtime support code */
 
1678
 
 
1679
static void __pyx_init_filenames(void) {
 
1680
  __pyx_f = __pyx_filenames;
 
1681
}
 
1682
 
 
1683
static PyObject *__Pyx_CreateClass(
 
1684
    PyObject *bases, PyObject *dict, PyObject *name, char *modname)
 
1685
{
 
1686
    PyObject *py_modname;
 
1687
    PyObject *result = 0;
 
1688
    
 
1689
    py_modname = PyString_FromString(modname);
 
1690
    if (!py_modname)
 
1691
        goto bad;
 
1692
    if (PyDict_SetItemString(dict, "__module__", py_modname) < 0)
 
1693
        goto bad;
 
1694
    result = PyClass_New(bases, dict, name);
 
1695
bad:
 
1696
    Py_XDECREF(py_modname);
 
1697
    return result;
 
1698
}
 
1699
 
 
1700
static int __Pyx_GetStarArgs(
 
1701
    PyObject **args, 
 
1702
    PyObject **kwds,
 
1703
    char *kwd_list[], 
 
1704
    Py_ssize_t nargs,
 
1705
    PyObject **args2, 
 
1706
    PyObject **kwds2,
 
1707
    char rqd_kwds[])
 
1708
{
 
1709
    PyObject *x = 0, *args1 = 0, *kwds1 = 0;
 
1710
    int i;
 
1711
    char **p;
 
1712
    
 
1713
    if (args2)
 
1714
        *args2 = 0;
 
1715
    if (kwds2)
 
1716
        *kwds2 = 0;
 
1717
    
 
1718
    if (args2) {
 
1719
        args1 = PyTuple_GetSlice(*args, 0, nargs);
 
1720
        if (!args1)
 
1721
            goto bad;
 
1722
        *args2 = PyTuple_GetSlice(*args, nargs, PyTuple_GET_SIZE(*args));
 
1723
        if (!*args2)
 
1724
            goto bad;
 
1725
    }
 
1726
    else if (PyTuple_GET_SIZE(*args) > nargs) {
 
1727
        int m = nargs;
 
1728
        int n = PyTuple_GET_SIZE(*args);
 
1729
        PyErr_Format(PyExc_TypeError,
 
1730
            "function takes at most %d positional arguments (%d given)",
 
1731
                m, n);
 
1732
        goto bad;
 
1733
    }
 
1734
    else {
 
1735
        args1 = *args;
 
1736
        Py_INCREF(args1);
 
1737
    }
 
1738
    
 
1739
    if (rqd_kwds && !*kwds)
 
1740
            for (i = 0, p = kwd_list; *p; i++, p++)
 
1741
                if (rqd_kwds[i])
 
1742
                    goto missing_kwarg;
 
1743
    
 
1744
    if (kwds2) {
 
1745
        if (*kwds) {
 
1746
            kwds1 = PyDict_New();
 
1747
            if (!kwds1)
 
1748
                goto bad;
 
1749
            *kwds2 = PyDict_Copy(*kwds);
 
1750
            if (!*kwds2)
 
1751
                goto bad;
 
1752
            for (i = 0, p = kwd_list; *p; i++, p++) {
 
1753
                x = PyDict_GetItemString(*kwds, *p);
 
1754
                if (x) {
 
1755
                    if (PyDict_SetItemString(kwds1, *p, x) < 0)
 
1756
                        goto bad;
 
1757
                    if (PyDict_DelItemString(*kwds2, *p) < 0)
 
1758
                        goto bad;
 
1759
                }
 
1760
                else if (rqd_kwds && rqd_kwds[i])
 
1761
                    goto missing_kwarg;
 
1762
            }
 
1763
        }
 
1764
        else {
 
1765
            *kwds2 = PyDict_New();
 
1766
            if (!*kwds2)
 
1767
                goto bad;
 
1768
        }
 
1769
    }
 
1770
    else {
 
1771
        kwds1 = *kwds;
 
1772
        Py_XINCREF(kwds1);
 
1773
        if (rqd_kwds && *kwds)
 
1774
            for (i = 0, p = kwd_list; *p; i++, p++)
 
1775
                if (rqd_kwds[i] && !PyDict_GetItemString(*kwds, *p))
 
1776
                        goto missing_kwarg;
 
1777
    }
 
1778
    
 
1779
    *args = args1;
 
1780
    *kwds = kwds1;
 
1781
    return 0;
 
1782
missing_kwarg:
 
1783
    PyErr_Format(PyExc_TypeError,
 
1784
        "required keyword argument '%s' is missing", *p);
 
1785
bad:
 
1786
    Py_XDECREF(args1);
 
1787
    Py_XDECREF(kwds1);
 
1788
    if (args2) {
 
1789
        Py_XDECREF(*args2);
 
1790
    }
 
1791
    if (kwds2) {
 
1792
        Py_XDECREF(*kwds2);
 
1793
    }
 
1794
    return -1;
 
1795
}
 
1796
 
 
1797
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
 
1798
    PyObject *__import__ = 0;
 
1799
    PyObject *empty_list = 0;
 
1800
    PyObject *module = 0;
 
1801
    PyObject *global_dict = 0;
 
1802
    PyObject *empty_dict = 0;
 
1803
    PyObject *list;
 
1804
    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
 
1805
    if (!__import__)
 
1806
        goto bad;
 
1807
    if (from_list)
 
1808
        list = from_list;
 
1809
    else {
 
1810
        empty_list = PyList_New(0);
 
1811
        if (!empty_list)
 
1812
            goto bad;
 
1813
        list = empty_list;
 
1814
    }
 
1815
    global_dict = PyModule_GetDict(__pyx_m);
 
1816
    if (!global_dict)
 
1817
        goto bad;
 
1818
    empty_dict = PyDict_New();
 
1819
    if (!empty_dict)
 
1820
        goto bad;
 
1821
    module = PyObject_CallFunction(__import__, "OOOO",
 
1822
        name, global_dict, empty_dict, list);
 
1823
bad:
 
1824
    Py_XDECREF(empty_list);
 
1825
    Py_XDECREF(__import__);
 
1826
    Py_XDECREF(empty_dict);
 
1827
    return module;
 
1828
}
 
1829
 
 
1830
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
 
1831
    PyObject *result;
 
1832
    result = PyObject_GetAttr(dict, name);
 
1833
    if (!result)
 
1834
        PyErr_SetObject(PyExc_NameError, name);
 
1835
    return result;
 
1836
}
 
1837
 
 
1838
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
 
1839
    Py_XINCREF(type);
 
1840
    Py_XINCREF(value);
 
1841
    Py_XINCREF(tb);
 
1842
    /* First, check the traceback argument, replacing None with NULL. */
 
1843
    if (tb == Py_None) {
 
1844
        Py_DECREF(tb);
 
1845
        tb = 0;
 
1846
    }
 
1847
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
 
1848
        PyErr_SetString(PyExc_TypeError,
 
1849
            "raise: arg 3 must be a traceback or None");
 
1850
        goto raise_error;
 
1851
    }
 
1852
    /* Next, replace a missing value with None */
 
1853
    if (value == NULL) {
 
1854
        value = Py_None;
 
1855
        Py_INCREF(value);
 
1856
    }
 
1857
    #if PY_VERSION_HEX < 0x02050000
 
1858
    if (!PyClass_Check(type))
 
1859
    #else
 
1860
    if (!PyType_Check(type))
 
1861
    #endif
 
1862
    {
 
1863
        /* Raising an instance.  The value should be a dummy. */
 
1864
        if (value != Py_None) {
 
1865
            PyErr_SetString(PyExc_TypeError,
 
1866
                "instance exception may not have a separate value");
 
1867
            goto raise_error;
 
1868
        }
 
1869
        /* Normalize to raise <class>, <instance> */
 
1870
        Py_DECREF(value);
 
1871
        value = type;
 
1872
        #if PY_VERSION_HEX < 0x02050000
 
1873
            if (PyInstance_Check(type)) {
 
1874
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
 
1875
                Py_INCREF(type);
 
1876
            }
 
1877
            else {
 
1878
                PyErr_SetString(PyExc_TypeError,
 
1879
                    "raise: exception must be an old-style class or instance");
 
1880
                goto raise_error;
 
1881
            }
 
1882
        #else
 
1883
            type = (PyObject*) type->ob_type;
 
1884
            Py_INCREF(type);
 
1885
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
 
1886
                PyErr_SetString(PyExc_TypeError,
 
1887
                    "raise: exception class must be a subclass of BaseException");
 
1888
                goto raise_error;
 
1889
            }
 
1890
        #endif
 
1891
    }
 
1892
    PyErr_Restore(type, value, tb);
 
1893
    return;
 
1894
raise_error:
 
1895
    Py_XDECREF(value);
 
1896
    Py_XDECREF(type);
 
1897
    Py_XDECREF(tb);
 
1898
    return;
 
1899
}
 
1900
 
 
1901
static void __Pyx_UnpackError(void) {
 
1902
    PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
 
1903
}
 
1904
 
 
1905
static PyObject *__Pyx_UnpackItem(PyObject *iter) {
 
1906
    PyObject *item;
 
1907
    if (!(item = PyIter_Next(iter))) {
 
1908
        if (!PyErr_Occurred())
 
1909
            __Pyx_UnpackError();
 
1910
    }
 
1911
    return item;
 
1912
}
 
1913
 
 
1914
static int __Pyx_EndUnpack(PyObject *iter) {
 
1915
    PyObject *item;
 
1916
    if ((item = PyIter_Next(iter))) {
 
1917
        Py_DECREF(item);
 
1918
        __Pyx_UnpackError();
 
1919
        return -1;
 
1920
    }
 
1921
    else if (!PyErr_Occurred())
 
1922
        return 0;
 
1923
    else
 
1924
        return -1;
 
1925
}
 
1926
 
 
1927
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
 
1928
    while (t->p) {
 
1929
        *t->p = PyString_InternFromString(t->s);
 
1930
        if (!*t->p)
 
1931
            return -1;
 
1932
        ++t;
 
1933
    }
 
1934
    return 0;
 
1935
}
 
1936
 
 
1937
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
 
1938
    while (t->p) {
 
1939
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
 
1940
        if (!*t->p)
 
1941
            return -1;
 
1942
        ++t;
 
1943
    }
 
1944
    return 0;
 
1945
}
 
1946
 
 
1947
#include "compile.h"
 
1948
#include "frameobject.h"
 
1949
#include "traceback.h"
 
1950
 
 
1951
static void __Pyx_AddTraceback(char *funcname) {
 
1952
    PyObject *py_srcfile = 0;
 
1953
    PyObject *py_funcname = 0;
 
1954
    PyObject *py_globals = 0;
 
1955
    PyObject *empty_tuple = 0;
 
1956
    PyObject *empty_string = 0;
 
1957
    PyCodeObject *py_code = 0;
 
1958
    PyFrameObject *py_frame = 0;
 
1959
    
 
1960
    py_srcfile = PyString_FromString(__pyx_filename);
 
1961
    if (!py_srcfile) goto bad;
 
1962
    py_funcname = PyString_FromString(funcname);
 
1963
    if (!py_funcname) goto bad;
 
1964
    py_globals = PyModule_GetDict(__pyx_m);
 
1965
    if (!py_globals) goto bad;
 
1966
    empty_tuple = PyTuple_New(0);
 
1967
    if (!empty_tuple) goto bad;
 
1968
    empty_string = PyString_FromString("");
 
1969
    if (!empty_string) goto bad;
 
1970
    py_code = PyCode_New(
 
1971
        0,            /*int argcount,*/
 
1972
        0,            /*int nlocals,*/
 
1973
        0,            /*int stacksize,*/
 
1974
        0,            /*int flags,*/
 
1975
        empty_string, /*PyObject *code,*/
 
1976
        empty_tuple,  /*PyObject *consts,*/
 
1977
        empty_tuple,  /*PyObject *names,*/
 
1978
        empty_tuple,  /*PyObject *varnames,*/
 
1979
        empty_tuple,  /*PyObject *freevars,*/
 
1980
        empty_tuple,  /*PyObject *cellvars,*/
 
1981
        py_srcfile,   /*PyObject *filename,*/
 
1982
        py_funcname,  /*PyObject *name,*/
 
1983
        __pyx_lineno,   /*int firstlineno,*/
 
1984
        empty_string  /*PyObject *lnotab*/
 
1985
    );
 
1986
    if (!py_code) goto bad;
 
1987
    py_frame = PyFrame_New(
 
1988
        PyThreadState_Get(), /*PyThreadState *tstate,*/
 
1989
        py_code,             /*PyCodeObject *code,*/
 
1990
        py_globals,          /*PyObject *globals,*/
 
1991
        0                    /*PyObject *locals*/
 
1992
    );
 
1993
    if (!py_frame) goto bad;
 
1994
    py_frame->f_lineno = __pyx_lineno;
 
1995
    PyTraceBack_Here(py_frame);
 
1996
bad:
 
1997
    Py_XDECREF(py_srcfile);
 
1998
    Py_XDECREF(py_funcname);
 
1999
    Py_XDECREF(empty_tuple);
 
2000
    Py_XDECREF(empty_string);
 
2001
    Py_XDECREF(py_code);
 
2002
    Py_XDECREF(py_frame);
 
2003
}