简体   繁体   中英

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);    

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM