mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/fiddle] windows: add Fiddle.win32_last_socket_error{,=}
GitHub: fix GH-72
Users can't use WSAGetLastError() with Ruby 3.0 or later because
rb_funcall() resets the last socket error internally.
Users can get the last socket error by Fiddle.win32_last_socket_error.
Reported by Kentaro Hayashi. Thanks!!!
76158db00a
This commit is contained in:
parent
2579593a56
commit
71d4a493b8
Notes:
git
2021-05-18 12:49:03 +09:00
2 changed files with 21 additions and 2 deletions
|
|
@ -375,10 +375,17 @@ function_call(int argc, VALUE argv[], VALUE self)
|
|||
(void)rb_thread_call_without_gvl(nogvl_ffi_call, &args, 0, 0);
|
||||
}
|
||||
|
||||
rb_funcall(mFiddle, rb_intern("last_error="), 1, INT2NUM(errno));
|
||||
{
|
||||
int errno_keep = errno;
|
||||
#if defined(_WIN32)
|
||||
rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, INT2NUM(errno));
|
||||
int socket_error = WSAGetLastError();
|
||||
rb_funcall(mFiddle, rb_intern("win32_last_error="), 1,
|
||||
INT2NUM(errno_keep));
|
||||
rb_funcall(mFiddle, rb_intern("win32_last_socket_error="), 1,
|
||||
INT2NUM(socket_error));
|
||||
#endif
|
||||
rb_funcall(mFiddle, rb_intern("last_error="), 1, INT2NUM(errno_keep));
|
||||
}
|
||||
|
||||
ALLOCV_END(alloc_buffer);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,18 @@ module Fiddle
|
|||
def self.win32_last_error= error
|
||||
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
|
||||
end
|
||||
|
||||
# Returns the last win32 socket +Error+ of the current executing
|
||||
# +Thread+ or nil if none
|
||||
def self.win32_last_socket_error
|
||||
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__]
|
||||
end
|
||||
|
||||
# Sets the last win32 socket +Error+ of the current executing
|
||||
# +Thread+ to +error+
|
||||
def self.win32_last_socket_error= error
|
||||
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the last +Error+ of the current executing +Thread+ or nil if none
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue