Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
ea4e1c65
Commit
ea4e1c65
authored
9 years ago
by
Nick Zavaritsky
Browse files
Options
Downloads
Patches
Plain Diff
gh-42: Workaround missing SO_PROTOCOL option (osx)
parent
59f1c3c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lua/bsdsocket.cc
+42
-50
42 additions, 50 deletions
src/lua/bsdsocket.cc
with
42 additions
and
50 deletions
src/lua/bsdsocket.cc
+
42
−
50
View file @
ea4e1c65
...
...
@@ -251,15 +251,9 @@ static const struct { char name[32]; int value, type, rw; } so_opts[] = {
#endif
#ifdef SO_PROTOCOL
{
"SO_PROTOCOL"
,
SO_PROTOCOL
,
1
,
0
,
},
#else
#define SO_PROTOCOL 38
#endif
#ifdef SO_TYPE
{
"SO_TYPE"
,
SO_TYPE
,
1
,
0
,
},
#else
#define SO_TYPE 3
#endif
{
""
,
0
,
0
,
0
,
}
};
...
...
@@ -718,68 +712,66 @@ lbox_bsdsocket_getaddrinfo(struct lua_State *L)
return
1
;
}
static
void
lbox_bsdsocket_update_proto_type
(
struct
lua_State
*
L
,
int
fh
)
{
if
(
lua_isnil
(
L
,
-
1
))
return
;
int
save_errno
=
errno
;
int
value
;
socklen_t
len
=
sizeof
(
value
);
if
(
getsockopt
(
fh
,
SOL_SOCKET
,
SO_PROTOCOL
,
&
value
,
&
len
)
==
0
)
{
lua_pushliteral
(
L
,
"protocol"
);
lbox_bsdsocket_push_protocol
(
L
,
value
);
lua_rawset
(
L
,
-
3
);
}
len
=
sizeof
(
value
);
if
(
getsockopt
(
fh
,
SOL_SOCKET
,
SO_TYPE
,
&
value
,
&
len
)
==
0
)
{
lua_pushliteral
(
L
,
"type"
);
lbox_bsdsocket_push_sotype
(
L
,
value
);
lua_rawset
(
L
,
-
3
);
}
errno
=
save_errno
;
}
static
int
lbox_bsdsocket_soname
(
struct
lua_State
*
L
)
lbox_bsdsocket_name
(
struct
lua_State
*
L
,
int
(
*
getname_func
)
(
int
,
struct
sockaddr
*
,
socklen_t
*
))
{
lua_pushvalue
(
L
,
1
);
int
fh
=
lua_tointeger
(
L
,
-
1
);
lua_pop
(
L
,
1
);
struct
sockaddr_storage
addr
;
socklen_t
len
=
sizeof
(
addr
);
if
(
get
sock
name
(
fh
,
(
struct
sockaddr
*
)
&
addr
,
&
len
)
!=
0
)
{
if
(
getname
_func
(
fh
,
(
struct
sockaddr
*
)
&
addr
,
&
len
)
!=
0
)
{
lua_pushnil
(
L
);
return
1
;
}
lbox_bsdsocket_push_addr
(
L
,
(
const
struct
sockaddr
*
)
&
addr
,
len
);
lbox_bsdsocket_update_proto_type
(
L
,
fh
);
if
(
lua_isnil
(
L
,
-
1
))
return
1
;
int
type
;
len
=
sizeof
(
type
);
if
(
getsockopt
(
fh
,
SOL_SOCKET
,
SO_TYPE
,
&
type
,
&
len
)
==
0
)
{
lua_pushliteral
(
L
,
"type"
);
lbox_bsdsocket_push_sotype
(
L
,
type
);
lua_rawset
(
L
,
-
3
);
}
else
{
type
=
-
1
;
}
int
protocol
=
0
;
#ifdef SO_PROTOCOL
len
=
sizeof
(
protocol
);
if
(
getsockopt
(
fh
,
SOL_SOCKET
,
SO_PROTOCOL
,
&
protocol
,
&
len
)
==
0
)
{
lua_pushliteral
(
L
,
"protocol"
);
lbox_bsdsocket_push_protocol
(
L
,
protocol
);
lua_rawset
(
L
,
-
3
);
}
#else
if
(
addr
.
ss_family
==
AF_INET
||
addr
.
ss_family
==
AF_INET6
)
{
if
(
type
==
SOCK_STREAM
)
protocol
=
IPPROTO_TCP
;
if
(
type
==
SOCK_DGRAM
)
protocol
=
IPPROTO_UDP
;
}
lua_pushliteral
(
L
,
"protocol"
);
lbox_bsdsocket_push_protocol
(
L
,
protocol
);
lua_rawset
(
L
,
-
3
);
#endif
return
1
;
}
static
int
lbox_bsdsocket_
peer
name
(
struct
lua_State
*
L
)
lbox_bsdsocket_
so
name
(
struct
lua_State
*
L
)
{
lua_pushvalue
(
L
,
1
);
int
fh
=
lua_tointeger
(
L
,
-
1
);
lua_pop
(
L
,
1
);
return
lbox_bsdsocket_name
(
L
,
getsockname
);
}
struct
sockaddr_storage
addr
;
socklen_t
len
=
sizeof
(
addr
);
if
(
getpeername
(
fh
,
(
struct
sockaddr
*
)
&
addr
,
&
len
)
!=
0
)
{
lua_pushnil
(
L
);
return
1
;
}
lbox_bsdsocket_push_addr
(
L
,
(
const
struct
sockaddr
*
)
&
addr
,
len
);
lbox_bsdsocket_update_proto_type
(
L
,
fh
);
return
1
;
static
int
lbox_bsdsocket_peername
(
struct
lua_State
*
L
)
{
return
lbox_bsdsocket_name
(
L
,
getpeername
);
}
static
int
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment