From: "usa (Usaku NAKAMURA)" <usa@...>
Date: 2012-03-28T00:16:02+09:00
Subject: [ruby-core:43749] [ruby-trunk - Feature #4906] rb_w32_add_socket / rb_w32_remove_socket


Issue #4906 has been updated by usa (Usaku NAKAMURA).


> Is this planned to be included in 2.0.0?

Yes.
Thank you for your reminder.
----------------------------------------
Feature #4906: rb_w32_add_socket / rb_w32_remove_socket
https://bugs.ruby-lang.org/issues/4906#change-25259

Author: ghazel (Greg Hazel)
Status: Assigned
Priority: Normal
Assignee: usa (Usaku NAKAMURA)
Category: core
Target version: 2.0.0


It is currently not possible to use an externally created
SOCKET on Windows with ruby 1.9. This bug is described in
detail here ( http://www.ruby-forum.com/topic/869239 ). In 
the meantime, a small pair of functions would allow gem
authors to use SOCKETs, without a significant rewrite of
ruby's win32 layer.

Attached is a very tiny patch for new functions which will
allow gem authors to use externally created sockets on Windows.
Their usage is as follows:

int fd = libwhatever_get_socket();
#ifdef _WIN32
 ruby_fd = rb_w32_add_socket(fd, 0);
#else
 ruby_fd = fd;
#endif

... do stuff with the ruby_fd as you would on other platforms ...

#ifdef _WIN32
 rb_w32_remove_socket(ruby_fd);
#endif

libwhatever_close_socket(fd);

In a nutshell; you pass the SOCKET given to you by the external
library to ruby and it gives you a CRT fd you can use with ruby
functions. When you're done, you pass that CRT fd to ruby to remove
it, and then close the SOCKET however the library normally does.

If the ifdefs are not preferred, rb_add_socket / rb_remove_socket
could be added as no-ops on non-win32 platforms, however I should
stress that making this a permanent fixture of the API is probably a
mistake, and the ruby win32 code should be rewritten to use
HANDLEs/SOCKETs instead of CRT fds. 


-- 
http://bugs.ruby-lang.org/