Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a HANDLE to File Descriptor

I have a HANDLE like that:

HANDLE hPipe = CreateNamedPipe(...)

Is possible to convert the hPipe to a File Descriptor (int)?

I need this because I have implemented in C++ a code to work with TLS using the OpenSSL. This is working like a charm with TCP sockets, but I really need use it over Namedpipe.

The OpenSSL's function SSL_set_fd(SSL *ssl, int fd) accepts just FileDescriptor that is a int, and not a HANDLE.

Note: I also tried use the below function, but doesn't worked (return 3):

int fd = _open_osfhandle(reinterpret_cast<intptr_t>(hPipe), 0);    
like image 529
user2538743 Avatar asked Sep 10 '25 22:09

user2538743


1 Answers

The 3 you're getting back isn't an error, it's the file descriptor handle. If you look at the documentation you'll see that it returns -1 for failure, otherwise the return value is a file descriptor.

like image 80
Sean Avatar answered Sep 13 '25 15:09

Sean