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
5340d39e
Unverified
Commit
5340d39e
authored
Jun 14, 2018
by
Tomoyuki Sahara
Committed by
GitHub
Jun 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4044 from iij/fixes-from-iij-socket
incorporate fixes from iij/socket
parents
97933665
af8020e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
mrbgems/mruby-socket/mrbgem.rake
mrbgems/mruby-socket/mrbgem.rake
+1
-0
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
+23
-11
No files found.
mrbgems/mruby-socket/mrbgem.rake
View file @
5340d39e
...
...
@@ -4,6 +4,7 @@ MRuby::Gem::Specification.new('mruby-socket') do |spec|
spec
.
summary
=
'standard socket class'
spec
.
cc
.
include_paths
<<
"
#{
build
.
root
}
/src"
#spec.cc.defines << "HAVE_SA_LEN=0"
# If Windows, use winsock
if
(
/mswin|mingw|win32/
=~
RUBY_PLATFORM
)
then
...
...
mrbgems/mruby-socket/src/socket.c
View file @
5340d39e
...
...
@@ -19,6 +19,7 @@
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
...
...
@@ -42,6 +43,14 @@
#include "mruby/ext/io.h"
#if !defined(HAVE_SA_LEN)
#if (defined(BSD) && (BSD >= 199006))
#define HAVE_SA_LEN 1
#else
#define HAVE_SA_LEN 0
#endif
#endif
#define E_SOCKET_ERROR (mrb_class_get(mrb, "SocketError"))
#if !defined(mrb_cptr)
...
...
@@ -214,7 +223,11 @@ mrb_addrinfo_unix_path(mrb_state *mrb, mrb_value self)
sastr
=
mrb_iv_get
(
mrb
,
self
,
mrb_intern_lit
(
mrb
,
"@sockaddr"
));
if
(((
struct
sockaddr
*
)
RSTRING_PTR
(
sastr
))
->
sa_family
!=
AF_UNIX
)
mrb_raise
(
mrb
,
E_SOCKET_ERROR
,
"need AF_UNIX address"
);
return
mrb_str_new_cstr
(
mrb
,
((
struct
sockaddr_un
*
)
RSTRING_PTR
(
sastr
))
->
sun_path
);
if
(
RSTRING_LEN
(
sastr
)
<
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
1
)
{
return
mrb_str_new
(
mrb
,
""
,
0
);
}
else
{
return
mrb_str_new_cstr
(
mrb
,
((
struct
sockaddr_un
*
)
RSTRING_PTR
(
sastr
))
->
sun_path
);
}
}
#endif
...
...
@@ -664,19 +677,15 @@ mrb_socket_listen(mrb_state *mrb, mrb_value klass)
static
mrb_value
mrb_socket_sockaddr_family
(
mrb_state
*
mrb
,
mrb_value
klass
)
{
mrb_value
sa
;
const
struct
sockaddr
*
sa
;
mrb_value
str
;
mrb_get_args
(
mrb
,
"S"
,
&
sa
);
#ifdef __linux__
if
((
size_t
)
RSTRING_LEN
(
sa
)
<
offsetof
(
struct
sockaddr
,
sa_family
)
+
sizeof
(
sa_family_t
))
{
mrb_raisef
(
mrb
,
E_SOCKET_ERROR
,
"invalid sockaddr (too short)"
);
}
#else
if
((
size_t
)
RSTRING_LEN
(
sa
)
<
sizeof
(
struct
sockaddr
))
{
mrb_get_args
(
mrb
,
"S"
,
&
str
);
if
((
size_t
)
RSTRING_LEN
(
str
)
<
offsetof
(
struct
sockaddr
,
sa_family
)
+
sizeof
(
sa
->
sa_family
))
{
mrb_raisef
(
mrb
,
E_SOCKET_ERROR
,
"invalid sockaddr (too short)"
);
}
#endif
return
mrb_fixnum_value
(
((
struct
sockaddr
*
)
RSTRING_PTR
(
sa
))
->
sa_family
);
sa
=
(
const
struct
sockaddr
*
)
RSTRING_PTR
(
str
);
return
mrb_fixnum_value
(
sa
->
sa_family
);
}
static
mrb_value
...
...
@@ -695,6 +704,9 @@ mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass)
}
s
=
mrb_str_buf_new
(
mrb
,
sizeof
(
struct
sockaddr_un
));
sunp
=
(
struct
sockaddr_un
*
)
RSTRING_PTR
(
s
);
#if HAVE_SA_LEN
sunp
->
sun_len
=
sizeof
(
struct
sockaddr_un
);
#endif
sunp
->
sun_family
=
AF_UNIX
;
memcpy
(
sunp
->
sun_path
,
RSTRING_PTR
(
path
),
RSTRING_LEN
(
path
));
sunp
->
sun_path
[
RSTRING_LEN
(
path
)]
=
'\0'
;
...
...
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