def _get_page_size(): try: si = rffi.make(SYSTEM_INFO) GetSystemInfo(si) return int(si.c_dwPageSize) finally: lltype.free(si, flavor="raw")
def _get_allocation_granularity(): try: si = rffi.make(SYSTEM_INFO) GetSystemInfo(si) return int(si.c_dwAllocationGranularity) finally: lltype.free(si, flavor="raw")
def _select(self, for_writing): """Returns 0 when reading/writing is possible, 1 when timing out and -1 on error.""" timeout = self.timeout if timeout <= 0.0 or self.fd == _c.INVALID_SOCKET: # blocking I/O or no socket. return 0 tv = rffi.make(_c.timeval) rffi.setintfield(tv, 'c_tv_sec', int(timeout)) rffi.setintfield(tv, 'c_tv_usec', int((timeout-int(timeout)) * 1000000)) fds = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(fds) _c.FD_SET(self.fd, fds) null = lltype.nullptr(_c.fd_set.TO) if for_writing: n = _c.select(self.fd + 1, null, fds, null, tv) else: n = _c.select(self.fd + 1, fds, null, null, tv) lltype.free(fds, flavor='raw') lltype.free(tv, flavor='raw') if n < 0: return -1 if n == 0: return 1 return 0
def spawn(loop, process, file, args, env, streams): """ The file descriptor list should be a list of streams to wire up to FDs in the child. A None stream is mapped to UV_IGNORE. """ with rffi.scoped_str2charp(file) as rawFile: rawArgs = rffi.liststr2charpp(args) rawEnv = rffi.liststr2charpp(env) with rffi.scoped_str2charp(".") as rawCWD: options = rffi.make(cConfig["process_options_t"], c_file=rawFile, c_args=rawArgs, c_env=rawEnv, c_cwd=rawCWD) with lltype.scoped_alloc(rffi.CArray(stdio_container_t), len(streams)) as rawStreams: for i, stream in enumerate(streams): if stream == lltype.nullptr(stream_t): flags = UV_IGNORE else: flags = UV_CREATE_PIPE if i == 0: flags |= UV_READABLE_PIPE elif i in (1, 2): flags |= UV_WRITABLE_PIPE set_stdio_stream(rawStreams[i], stream) rffi.setintfield(rawStreams[i], "c_flags", flags) options.c_stdio = rawStreams rffi.setintfield(options, "c_stdio_count", len(streams)) add_exit_cb(options, processDiscard) rffi.setintfield(options, "c_flags", UV_PROCESS_WINDOWS_HIDE) rv = uv_spawn(loop, process, options) free(options) rffi.free_charpp(rawEnv) rffi.free_charpp(rawArgs) check("spawn", rv)
def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout): """Wait until one or more file descriptors are ready for some kind of I/O. The first three arguments are sequences of file descriptors to be waited for: rlist -- wait until ready for reading wlist -- wait until ready for writing xlist -- wait for an ``exceptional condition'' If only one kind of condition is required, pass [] for the other lists. A file descriptor is either a socket or file object, or a small integer gotten from a fileno() method call on one of those. The optional 4th argument specifies a timeout in seconds; it may be a floating point number to specify fractions of seconds. If it is absent or None, the call will never time out. The return value is a tuple of three lists corresponding to the first three arguments; each contains the subset of the corresponding file descriptors that are ready. *** IMPORTANT NOTICE *** On Windows, only sockets are supported; on Unix, all file descriptors. """ iwtd_w = space.listview(w_iwtd) owtd_w = space.listview(w_owtd) ewtd_w = space.listview(w_ewtd) if space.is_w(w_timeout, space.w_None): timeout = -1.0 else: timeout = space.float_w(w_timeout) ll_inl = lltype.nullptr(_c.fd_set.TO) ll_outl = lltype.nullptr(_c.fd_set.TO) ll_errl = lltype.nullptr(_c.fd_set.TO) ll_timeval = lltype.nullptr(_c.timeval) try: if len(iwtd_w) > 0: ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw') if len(owtd_w) > 0: ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw') if len(ewtd_w) > 0: ll_errl = lltype.malloc(_c.fd_set.TO, flavor='raw') if timeout >= 0.0: ll_timeval = rffi.make(_c.timeval) i = int(timeout) rffi.setintfield(ll_timeval, 'c_tv_sec', i) rffi.setintfield(ll_timeval, 'c_tv_usec', int((timeout-i)*1000000)) # Call this as a separate helper to avoid a large piece of code # in try:finally:. Needed for calling further _always_inline_ # helpers like _build_fd_set(). return _call_select(space, iwtd_w, owtd_w, ewtd_w, ll_inl, ll_outl, ll_errl, ll_timeval) finally: if ll_timeval: lltype.free(ll_timeval, flavor='raw') if ll_errl: lltype.free(ll_errl, flavor='raw') if ll_outl: lltype.free(ll_outl, flavor='raw') if ll_inl: lltype.free(ll_inl, flavor='raw')
def __init__(self, types): # self.thetape = [0] # self.position = 0 self.thetape = test test_object = rffi.make(TYPE_BFG_OBJECT, c_metadata=rffi.cast(rffi.ULONGLONG, 0), c_data=lltype.nullptr(rffi.VOIDP.TO)) test.c_objects = test_object
def select(inl, outl, excl, timeout=-1.0): nfds = 0 if inl: ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_inl) for i in inl: _c.FD_SET(i, ll_inl) if i > nfds: nfds = i else: ll_inl = lltype.nullptr(_c.fd_set.TO) if outl: ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_outl) for i in outl: _c.FD_SET(i, ll_outl) if i > nfds: nfds = i else: ll_outl = lltype.nullptr(_c.fd_set.TO) if excl: ll_excl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_excl) for i in excl: _c.FD_SET(i, ll_excl) if i > nfds: nfds = i else: ll_excl = lltype.nullptr(_c.fd_set.TO) if timeout != -1.0: ll_timeval = rffi.make(_c.timeval) rffi.setintfield(ll_timeval, 'c_tv_sec', int(timeout)) rffi.setintfield(ll_timeval, 'c_tv_usec', int((timeout-int(timeout)) * 1000000)) else: ll_timeval = lltype.nullptr(_c.timeval) try: res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval) if res == -1: raise SelectError(_c.geterrno()) if res == 0: return ([], [], []) else: return ( [i for i in inl if _c.FD_ISSET(i, ll_inl)], [i for i in outl if _c.FD_ISSET(i, ll_outl)], [i for i in excl if _c.FD_ISSET(i, ll_excl)]) finally: if ll_inl: lltype.free(ll_inl, flavor='raw') if ll_outl: lltype.free(ll_outl, flavor='raw') if ll_excl: lltype.free(ll_excl, flavor='raw') if ll_timeval: lltype.free(ll_timeval, flavor='raw')
def inet_ntoa(packed): "packet 32-bits string -> IPv4 dotted string" if len(packed) != sizeof(_c.in_addr): raise RSocketError("packed IP wrong length for inet_ntoa") buf = rffi.make(_c.in_addr) try: for i in range(sizeof(_c.in_addr)): rffi.cast(rffi.CCHARP, buf)[i] = packed[i] return rffi.charp2str(_c.inet_ntoa(buf)) finally: lltype.free(buf, flavor='raw')
def spawn(loop, process, file, args, env): with rffi.scoped_str2charp(file) as rawFile: rawArgs = rffi.liststr2charpp(args) rawEnv = rffi.liststr2charpp(env) with rffi.scoped_str2charp(".") as rawCWD: options = rffi.make(cConfig["process_options_t"], c_file=rawFile, c_args=rawArgs, c_env=rawEnv, c_cwd=rawCWD) add_exit_cb(options, processDiscard) rffi.setintfield(options, "c_flags", UV_PROCESS_WINDOWS_HIDE) rffi.setintfield(options, "c_stdio_count", 0) rv = uv_spawn(loop, process, options) free(options) rffi.free_charpp(rawEnv) rffi.free_charpp(rawArgs) check("spawn", rv)
def spawn(loop, process, file, args, env, streams): """ The file descriptor list should be a list of streams to wire up to FDs in the child. A None stream is mapped to UV_IGNORE. """ with rffi.scoped_str2charp(file) as rawFile: rawArgs = rffi.liststr2charpp(args) rawEnv = rffi.liststr2charpp(env) with rffi.scoped_str2charp(".") as rawCWD: options = rffi.make(cConfig["process_options_t"], c_file=rawFile, c_args=rawArgs, c_env=rawEnv, c_cwd=rawCWD) with lltype.scoped_alloc(rffi.CArray(stdio_container_t), len(streams)) as rawStreams: for i, stream in enumerate(streams): if stream == lltype.nullptr(stream_t): flags = UV_IGNORE else: flags = UV_CREATE_PIPE if i == 0: flags |= UV_READABLE_PIPE elif i in (1, 2): flags |= UV_WRITABLE_PIPE if not we_are_translated(): # doing extra allocations here to work around ll2ctypes' # desire to gratuitously copy arrays with lltype.scoped_alloc(stdio_container_t) as con: set_stdio_stream(con, stream) for field in rawStreams[i]._T._names: setattr(rawStreams[i], field, getattr(con, field)) else: set_stdio_stream(rawStreams[i], stream) rffi.setintfield(rawStreams[i], "c_flags", flags) options.c_stdio = rawStreams rffi.setintfield(options, "c_stdio_count", len(streams)) add_exit_cb(options, processDiscard) # On Windows, ask to *not* have one of those annoying # console/terminal windows pop up. ~ C. rffi.setintfield(options, "c_flags", UV_PROCESS_WINDOWS_HIDE) rv = uv_spawn(loop, process, options) free(options) rffi.free_charpp(rawEnv) rffi.free_charpp(rawArgs) check("spawn", rv)
def _connect(self, address): """Connect the socket to a remote address.""" addr = address.lock() res = _c.socketconnect(self.fd, addr, address.addrlen) address.unlock() errno = _c.geterrno() timeout = self.timeout if timeout > 0.0 and res < 0 and errno == _c.EWOULDBLOCK: tv = rffi.make(_c.timeval) rffi.setintfield(tv, 'c_tv_sec', int(timeout)) rffi.setintfield(tv, 'c_tv_usec', int((timeout-int(timeout)) * 1000000)) fds = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(fds) _c.FD_SET(self.fd, fds) fds_exc = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(fds_exc) _c.FD_SET(self.fd, fds_exc) null = lltype.nullptr(_c.fd_set.TO) try: n = _c.select(self.fd + 1, null, fds, fds_exc, tv) if n > 0: if _c.FD_ISSET(self.fd, fds): # socket writable == connected return (0, False) else: # per MS docs, call getsockopt() to get error assert _c.FD_ISSET(self.fd, fds_exc) return (self.getsockopt_int(_c.SOL_SOCKET, _c.SO_ERROR), False) elif n == 0: return (_c.EWOULDBLOCK, True) else: return (_c.geterrno(), False) finally: lltype.free(fds, flavor='raw') lltype.free(fds_exc, flavor='raw') lltype.free(tv, flavor='raw') if res == 0: errno = 0 return (errno, False)
def _select(self, for_writing): """Returns 0 when reading/writing is possible, 1 when timing out and -1 on error.""" if self.timeout <= 0.0 or self.fd == _c.INVALID_SOCKET: # blocking I/O or no socket. return 0 pollfd = rffi.make(_c.pollfd) try: rffi.setintfield(pollfd, "c_fd", self.fd) if for_writing: rffi.setintfield(pollfd, "c_events", _c.POLLOUT) else: rffi.setintfield(pollfd, "c_events", _c.POLLIN) timeout = int(self.timeout * 1000.0 + 0.5) n = _c.poll(rffi.cast(lltype.Ptr(_c.pollfdarray), pollfd), 1, timeout) finally: lltype.free(pollfd, flavor="raw") if n < 0: return -1 if n == 0: return 1 return 0
def _select(self, for_writing): """Returns 0 when reading/writing is possible, 1 when timing out and -1 on error.""" if self.timeout <= 0.0 or self.fd == _c.INVALID_SOCKET: # blocking I/O or no socket. return 0 pollfd = rffi.make(_c.pollfd) try: rffi.setintfield(pollfd, 'c_fd', self.fd) if for_writing: rffi.setintfield(pollfd, 'c_events', _c.POLLOUT) else: rffi.setintfield(pollfd, 'c_events', _c.POLLIN) timeout = int(self.timeout * 1000.0 + 0.5) n = _c.poll(rffi.cast(lltype.Ptr(_c.pollfdarray), pollfd), 1, timeout) finally: lltype.free(pollfd, flavor='raw') if n < 0: return -1 if n == 0: return 1 return 0
def select(inl, outl, excl, timeout=-1.0, handle_eintr=False): nfds = 0 if inl: ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_inl) for i in inl: _c.FD_SET(i, ll_inl) if i > nfds: nfds = i else: ll_inl = lltype.nullptr(_c.fd_set.TO) if outl: ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_outl) for i in outl: _c.FD_SET(i, ll_outl) if i > nfds: nfds = i else: ll_outl = lltype.nullptr(_c.fd_set.TO) if excl: ll_excl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_excl) for i in excl: _c.FD_SET(i, ll_excl) if i > nfds: nfds = i else: ll_excl = lltype.nullptr(_c.fd_set.TO) if timeout < 0: ll_timeval = lltype.nullptr(_c.timeval) while True: res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval) if not handle_eintr or res >= 0 or _c.geterrno() != EINTR: break else: sec = int(timeout) usec = int((timeout - sec) * 10**6) ll_timeval = rffi.make(_c.timeval) rffi.setintfield(ll_timeval, 'c_tv_sec', sec) rffi.setintfield(ll_timeval, 'c_tv_usec', usec) res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval) if handle_eintr and res < 0 and _c.geterrno() == EINTR: res = 0 # interrupted, act as timed out try: if res == -1: raise SelectError(_c.geterrno()) if res == 0: return ([], [], []) else: return ( [i for i in inl if _c.FD_ISSET(i, ll_inl)], [i for i in outl if _c.FD_ISSET(i, ll_outl)], [i for i in excl if _c.FD_ISSET(i, ll_excl)]) finally: if ll_inl: lltype.free(ll_inl, flavor='raw') if ll_outl: lltype.free(ll_outl, flavor='raw') if ll_excl: lltype.free(ll_excl, flavor='raw') if ll_timeval: lltype.free(ll_timeval, flavor='raw')
def alloc_mq_attr(): return rffi.make(mq_attr)
def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout): """Wait until one or more file descriptors are ready for some kind of I/O. The first three arguments are sequences of file descriptors to be waited for: rlist -- wait until ready for reading wlist -- wait until ready for writing xlist -- wait for an ``exceptional condition'' If only one kind of condition is required, pass [] for the other lists. A file descriptor is either a socket or file object, or a small integer gotten from a fileno() method call on one of those. The optional 4th argument specifies a timeout in seconds; it may be a floating point number to specify fractions of seconds. If it is absent or None, the call will never time out. The return value is a tuple of three lists corresponding to the first three arguments; each contains the subset of the corresponding file descriptors that are ready. *** IMPORTANT NOTICE *** On Windows, only sockets are supported; on Unix, all file descriptors. """ iwtd_w = space.unpackiterable(w_iwtd) owtd_w = space.unpackiterable(w_owtd) ewtd_w = space.unpackiterable(w_ewtd) if space.is_w(w_timeout, space.w_None): timeout = -1.0 else: timeout = space.float_w(w_timeout) ll_inl = lltype.nullptr(_c.fd_set.TO) ll_outl = lltype.nullptr(_c.fd_set.TO) ll_errl = lltype.nullptr(_c.fd_set.TO) ll_timeval = lltype.nullptr(_c.timeval) try: if len(iwtd_w) > 0: ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw') if len(owtd_w) > 0: ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw') if len(ewtd_w) > 0: ll_errl = lltype.malloc(_c.fd_set.TO, flavor='raw') if timeout >= 0.0: ll_timeval = rffi.make(_c.timeval) i = int(timeout) rffi.setintfield(ll_timeval, 'c_tv_sec', i) rffi.setintfield(ll_timeval, 'c_tv_usec', int((timeout - i) * 1000000)) # Call this as a separate helper to avoid a large piece of code # in try:finally:. Needed for calling further _always_inline_ # helpers like _build_fd_set(). return _call_select(space, iwtd_w, owtd_w, ewtd_w, ll_inl, ll_outl, ll_errl, ll_timeval) finally: if ll_timeval: lltype.free(ll_timeval, flavor='raw') if ll_errl: lltype.free(ll_errl, flavor='raw') if ll_outl: lltype.free(ll_outl, flavor='raw') if ll_inl: lltype.free(ll_inl, flavor='raw')
def poll(fddict, timeout=-1): """'fddict' maps file descriptors to interesting events. 'timeout' is an integer in milliseconds, and NOT a float number of seconds, but it's the same in CPython. Use -1 for infinite. Returns a list [(fd, events)]. """ numfd = len(fddict) numevents = 0 socketevents = lltype.malloc(_c.WSAEVENT_ARRAY, numfd, flavor='raw') try: eventdict = {} for fd, events in fddict.iteritems(): # select desired events wsaEvents = 0 if events & _c.POLLIN: wsaEvents |= _c.FD_READ | _c.FD_ACCEPT | _c.FD_CLOSE if events & _c.POLLOUT: wsaEvents |= _c.FD_WRITE | _c.FD_CONNECT | _c.FD_CLOSE # if no events then ignore socket if wsaEvents == 0: continue # select socket for desired events event = _c.WSACreateEvent() if _c.WSAEventSelect(fd, event, wsaEvents) != 0: raise PollError(_c.geterrno()) eventdict[fd] = event socketevents[numevents] = event numevents += 1 assert numevents <= numfd # if no sockets then return immediately # XXX commented out by arigo - we just want to sleep for # 'timeout' milliseconds in this case, which is what # I hope WSAWaitForMultipleEvents will do, no? #if numevents == 0: # return [] # prepare timeout if timeout < 0: timeout = _c.INFINITE ret = _c.WSAWaitForMultipleEvents(numevents, socketevents, False, timeout, False) if ret == _c.WSA_WAIT_TIMEOUT: return [] if ret == r_uint(_c.WSA_WAIT_FAILED): raise PollError(_c.geterrno()) retval = [] info = rffi.make(_c.WSANETWORKEVENTS) for fd, event in eventdict.iteritems(): if _c.WSAEnumNetworkEvents(fd, event, info) < 0: continue revents = 0 if info.c_lNetworkEvents & _c.FD_READ: revents |= _c.POLLIN if info.c_lNetworkEvents & _c.FD_ACCEPT: revents |= _c.POLLIN if info.c_lNetworkEvents & _c.FD_WRITE: revents |= _c.POLLOUT if info.c_lNetworkEvents & _c.FD_CONNECT: if info.c_iErrorCode[_c.FD_CONNECT_BIT]: revents |= _c.POLLERR else: revents |= _c.POLLOUT if info.c_lNetworkEvents & _c.FD_CLOSE: if info.c_iErrorCode[_c.FD_CLOSE_BIT]: revents |= _c.POLLERR else: if fddict[fd] & _c.POLLIN: revents |= _c.POLLIN if fddict[fd] & _c.POLLOUT: revents |= _c.POLLOUT if revents: retval.append((fd, revents)) lltype.free(info, flavor='raw') finally: for fd, event in eventdict.iteritems(): _c.WSAEventSelect(fd, event, 0) _c.WSACloseEvent(event) lltype.free(socketevents, flavor='raw') return retval
def select(inl, outl, excl, timeout=-1.0, handle_eintr=False): nfds = 0 if inl: ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_inl) for i in inl: _c.FD_SET(i, ll_inl) if i > nfds: nfds = i else: ll_inl = lltype.nullptr(_c.fd_set.TO) if outl: ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_outl) for i in outl: _c.FD_SET(i, ll_outl) if i > nfds: nfds = i else: ll_outl = lltype.nullptr(_c.fd_set.TO) if excl: ll_excl = lltype.malloc(_c.fd_set.TO, flavor='raw') _c.FD_ZERO(ll_excl) for i in excl: _c.FD_SET(i, ll_excl) if i > nfds: nfds = i else: ll_excl = lltype.nullptr(_c.fd_set.TO) if timeout < 0: ll_timeval = lltype.nullptr(_c.timeval) while True: res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval) if not handle_eintr or res >= 0 or _c.geterrno() != EINTR: break else: sec = int(timeout) usec = int((timeout - sec) * 10**6) ll_timeval = rffi.make(_c.timeval) rffi.setintfield(ll_timeval, 'c_tv_sec', sec) rffi.setintfield(ll_timeval, 'c_tv_usec', usec) res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval) if handle_eintr and res < 0 and _c.geterrno() == EINTR: res = 0 # interrupted, act as timed out try: if res == -1: raise SelectError(_c.geterrno()) if res == 0: return ([], [], []) else: return ([i for i in inl if _c.FD_ISSET(i, ll_inl) ], [i for i in outl if _c.FD_ISSET(i, ll_outl)], [i for i in excl if _c.FD_ISSET(i, ll_excl)]) finally: if ll_inl: lltype.free(ll_inl, flavor='raw') if ll_outl: lltype.free(ll_outl, flavor='raw') if ll_excl: lltype.free(ll_excl, flavor='raw') if ll_timeval: lltype.free(ll_timeval, flavor='raw')
def _poll(fddict, timeout=-1): """'fddict' maps file descriptors to interesting events. 'timeout' is an integer in milliseconds, and NOT a float number of seconds, but it's the same in CPython. Use -1 for infinite. Returns a list [(fd, events)]. """ numfd = len(fddict) numevents = 0 socketevents = lltype.malloc(_c.WSAEVENT_ARRAY, numfd, flavor='raw') try: eventdict = {} for fd, events in fddict.iteritems(): # select desired events wsaEvents = 0 if events & _c.POLLIN: wsaEvents |= _c.FD_READ | _c.FD_ACCEPT | _c.FD_CLOSE if events & _c.POLLOUT: wsaEvents |= _c.FD_WRITE | _c.FD_CONNECT | _c.FD_CLOSE # if no events then ignore socket if wsaEvents == 0: continue # select socket for desired events event = _c.WSACreateEvent() if _c.WSAEventSelect(fd, event, wsaEvents) != 0: raise PollError(_c.geterrno()) eventdict[fd] = event socketevents[numevents] = event numevents += 1 assert numevents <= numfd # if no sockets then return immediately # XXX commented out by arigo - we just want to sleep for # 'timeout' milliseconds in this case, which is what # I hope WSAWaitForMultipleEvents will do, no? #if numevents == 0: # return [] # prepare timeout if timeout < 0: timeout = _c.INFINITE # XXX does not correctly report write status of a port ret = _c.WSAWaitForMultipleEvents(numevents, socketevents, False, timeout, False) if ret == _c.WSA_WAIT_TIMEOUT: return [] if ret == r_uint(_c.WSA_WAIT_FAILED): raise PollError(_c.geterrno()) retval = [] info = rffi.make(_c.WSANETWORKEVENTS) for fd, event in eventdict.iteritems(): if _c.WSAEnumNetworkEvents(fd, event, info) < 0: continue revents = 0 if info.c_lNetworkEvents & _c.FD_READ: revents |= _c.POLLIN if info.c_lNetworkEvents & _c.FD_ACCEPT: revents |= _c.POLLIN if info.c_lNetworkEvents & _c.FD_WRITE: revents |= _c.POLLOUT if info.c_lNetworkEvents & _c.FD_CONNECT: if info.c_iErrorCode[_c.FD_CONNECT_BIT]: revents |= _c.POLLERR else: revents |= _c.POLLOUT if info.c_lNetworkEvents & _c.FD_CLOSE: if info.c_iErrorCode[_c.FD_CLOSE_BIT]: revents |= _c.POLLERR else: if fddict[fd] & _c.POLLIN: revents |= _c.POLLIN if fddict[fd] & _c.POLLOUT: revents |= _c.POLLOUT if revents: retval.append((fd, revents)) lltype.free(info, flavor='raw') finally: for fd, event in eventdict.iteritems(): _c.WSAEventSelect(fd, event, 0) _c.WSACloseEvent(event) lltype.free(socketevents, flavor='raw') return retval
('GUID_high', rffi.ULONGLONG), ('GUID_low', rffi.ULONGLONG), ('index', rffi.ULONGLONG), ('length', rffi.ULONGLONG), ('alloc_length', rffi.ULONGLONG), ('objects', TYPE_BFG_OBJECT_PTR)) TYPE_BFG_TYPE_SPACE_PTR = lltype.Ptr(TYPE_BFG_TYPE_SPACE) TYPE_BFG_TAPE_ARRAY = rffi.CArray(TYPE_BFG_TYPE_SPACE_PTR) aa = lltype.malloc(TYPE_BFG_TAPE_ARRAY, 1, flavor='raw') aa[0] = lltype.malloc(TYPE_BFG_TYPE_SPACE, flavor='raw') test = rffi.make(TYPE_BFG_TYPE_SPACE, c_GUID_high=rffi.cast(rffi.ULONG, INTEGER[0]),#1), c_GUID_low=rffi.cast(rffi.ULONG, 1), c_length=rffi.cast(rffi.ULONG, 1), c_index=rffi.cast(rffi.ULONG, 0), c_alloc_length=rffi.cast(rffi.ULONG, 1)) # test.c_objects = lltype.nullptr(TYPE_BFG_OBJECT_PTR.TO) test_object = rffi.make(TYPE_BFG_OBJECT, c_metadata=rffi.cast(rffi.ULONGLONG, 0), c_data=lltype.nullptr(rffi.VOIDP.TO)) test.c_objects = test_object #testb = lltype.malloc(TYPE_BFG_OBJECT_ARRAY, 2, flavor='raw') #testb[0].c_metadata = rffi.cast(rffi.ULONGLONG, 0)#20) #testb[1].c_metadata = rffi.cast(rffi.ULONGLONG, 0)#43) #test.c_objects = rffi.cast(TYPE_BFG_OBJECT_PTR, testb) external_function2 = rffi.llexternal('bfg_execute', [rffi.ULONGLONG,