Feature #4906

rb_w32_add_socket / rb_w32_remove_socket

Added by Greg Hazel almost 3 years ago. Updated almost 2 years ago.

[ruby-core:37227]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA
Category:core
Target version:2.0.0

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 = libwhatevergetsocket();
#ifdef WIN32
ruby
fd = rbw32addsocket(fd, 0);
#else
ruby
fd = fd;
#endif

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

#ifdef WIN32
rb
w32removesocket(ruby_fd);
#endif

libwhateverclosesocket(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, rbaddsocket / rbremovesocket
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_9.patch Magnifier (1.29 KB) Greg Hazel, 06/19/2011 10:35 PM

Associated revisions

Revision 35938
Added by Usaku NAKAMURA almost 2 years ago

  • ChangeLog: typo. [Feature #4906]

History

#1 Updated by Luis Lavena almost 3 years ago

  • Category set to core
  • Assignee set to 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?

#2 Updated by Luis Lavena almost 3 years ago

  • Assignee changed from Nobuyoshi Nakada to Usaku NAKAMURA

#3 Updated by Usaku NAKAMURA almost 3 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.

#4 Updated by Jon Forums almost 3 years ago

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

#5 Updated by Luis Lavena almost 3 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.

#6 Updated by Jon Forums about 2 years ago

Is this planned to be included in 2.0.0?

#7 Updated by Usaku NAKAMURA about 2 years ago

Is this planned to be included in 2.0.0?

Yes.
Thank you for your reminder.

#8 Updated by Usaku NAKAMURA almost 2 years ago

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

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

int fd = libwhatevergetsocket();
#ifdef WIN32
ruby
fd = rbw32wraipiohandle(fd, ORDWR|OBINARY|ONOINHERIT);
#else
ruby
fd = fd;
#endif

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

#ifdef WIN32
rb
w32unwrapiohandle(rubyfd);
#endif
libwhateverclosesocket(fd);

#9 Updated by Usaku NAKAMURA almost 2 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]

Also available in: Atom PDF