def getsockopt_int(self, level, option): flag_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw') try: flagsize_p = lltype.malloc(_c.socklen_t_ptr.TO, flavor='raw') try: flagsize_p[0] = rffi.cast(_c.socklen_t, rffi.sizeof(rffi.INT)) res = _c.socketgetsockopt(self.fd, level, option, rffi.cast(rffi.VOIDP, flag_p), flagsize_p) if res < 0: raise self.error_handler() result = rffi.cast(lltype.Signed, flag_p[0]) finally: lltype.free(flagsize_p, flavor='raw') finally: lltype.free(flag_p, flavor='raw') return result
def getsockopt(self, level, option, maxlen): buf = mallocbuf(maxlen) try: bufsize_p = lltype.malloc(_c.socklen_t_ptr.TO, flavor='raw') try: bufsize_p[0] = rffi.cast(_c.socklen_t, maxlen) res = _c.socketgetsockopt(self.fd, level, option, buf, bufsize_p) if res < 0: raise self.error_handler() size = rffi.cast(lltype.Signed, bufsize_p[0]) assert size >= 0 # socklen_t is signed on Windows result = ''.join([buf[i] for i in range(size)]) finally: lltype.free(bufsize_p, flavor='raw') finally: lltype.free(buf, flavor='raw') return result