Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
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-2-2
Commits
ca9b8b45
Commit
ca9b8b45
authored
Oct 04, 2013
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lua intf: allocate file descriptor table dynamically
parent
94452373
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
30 deletions
+33
-30
modules/lua/libs/net.c
modules/lua/libs/net.c
+31
-29
modules/lua/vlc.h
modules/lua/vlc.h
+2
-1
No files found.
modules/lua/libs/net.c
View file @
ca9b8b45
...
...
@@ -49,19 +49,18 @@
void
vlclua_fd_init
(
intf_sys_t
*
sys
)
{
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]));
i
++
)
sys
->
fds
[
i
]
=
-
1
;
sys
->
fdv
=
NULL
;
sys
->
fdc
=
0
;
}
/** Releases all (leaked) VLC Lua file descriptors. */
void
vlclua_fd_destroy
(
intf_sys_t
*
sys
)
{
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
if
(
sys
->
fds
[
i
]
!=
-
1
)
net_Close
(
sys
->
fds
[
i
]
);
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
net_Close
(
sys
->
fdv
[
i
]
);
free
(
sys
->
fdv
);
}
/** Maps an OS file descriptor to a VLC Lua file descriptor */
static
int
vlclua_fd_map
(
lua_State
*
L
,
int
fd
)
{
...
...
@@ -72,17 +71,22 @@ static int vlclua_fd_map( lua_State *L, int fd )
return
-
1
;
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
assert
(
sys
->
fd
s
[
i
]
!=
fd
);
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fd
v
[
i
]
!=
fd
);
#endif
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]));
i
++
)
if
(
sys
->
fds
[
i
]
==
-
1
)
{
sys
->
fds
[
i
]
=
fd
;
return
3
+
i
;
}
return
-
1
;
if
(
sys
->
fdc
>=
64
)
return
-
1
;
int
*
fdv
=
realloc
(
sys
->
fdv
,
(
sys
->
fdc
+
1
)
*
sizeof
(
sys
->
fdv
[
0
])
);
if
(
unlikely
(
fdv
==
NULL
)
)
return
-
1
;
sys
->
fdv
=
fdv
;
sys
->
fdv
[
sys
->
fdc
]
=
fd
;
fd
=
3
+
sys
->
fdc
;
sys
->
fdc
++
;
return
fd
;
}
static
int
vlclua_fd_map_safe
(
lua_State
*
L
,
int
fd
)
...
...
@@ -102,9 +106,7 @@ static int vlclua_fd_get( lua_State *L, unsigned idx )
if
(
idx
<
3u
)
return
idx
;
idx
-=
3
;
if
(
sizeof
(
sys
->
fds
[
0
])
*
idx
<
sizeof
(
sys
->
fds
)
)
return
sys
->
fds
[
idx
];
return
-
1
;
return
(
idx
<
sys
->
fdc
)
?
sys
->
fdv
[
idx
]
:
-
1
;
}
/** Gets the VLC Lua file descriptor mapped from an OS file descriptor */
...
...
@@ -115,8 +117,8 @@ static int vlclua_fd_get_lua( lua_State *L, int fd )
if
(
(
unsigned
)
fd
<
3u
)
return
fd
;
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
if
(
sys
->
fd
s
[
i
]
==
fd
)
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
if
(
sys
->
fd
v
[
i
]
==
fd
)
return
3
+
i
;
return
-
1
;
}
...
...
@@ -132,17 +134,17 @@ static void vlclua_fd_unmap( lua_State *L, unsigned idx )
return
;
/* Never close stdin/stdout/stderr. */
idx
-=
3
;
if
(
idx
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
)
{
fd
=
sys
->
fds
[
idx
];
sys
->
fds
[
idx
]
=
-
1
;
}
if
(
fd
==
-
1
)
if
(
idx
>=
sys
->
fdc
)
return
;
fd
=
sys
->
fdv
[
idx
];
sys
->
fdc
--
;
memmove
(
sys
->
fdv
+
idx
,
sys
->
fdv
+
idx
+
1
,
(
sys
->
fdc
-
idx
)
*
sizeof
(
sys
->
fdv
[
0
])
);
/* realloc() not really needed */
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
assert
(
sys
->
fd
s
[
i
]
!=
fd
);
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fd
v
[
i
]
!=
fd
);
#endif
}
...
...
modules/lua/vlc.h
View file @
ca9b8b45
...
...
@@ -161,7 +161,8 @@ struct intf_sys_t
#ifndef _WIN32
int
fd
[
2
];
#endif
int
fds
[
64
];
int
*
fdv
;
unsigned
fdc
;
vlc_thread_t
thread
;
};
...
...
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