mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fix socket closing by using closesocket API in windows instead.
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
2300c9f737
commit
949bf6ca43
@@ -15,7 +15,8 @@ struct mrb_io {
|
||||
int pid; /* child's pid (for pipes) */
|
||||
unsigned int readable:1,
|
||||
writable:1,
|
||||
sync:1;
|
||||
sync:1,
|
||||
is_socket:1;
|
||||
};
|
||||
|
||||
#define FMODE_READABLE 0x00000001
|
||||
|
||||
@@ -578,8 +578,18 @@ fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int quiet)
|
||||
}
|
||||
|
||||
if (fptr->fd > 2) {
|
||||
if (close(fptr->fd) == -1) {
|
||||
saved_errno = errno;
|
||||
#ifdef _WIN32
|
||||
if (fptr->is_socket) {
|
||||
if (closesocket(fptr->fd) != 0) {
|
||||
saved_errno = WSAGetLastError();
|
||||
}
|
||||
fptr->fd = -1;
|
||||
}
|
||||
#endif
|
||||
if (fptr->fd != -1) {
|
||||
if (close(fptr->fd) == -1) {
|
||||
saved_errno = errno;
|
||||
}
|
||||
}
|
||||
fptr->fd = -1;
|
||||
}
|
||||
|
||||
@@ -178,6 +178,7 @@ class BasicSocket
|
||||
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
self.is_socket = true
|
||||
@do_not_reverse_lookup = @@do_not_reverse_lookup
|
||||
end
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "mruby/variable.h"
|
||||
#include "error.h"
|
||||
|
||||
#include "mruby/ext/io.h"
|
||||
|
||||
#define E_SOCKET_ERROR (mrb_class_get(mrb, "SocketError"))
|
||||
|
||||
#if !defined(mrb_cptr)
|
||||
@@ -479,6 +481,21 @@ mrb_basicsocket_shutdown(mrb_state *mrb, mrb_value self)
|
||||
return mrb_fixnum_value(0);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_basicsocket_set_is_socket(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_bool b;
|
||||
struct mrb_io *io_p;
|
||||
mrb_get_args(mrb, "b", &b);
|
||||
|
||||
io_p = (struct mrb_io*)DATA_PTR(self);
|
||||
if (io_p) {
|
||||
io_p->is_socket = b;
|
||||
}
|
||||
|
||||
return mrb_bool_value(b);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_ipsocket_ntop(mrb_state *mrb, mrb_value klass)
|
||||
{
|
||||
@@ -839,6 +856,7 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
|
||||
// #sendmsg_nonblock
|
||||
mrb_define_method(mrb, bsock, "setsockopt", mrb_basicsocket_setsockopt, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(2));
|
||||
mrb_define_method(mrb, bsock, "shutdown", mrb_basicsocket_shutdown, MRB_ARGS_OPT(1));
|
||||
mrb_define_method(mrb, bsock, "is_socket=", mrb_basicsocket_set_is_socket, MRB_ARGS_REQ(1));
|
||||
|
||||
ipsock = mrb_define_class(mrb, "IPSocket", bsock);
|
||||
mrb_define_class_method(mrb, ipsock, "ntop", mrb_ipsocket_ntop, MRB_ARGS_REQ(1));
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
unless SocketTest.win?
|
||||
|
||||
def unixserver_test_block
|
||||
path = SocketTest.tmppath
|
||||
File.unlink path rescue nil
|
||||
@@ -126,5 +124,3 @@ assert('UNIXSocket#recvfrom') do
|
||||
# a[1][1] would be "" or something
|
||||
end
|
||||
end
|
||||
|
||||
end # win?
|
||||
|
||||
Reference in New Issue
Block a user