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
Show 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 @@
...
@@ -49,19 +49,18 @@
void
vlclua_fd_init
(
intf_sys_t
*
sys
)
void
vlclua_fd_init
(
intf_sys_t
*
sys
)
{
{
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]));
i
++
)
sys
->
fdv
=
NULL
;
sys
->
fds
[
i
]
=
-
1
;
sys
->
fdc
=
0
;
}
}
/** Releases all (leaked) VLC Lua file descriptors. */
/** Releases all (leaked) VLC Lua file descriptors. */
void
vlclua_fd_destroy
(
intf_sys_t
*
sys
)
void
vlclua_fd_destroy
(
intf_sys_t
*
sys
)
{
{
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
if
(
sys
->
fds
[
i
]
!=
-
1
)
net_Close
(
sys
->
fdv
[
i
]
);
net_Close
(
sys
->
fds
[
i
]
);
free
(
sys
->
fdv
);
}
}
/** Maps an OS file descriptor to a VLC Lua file descriptor */
/** Maps an OS file descriptor to a VLC Lua file descriptor */
static
int
vlclua_fd_map
(
lua_State
*
L
,
int
fd
)
static
int
vlclua_fd_map
(
lua_State
*
L
,
int
fd
)
{
{
...
@@ -72,17 +71,22 @@ 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
;
return
-
1
;
#ifndef NDEBUG
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fd
s
[
i
]
!=
fd
);
assert
(
sys
->
fd
v
[
i
]
!=
fd
);
#endif
#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
;
}
if
(
sys
->
fdc
>=
64
)
return
-
1
;
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
)
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 )
...
@@ -102,9 +106,7 @@ static int vlclua_fd_get( lua_State *L, unsigned idx )
if
(
idx
<
3u
)
if
(
idx
<
3u
)
return
idx
;
return
idx
;
idx
-=
3
;
idx
-=
3
;
if
(
sizeof
(
sys
->
fds
[
0
])
*
idx
<
sizeof
(
sys
->
fds
)
)
return
(
idx
<
sys
->
fdc
)
?
sys
->
fdv
[
idx
]
:
-
1
;
return
sys
->
fds
[
idx
];
return
-
1
;
}
}
/** Gets the VLC Lua file descriptor mapped from an OS file descriptor */
/** 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 )
...
@@ -115,8 +117,8 @@ static int vlclua_fd_get_lua( lua_State *L, int fd )
if
(
(
unsigned
)
fd
<
3u
)
if
(
(
unsigned
)
fd
<
3u
)
return
fd
;
return
fd
;
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
if
(
sys
->
fd
s
[
i
]
==
fd
)
if
(
sys
->
fd
v
[
i
]
==
fd
)
return
3
+
i
;
return
3
+
i
;
return
-
1
;
return
-
1
;
}
}
...
@@ -132,17 +134,17 @@ static void vlclua_fd_unmap( lua_State *L, unsigned idx )
...
@@ -132,17 +134,17 @@ static void vlclua_fd_unmap( lua_State *L, unsigned idx )
return
;
/* Never close stdin/stdout/stderr. */
return
;
/* Never close stdin/stdout/stderr. */
idx
-=
3
;
idx
-=
3
;
if
(
idx
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
)
if
(
idx
>=
sys
->
fdc
)
{
fd
=
sys
->
fds
[
idx
];
sys
->
fds
[
idx
]
=
-
1
;
}
if
(
fd
==
-
1
)
return
;
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
#ifndef NDEBUG
for
(
unsigned
i
=
0
;
i
<
(
sizeof
(
sys
->
fds
)
/
sizeof
(
sys
->
fds
[
0
]))
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
sys
->
fdc
;
i
++
)
assert
(
sys
->
fd
s
[
i
]
!=
fd
);
assert
(
sys
->
fd
v
[
i
]
!=
fd
);
#endif
#endif
}
}
...
...
modules/lua/vlc.h
View file @
ca9b8b45
...
@@ -161,7 +161,8 @@ struct intf_sys_t
...
@@ -161,7 +161,8 @@ struct intf_sys_t
#ifndef _WIN32
#ifndef _WIN32
int
fd
[
2
];
int
fd
[
2
];
#endif
#endif
int
fds
[
64
];
int
*
fdv
;
unsigned
fdc
;
vlc_thread_t
thread
;
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