Debian Codegraph @

pypy/module/_multiprocessing/interp_win32_py3.py

raw symbols SCIP
1 from rpython.rtyper.lltypesystem import rffi
2 from rpython.rlib._rsocket_rffi import socketclose, geterrno, socketrecv, send
3 from rpython.rlib import rwin32
4 from pypy.interpreter.error import OperationError
5 from pypy.interpreter.gateway import unwrap_spec
6
7 def getWindowsError(space):
8 errno = geterrno()
9 message = rwin32.FormatErrorW(errno)
10 w_errcode = space.newint(errno)
11 return OperationError(space.w_WindowsError,
12 space.newtuple([w_errcode, space.newtext(*message),
13 space.w_None, w_errcode]))
14
15 @unwrap_spec(handle=int)
16 def multiprocessing_closesocket(space, handle):
17 res = socketclose(handle)
18 if res != 0:
19 raise getWindowsError(space)
20
21 @unwrap_spec(handle=int, buffersize=int)
22 def multiprocessing_recv(space, handle, buffersize):
23 with rffi.scoped_alloc_buffer(buffersize) as buf:
24 read_bytes = socketrecv(handle, buf.raw, buffersize, 0)
25 if read_bytes >= 0:
26 return space.newbytes(buf.str(read_bytes))
27 raise getWindowsError(space)
28
29 @unwrap_spec(handle=int, data='bufferstr')
30 def multiprocessing_send(space, handle, data):
31 if data is None:
32 raise OperationError(space.w_ValueError, 'data cannot be None')
33 with rffi.scoped_nonmovingbuffer(data) as dataptr:
34 # rsocket checks for writability of socket with wait_for_data, cpython does check
35 res = send(handle, dataptr, len(data), 0)
36 if res < 0:
37 raise getWindowsError(space)
38 return space.newint(res)
39
40 def handle_w(space, w_handle):
41 return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))
42
43 _GetTickCount = rwin32.winexternal(
44 'GetTickCount', [], rwin32.DWORD)
45