Commit 437bbd56 authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang/gevent: Adjust to support Windows

On Windows rthere is no fcntl

    golang/runtime\_runtime_gevent.cpp(4811): error C3861: 'S_ISBLK': identifier not found
    golang/runtime\_runtime_gevent.cpp(4823): error C2039: 'Fcntl': is not a member of 'golang::internal::syscall'
    .\golang/runtime/internal/syscall.h(36): note: see declaration of 'golang::internal::syscall'
    golang/runtime\_runtime_gevent.cpp(4823): error C2065: 'F_GETFL': undeclared identifier
    golang/runtime\_runtime_gevent.cpp(4823): error C3861: 'Fcntl': identifier not found
    golang/runtime\_runtime_gevent.cpp(4870): error C2065: 'O_ACCMODE': undeclared identifier
    golang/runtime\_runtime_gevent.cpp(4889): error C2039: 'Fcntl': is not a member of 'golang::internal::syscall'
    .\golang/runtime/internal/syscall.h(36): note: see declaration of 'golang::internal::syscall'
    golang/runtime\_runtime_gevent.cpp(4889): error C2065: 'F_SETFL': undeclared identifier
    golang/runtime\_runtime_gevent.cpp(4889): error C2065: 'O_NONBLOCK': undeclared identifier
    golang/runtime\_runtime_gevent.cpp(4889): error C3861: 'Fcntl': identifier not found

and even if there would be gevent does not provide cooperative version
of FileObject for non-POSIX platforms.

-> Always use FileObjectThread on windows even for pipes.
parent 45473979
# cython: language_level=2 # cython: language_level=2
# Copyright (C) 2019-2022 Nexedi SA and Contributors. # Copyright (C) 2019-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -57,7 +57,7 @@ from posix.fcntl cimport mode_t, F_GETFL, F_SETFL, O_NONBLOCK, O_ACCMODE, O_RDON ...@@ -57,7 +57,7 @@ from posix.fcntl cimport mode_t, F_GETFL, F_SETFL, O_NONBLOCK, O_ACCMODE, O_RDON
from posix.stat cimport struct_stat, S_ISREG, S_ISDIR, S_ISBLK from posix.stat cimport struct_stat, S_ISREG, S_ISDIR, S_ISBLK
from posix.strings cimport bzero from posix.strings cimport bzero
from gevent.fileobject import FileObjectThread, FileObjectPosix from gevent import fileobject as gfileobj
# _goviapy & _togo serve go # _goviapy & _togo serve go
...@@ -194,6 +194,7 @@ cdef nogil: ...@@ -194,6 +194,7 @@ cdef nogil:
return ioh return ioh
_libgolang_ioh* _io_fdopen(int *out_syserr, int sysfd): _libgolang_ioh* _io_fdopen(int *out_syserr, int sysfd):
IF POSIX:
# check if we should enable O_NONBLOCK on this file-descriptor # check if we should enable O_NONBLOCK on this file-descriptor
# even though we could enable O_NONBLOCK for regular files, it does not # even though we could enable O_NONBLOCK for regular files, it does not
# work as expected as most unix'es report regular files as always read # work as expected as most unix'es report regular files as always read
...@@ -220,6 +221,13 @@ cdef nogil: ...@@ -220,6 +221,13 @@ cdef nogil:
out_syserr[0] = syserr out_syserr[0] = syserr
return NULL return NULL
ELSE: # !POSIX (windows)
cdef bint blocking = True
# FIXME acc: use GetFileInformationByHandleEx to determine whether
# HANDLE(sysfd) was opened for reading or writing.
# https://stackoverflow.com/q/9442436/9456786
cdef int acc = O_RDWR
# create IOH backed by FileObjectThread or FileObjectPosix # create IOH backed by FileObjectThread or FileObjectPosix
ioh = <IOH*>calloc(1, sizeof(IOH)) ioh = <IOH*>calloc(1, sizeof(IOH))
if ioh == NULL: if ioh == NULL:
...@@ -253,9 +261,9 @@ cdef: ...@@ -253,9 +261,9 @@ cdef:
pygfobj = None pygfobj = None
try: try:
if blocking: if blocking:
pygfobj = FileObjectThread(sysfd, mode=mode, buffering=0) pygfobj = gfileobj.FileObjectThread(sysfd, mode=mode, buffering=0)
else: else:
pygfobj = FileObjectPosix(sysfd, mode=mode, buffering=0) pygfobj = gfileobj.FileObjectPosix(sysfd, mode=mode, buffering=0)
except OSError as e: except OSError as e:
out_syserr[0] = -e.errno out_syserr[0] = -e.errno
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment