Project

General

Profile

Actions

Feature #4906

closed

rb_w32_add_socket / rb_w32_remove_socket

Added by ghazel (Greg Hazel) almost 13 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
[ruby-core:37227]

Description

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.


Files

add_socket.1_9.patch (1.29 KB) add_socket.1_9.patch ghazel (Greg Hazel), 06/19/2011 10:35 PM

Updated by luislavena (Luis Lavena) almost 13 years ago

  • Category set to core
  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version set to 1.9.3

Thank you Greg for the work on this.

I've assigned to Mr. Nobuyoshi Nakada, hoping this can be cleared out as a w32 API specific and be allowed in 1.9.3.

I don't think Yugui's schedule has been followed (or at least was delayed) so I'm hoping this could be into 1.9.3.

Thoughts?

Updated by luislavena (Luis Lavena) almost 13 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to usa (Usaku NAKAMURA)

Updated by usa (Usaku NAKAMURA) almost 13 years ago

  • Status changed from Open to Assigned
  • Target version changed from 1.9.3 to 2.0.0

1.9.3 feature is already freezed.
Wait next version, sorry.

Updated by jonforums (Jon Forums) over 12 years ago

Version concerns aside, do any mods need to be made, or does it appear to be OK as-is?

Updated by luislavena (Luis Lavena) over 12 years ago

Usaku NAKAMURA wrote:

1.9.3 feature is already freezed.
Wait next version, sorry.

Mr. Usaku Nakamura,

Similar to #4896 which is possible to include new features in curses for 1.9.3, can we make an exception for this too?

Asking this considering the amount of savings this new feature could provide to Ruby-C code in some extensions.

Not to mention make some of them actually work.

Thank you.

Updated by jonforums (Jon Forums) about 12 years ago

Is this planned to be included in 2.0.0?

Updated by usa (Usaku NAKAMURA) about 12 years ago

Is this planned to be included in 2.0.0?

Yes.
Thank you for your reminder.

Updated by usa (Usaku NAKAMURA) almost 12 years ago

Sorry to keep you waiting for a long time.
I've added rb_w32_wrap_io_handle() and rb_w32_unwrap_io_handle().

Although these APIs just like which you proposed, they support not only
sockets but also other I/O handles.

int fd = libwhatever_get_socket();
#ifdef _WIN32
ruby_fd = rb_w32_wraip_io_handle(fd, O_RDWR|O_BINARY|O_NOINHERIT);
#else
ruby_fd = fd;
#endif

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

#ifdef _WIN32
rb_w32_unwrap_io_handle(ruby_fd);
#endif
libwhatever_close_socket(fd);

Actions #9

Updated by usa (Usaku NAKAMURA) almost 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35938.
Greg, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ChangeLog: typo. [Feature #4906]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0