Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
a426f0e2
Commit
a426f0e2
authored
Jul 18, 2015
by
Rubyist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overrided close and write to work on Win32 platforms
parent
752f7c15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
src/socket.c
src/socket.c
+37
-0
No files found.
src/socket.c
View file @
a426f0e2
...
...
@@ -649,6 +649,37 @@ mrb_tcpsocket_allocate(mrb_state *mrb, mrb_value klass)
return
mrb_obj_value
((
struct
RObject
*
)
mrb_obj_alloc
(
mrb
,
ttype
,
c
));
}
/* Windows overrides for IO methods on BasicSocket objects.
* This is because sockets on Windows are not the same as file
* descriptors, and thus functions which operate on file descriptors
* will break on socket descriptors.
*/
#ifdef _WIN32
static
mrb_value
mrb_win32_basicsocket_close
(
mrb_state
*
mrb
,
mrb_value
self
)
{
if
(
closesocket
(
socket_fd
(
mrb
,
self
))
!=
NO_ERROR
)
mrb_sys_fail
(
mrb
,
"closesocket"
);
return
mrb_nil_value
();
}
static
mrb_value
mrb_win32_basicsocket_write
(
mrb_state
*
mrb
,
mrb_value
self
)
{
int
n
;
SOCKET
sd
;
mrb_value
str
;
sd
=
socket_fd
(
mrb
,
self
);
mrb_get_args
(
mrb
,
"S"
,
&
str
);
n
=
send
(
sd
,
RSTRING_PTR
(
str
),
RSTRING_LEN
(
str
),
0
);
if
(
n
==
SOCKET_ERROR
)
mrb_sys_fail
(
mrb
,
"write"
);
return
mrb_fixnum_value
(
n
);
}
#endif
void
mrb_mruby_socket_gem_init
(
mrb_state
*
mrb
)
{
...
...
@@ -728,6 +759,12 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
//mrb_define_method(mrb, usock, "recvfrom", mrb_unixsocket_peeraddr, MRB_ARGS_NONE());
//mrb_define_method(mrb, usock, "send_io", mrb_unixsocket_peeraddr, MRB_ARGS_NONE());
/* Windows IO Method Overrides on BasicSocket */
#ifdef _WIN32
mrb_define_method
(
mrb
,
bsock
,
"close"
,
mrb_win32_basicsocket_close
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
bsock
,
"write"
,
mrb_win32_basicsocket_write
,
MRB_ARGS_REQ
(
1
));
#endif
constants
=
mrb_define_module_under
(
mrb
,
sock
,
"Constants"
);
#define define_const(SYM) \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment