This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: improve cygwin_attach_handle_to_fd()


On Oct  1 12:52, Basin Ilya wrote:
> Hi All.
> There's undocumented function cygwin_attach_handle_to_fd() , which is
> similar to Visual C _open_osfhandle() for wrapping Windows file handles.
> 
> I wanted to wrap a handle returned by CreateNamedPipe() using a custom
> tool running in background and then dup the fd to parent shell using
> exec 4</proc/$!/fd/4
> 
> I knew Cygwin internally used CreateNamedPipe() instead of CreatePipe()
> and hoped the idea would work. Unfortunately it didn't, mainly because
> cygwin_attach_handle_to_fd() calls some other windows functions on the
> handle, which is fine for normal files, but makes a connected pipe unusable.

I don't understand your scenario.  If /proc/$!/fd/4 exists, then the
custom tool is a Cygwin tool and cygwin_attach_handle_to_fd is never
called.

> Also for stealing a pipe handle via procfs, the fd should have a special
> name like "pipe:[652]". You cannot freely choose the name with
> cygwin_attach_handle_to_fd()
> 
> Do you think it is possible to add another function for wrapping native
> pipes and sockets? It could be less destructive for a hanlde, if it took
> all the needed info from its parameters instead of querying the hanlde.

I'm not positive on that.  From the Cygwin side the pipes and sockets
need specific setting, e.g., the pipe must be overlapped, the socket
nonblocking.  Cygwin_attach_handle_to_fd is only a band-aid.  It's
tricky to make sure the handle behaves correctly for the way they are
used inside Cygwin.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpTFydGaksnD.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]