Backport #4905

rb_w32_add_socket / rb_w32_remove_socket

Added by ghazel (Greg Hazel) about 9 years ago. Updated almost 3 years ago.



It is currently very difficult to use an externally created
SOCKET on Windows with ruby 1.8. Authors of all the gems I
found (pg, mysql2, curb) got it wrong. This bug is described
in detail here ( ). In
the meantime, a small pair of functions would allow gem authors
to use SOCKETs, without a significant rewrite of ruby's win32

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);
ruby_fd = fd;

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

#ifdef _WIN32


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.


add_socket.1_8.patch (906 Bytes) add_socket.1_8.patch ghazel (Greg Hazel), 06/19/2011 10:34 PM

Updated by luislavena (Luis Lavena) about 9 years ago

  • Category set to core
  • Assignee set to usa (Usaku NAKAMURA)

Updated by usa (Usaku NAKAMURA) about 9 years ago

  • Status changed from Open to Assigned

(Please wait for progress in trunk. )

Updated by usa (Usaku NAKAMURA) almost 3 years ago

  • Project changed from Ruby 1.8 to Backport186
  • Tracker changed from Feature to Backport

1.8 is out of date


Updated by usa (Usaku NAKAMURA) almost 3 years ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF