Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
vlc
Commits
5097a477
Commit
5097a477
authored
Jun 30, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lua: use <vlc_interrupt.h> instead of custom pipe for I/O
parent
1f67a0dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
67 deletions
+28
-67
modules/lua/libs/net.c
modules/lua/libs/net.c
+25
-66
modules/lua/vlc.h
modules/lua/vlc.h
+3
-1
No files found.
modules/lua/libs/net.c
View file @
5097a477
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#include <vlc_network.h>
#include <vlc_network.h>
#include <vlc_url.h>
#include <vlc_url.h>
#include <vlc_fs.h>
#include <vlc_fs.h>
#include <vlc_interrupt.h>
#include "../vlc.h"
#include "../vlc.h"
#include "../libs.h"
#include "../libs.h"
...
@@ -319,11 +320,9 @@ static int vlclua_net_recv( lua_State *L )
...
@@ -319,11 +320,9 @@ static int vlclua_net_recv( lua_State *L )
/* Takes a { fd : events } table as first arg and modifies it to { fd : revents } */
/* Takes a { fd : events } table as first arg and modifies it to { fd : revents } */
static
int
vlclua_net_poll
(
lua_State
*
L
)
static
int
vlclua_net_poll
(
lua_State
*
L
)
{
{
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
luaL_checktype
(
L
,
1
,
LUA_TTABLE
);
luaL_checktype
(
L
,
1
,
LUA_TTABLE
);
int
i_fds
=
1
;
int
i_fds
=
0
;
lua_pushnil
(
L
);
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
1
)
)
while
(
lua_next
(
L
,
1
)
)
{
{
...
@@ -335,40 +334,43 @@ static int vlclua_net_poll( lua_State *L )
...
@@ -335,40 +334,43 @@ static int vlclua_net_poll( lua_State *L )
int
*
luafds
=
xmalloc
(
i_fds
*
sizeof
(
*
luafds
)
);
int
*
luafds
=
xmalloc
(
i_fds
*
sizeof
(
*
luafds
)
);
lua_pushnil
(
L
);
lua_pushnil
(
L
);
int
i
=
1
;
for
(
int
i
=
0
;
lua_next
(
L
,
1
);
i
++
)
p_fds
[
0
].
fd
=
dt
->
fd
[
0
];
p_fds
[
0
].
events
=
POLLIN
;
while
(
lua_next
(
L
,
1
)
)
{
{
luafds
[
i
]
=
luaL_checkinteger
(
L
,
-
2
);
luafds
[
i
]
=
luaL_checkinteger
(
L
,
-
2
);
p_fds
[
i
].
fd
=
vlclua_fd_get
(
L
,
luafds
[
i
]
);
p_fds
[
i
].
fd
=
vlclua_fd_get
(
L
,
luafds
[
i
]
);
p_fds
[
i
].
events
=
luaL_checkinteger
(
L
,
-
1
);
p_fds
[
i
].
events
=
luaL_checkinteger
(
L
,
-
1
);
p_fds
[
i
].
events
&=
POLLIN
|
POLLOUT
|
POLLPRI
;
p_fds
[
i
].
events
&=
POLLIN
|
POLLOUT
|
POLLPRI
;
lua_pop
(
L
,
1
);
lua_pop
(
L
,
1
);
i
++
;
}
}
int
i_ret
;
vlclua_dtable_t
*
dt
=
vlclua_get_dtable
(
L
);
vlc_interrupt_t
*
oint
=
vlc_interrupt_set
(
dt
->
interrupt
);
int
ret
=
1
,
val
;
do
do
i_ret
=
poll
(
p_fds
,
i_fds
,
-
1
);
{
while
(
i_ret
==
-
1
&&
errno
==
EINTR
);
if
(
vlc_killed
()
)
{
ret
=
luaL_error
(
L
,
"Interrupted."
);
break
;
}
val
=
vlc_poll_i11e
(
p_fds
,
i_fds
,
-
1
);
}
while
(
val
==
-
1
&&
errno
==
EINTR
);
vlc_interrupt_set
(
oint
);
for
(
i
=
1
;
i
<
i_fds
;
i
++
)
for
(
i
nt
i
=
0
;
i
<
i_fds
;
i
++
)
{
{
lua_pushinteger
(
L
,
luafds
[
i
]
);
lua_pushinteger
(
L
,
luafds
[
i
]
);
lua_pushinteger
(
L
,
p_fds
[
i
].
revents
);
lua_pushinteger
(
L
,
p_fds
[
i
].
revents
);
lua_settable
(
L
,
1
);
lua_settable
(
L
,
1
);
}
}
lua_pushinteger
(
L
,
i_ret
);
lua_pushinteger
(
L
,
val
);
if
(
p_fds
[
0
].
revents
)
i_ret
=
luaL_error
(
L
,
"Interrupted."
);
else
i_ret
=
1
;
free
(
luafds
);
free
(
luafds
);
free
(
p_fds
);
free
(
p_fds
);
return
ret
;
return
i_ret
;
}
}
/*****************************************************************************
/*****************************************************************************
...
@@ -522,41 +524,11 @@ static void luaopen_net_intf( lua_State *L )
...
@@ -522,41 +524,11 @@ static void luaopen_net_intf( lua_State *L )
lua_setfield
(
L
,
-
2
,
"net"
);
lua_setfield
(
L
,
-
2
,
"net"
);
}
}
#ifdef _WIN32
static
int
vlc_socket_pair
(
int
fds
[
2
]
)
{
struct
sockaddr_in
inaddr
;
struct
sockaddr
addr
;
SOCKET
lst
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
memset
(
&
inaddr
,
0
,
sizeof
(
inaddr
)
);
memset
(
&
addr
,
0
,
sizeof
(
addr
)
);
inaddr
.
sin_family
=
AF_INET
;
inaddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_LOOPBACK
);
inaddr
.
sin_port
=
0
;
int
yes
=
1
;
setsockopt
(
lst
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
yes
,
sizeof
(
yes
)
);
bind
(
lst
,
(
struct
sockaddr
*
)
&
inaddr
,
sizeof
(
inaddr
)
);
listen
(
lst
,
1
);
int
len
=
sizeof
(
inaddr
);
getsockname
(
lst
,
&
addr
,
&
len
);
fds
[
0
]
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
connect
(
fds
[
0
],
&
addr
,
len
);
fds
[
1
]
=
accept
(
lst
,
0
,
0
);
closesocket
(
lst
);
return
0
;
}
#endif
int
vlclua_fd_init
(
lua_State
*
L
,
vlclua_dtable_t
*
dt
)
int
vlclua_fd_init
(
lua_State
*
L
,
vlclua_dtable_t
*
dt
)
{
{
#ifndef _WIN32
dt
->
interrupt
=
vlc_interrupt_create
();
if
(
vlc_pipe
(
dt
->
fd
)
)
if
(
unlikely
(
dt
->
interrupt
==
NULL
)
)
return
-
1
;
return
-
1
;
#else
if
(
vlc_socket_pair
(
dt
->
fd
)
)
return
-
1
;
#endif
dt
->
fdv
=
NULL
;
dt
->
fdv
=
NULL
;
dt
->
fdc
=
0
;
dt
->
fdc
=
0
;
vlclua_set_object
(
L
,
vlclua_get_dtable
,
dt
);
vlclua_set_object
(
L
,
vlclua_get_dtable
,
dt
);
...
@@ -566,13 +538,7 @@ int vlclua_fd_init( lua_State *L, vlclua_dtable_t *dt )
...
@@ -566,13 +538,7 @@ int vlclua_fd_init( lua_State *L, vlclua_dtable_t *dt )
void
vlclua_fd_interrupt
(
vlclua_dtable_t
*
dt
)
void
vlclua_fd_interrupt
(
vlclua_dtable_t
*
dt
)
{
{
#ifndef _WIN32
vlc_interrupt_kill
(
dt
->
interrupt
);
close
(
dt
->
fd
[
1
]
);
dt
->
fd
[
1
]
=
-
1
;
#else
closesocket
(
dt
->
fd
[
0
]
);
dt
->
fd
[
0
]
=
-
1
;
#endif
}
}
/** Releases all (leaked) VLC Lua file descriptors. */
/** Releases all (leaked) VLC Lua file descriptors. */
...
@@ -582,12 +548,5 @@ void vlclua_fd_cleanup( vlclua_dtable_t *dt )
...
@@ -582,12 +548,5 @@ void vlclua_fd_cleanup( vlclua_dtable_t *dt )
if
(
dt
->
fdv
[
i
]
!=
-
1
)
if
(
dt
->
fdv
[
i
]
!=
-
1
)
net_Close
(
dt
->
fdv
[
i
]
);
net_Close
(
dt
->
fdv
[
i
]
);
free
(
dt
->
fdv
);
free
(
dt
->
fdv
);
#ifndef _WIN32
vlc_interrupt_destroy
(
dt
->
interrupt
);
if
(
dt
->
fd
[
1
]
!=
-
1
)
close
(
dt
->
fd
[
1
]
);
close
(
dt
->
fd
[
0
]
);
#else
if
(
dt
->
fd
[
0
]
!=
-
1
)
closesocket
(
dt
->
fd
[
0
]
);
#endif
}
}
modules/lua/vlc.h
View file @
5097a477
...
@@ -165,14 +165,16 @@ int vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
...
@@ -165,14 +165,16 @@ int vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
int
vlclua_add_modules_path
(
lua_State
*
,
const
char
*
psz_filename
);
int
vlclua_add_modules_path
(
lua_State
*
,
const
char
*
psz_filename
);
struct
vlc_interrupt
;
/**
/**
* File descriptors table
* File descriptors table
*/
*/
typedef
struct
typedef
struct
{
{
struct
vlc_interrupt
*
interrupt
;
int
*
fdv
;
int
*
fdv
;
unsigned
fdc
;
unsigned
fdc
;
int
fd
[
2
];
}
vlclua_dtable_t
;
}
vlclua_dtable_t
;
int
vlclua_fd_init
(
lua_State
*
,
vlclua_dtable_t
*
);
int
vlclua_fd_init
(
lua_State
*
,
vlclua_dtable_t
*
);
...
...
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