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
2f5e4399
Commit
2f5e4399
authored
Jan 10, 2016
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tls: use I/O vector for receiving
parent
3f72fbdd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
34 deletions
+80
-34
include/vlc_tls.h
include/vlc_tls.h
+1
-1
modules/access/http/chunked_test.c
modules/access/http/chunked_test.c
+21
-10
modules/access/http/h2conn.c
modules/access/http/h2conn.c
+7
-2
modules/misc/gnutls.c
modules/misc/gnutls.c
+24
-9
modules/misc/securetransport.c
modules/misc/securetransport.c
+8
-4
src/network/tls.c
src/network/tls.c
+16
-7
test/modules/misc/tls.c
test/modules/misc/tls.c
+3
-1
No files found.
include/vlc_tls.h
View file @
2f5e4399
...
...
@@ -42,7 +42,7 @@ struct vlc_tls
void
*
sys
;
int
fd
;
ssize_t
(
*
re
cv
)(
struct
vlc_tls
*
,
void
*
,
size_t
);
ssize_t
(
*
re
adv
)(
struct
vlc_tls
*
,
struct
iovec
*
,
unsigned
);
ssize_t
(
*
writev
)(
struct
vlc_tls
*
,
const
struct
iovec
*
,
unsigned
);
int
(
*
shutdown
)(
struct
vlc_tls
*
,
bool
duplex
);
void
(
*
close
)(
vlc_tls_t
*
);
...
...
modules/access/http/chunked_test.c
View file @
2f5e4399
...
...
@@ -39,19 +39,30 @@ static const char *stream_content;
static
size_t
stream_length
;
static
bool
stream_bad
;
static
ssize_t
recv_callback
(
struct
vlc_tls
*
tls
,
void
*
buf
,
size_t
len
)
static
ssize_t
recv_callback
(
struct
vlc_tls
*
tls
,
struct
iovec
*
iov
,
unsigned
count
)
{
size_t
copy
=
len
;
if
(
copy
>
stream_length
)
copy
=
stream_length
;
if
(
copy
>
0
)
size_t
rcvd
=
0
;
while
(
count
>
0
)
{
memcpy
(
buf
,
stream_content
,
copy
);
stream_content
+=
copy
;
stream_length
-=
copy
;
size_t
copy
=
iov
->
iov_len
;
if
(
copy
>
stream_length
)
copy
=
stream_length
;
if
(
copy
>
0
)
{
memcpy
(
iov
->
iov_base
,
stream_content
,
copy
);
stream_content
+=
copy
;
stream_length
-=
copy
;
rcvd
+=
copy
;
}
iov
++
;
count
--
;
}
(
void
)
tls
;
return
copy
;
return
rcvd
;
}
static
void
close_callback
(
struct
vlc_tls
*
tls
)
...
...
@@ -61,7 +72,7 @@ static void close_callback(struct vlc_tls *tls)
static
struct
vlc_tls
chunked_tls
=
{
.
re
c
v
=
recv_callback
,
.
re
ad
v
=
recv_callback
,
.
close
=
close_callback
,
};
...
...
modules/access/http/h2conn.c
View file @
2f5e4399
...
...
@@ -525,15 +525,18 @@ static const struct vlc_h2_parser_cbs vlc_h2_parser_callbacks =
static
ssize_t
vlc_https_recv
(
vlc_tls_t
*
tls
,
void
*
buf
,
size_t
len
)
{
struct
pollfd
ufd
;
struct
iovec
iov
;
size_t
count
=
0
;
ufd
.
fd
=
tls
->
fd
;
ufd
.
events
=
POLLIN
;
iov
.
iov_base
=
buf
;
iov
.
iov_len
=
len
;
while
(
count
<
len
)
while
(
iov
.
iov_len
>
0
)
{
int
canc
=
vlc_savecancel
();
ssize_t
val
=
tls
->
re
cv
(
tls
,
(
char
*
)
buf
+
count
,
len
-
count
);
ssize_t
val
=
tls
->
re
adv
(
tls
,
&
iov
,
1
);
vlc_restorecancel
(
canc
);
...
...
@@ -542,6 +545,8 @@ static ssize_t vlc_https_recv(vlc_tls_t *tls, void *buf, size_t len)
if
(
val
>=
0
)
{
iov
.
iov_base
=
(
char
*
)
iov
.
iov_base
+
val
;
iov
.
iov_len
-=
val
;
count
+=
val
;
continue
;
}
...
...
modules/misc/gnutls.c
View file @
2f5e4399
...
...
@@ -157,6 +157,29 @@ static ssize_t vlc_gnutls_writev (gnutls_transport_ptr_t ptr,
return
sendmsg
(
fd
,
&
msg
,
MSG_NOSIGNAL
);
}
static
ssize_t
gnutls_Recv
(
vlc_tls_t
*
tls
,
struct
iovec
*
iov
,
unsigned
count
)
{
gnutls_session_t
session
=
tls
->
sys
;
size_t
rcvd
=
0
;
while
(
count
>
0
)
{
ssize_t
val
=
gnutls_record_recv
(
session
,
iov
->
iov_base
,
iov
->
iov_len
);
if
(
val
<
0
)
return
rcvd
?
(
ssize_t
)
rcvd
:
gnutls_Error
(
tls
,
val
);
rcvd
+=
val
;
if
((
size_t
)
val
<
iov
->
iov_len
)
break
;
iov
++
;
count
--
;
}
return
rcvd
;
}
static
ssize_t
gnutls_Send
(
vlc_tls_t
*
tls
,
const
struct
iovec
*
iov
,
unsigned
count
)
{
...
...
@@ -182,14 +205,6 @@ static ssize_t gnutls_Send (vlc_tls_t *tls, const struct iovec *iov,
return
(
val
<
0
)
?
gnutls_Error
(
tls
,
val
)
:
val
;
}
static
ssize_t
gnutls_Recv
(
vlc_tls_t
*
tls
,
void
*
buf
,
size_t
length
)
{
gnutls_session_t
session
=
tls
->
sys
;
ssize_t
val
=
gnutls_record_recv
(
session
,
buf
,
length
);
return
(
val
<
0
)
?
gnutls_Error
(
tls
,
val
)
:
val
;
}
static
int
gnutls_Shutdown
(
vlc_tls_t
*
tls
,
bool
duplex
)
{
gnutls_session_t
session
=
tls
->
sys
;
...
...
@@ -278,8 +293,8 @@ static int gnutls_SessionOpen(vlc_tls_creds_t *creds, vlc_tls_t *tls, int type,
gnutls_transport_set_int
(
session
,
fd
);
gnutls_transport_set_vec_push_function
(
session
,
vlc_gnutls_writev
);
tls
->
sys
=
session
;
tls
->
readv
=
gnutls_Recv
;
tls
->
writev
=
gnutls_Send
;
tls
->
recv
=
gnutls_Recv
;
tls
->
shutdown
=
gnutls_Shutdown
;
tls
->
close
=
gnutls_Close
;
return
VLC_SUCCESS
;
...
...
modules/misc/securetransport.c
View file @
2f5e4399
...
...
@@ -60,7 +60,7 @@ vlc_module_begin ()
/*
* The server module currently uses an OSX only API, to be compatible with 10.6.
*
If the module is needed on iOS, then the "modern" keychain lookup API need to be
If the module is needed on iOS, then the "modern" keychain lookup API need to be
* implemented.
*/
#if !TARGET_OS_IPHONE
...
...
@@ -486,13 +486,17 @@ static ssize_t st_Send (vlc_tls_t *session, const struct iovec *iov,
/**
* Receives data through a TLS session.
*/
static
ssize_t
st_Recv
(
vlc_tls_t
*
session
,
void
*
buf
,
size_t
length
)
static
ssize_t
st_Recv
(
vlc_tls_t
*
session
,
struct
iovec
*
iov
,
unsigned
count
)
{
vlc_tls_sys_t
*
sys
=
session
->
sys
;
assert
(
sys
);
if
(
unlikely
(
count
==
0
))
return
0
;
size_t
actualSize
;
OSStatus
ret
=
SSLRead
(
sys
->
p_context
,
buf
,
length
,
&
actualSize
);
OSStatus
ret
=
SSLRead
(
sys
->
p_context
,
iov
->
iov_base
,
iov
->
iov_len
,
&
actualSize
);
if
(
ret
==
errSSLWouldBlock
&&
actualSize
)
return
actualSize
;
...
...
@@ -565,8 +569,8 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
sys
->
p_context
=
NULL
;
session
->
sys
=
sys
;
session
->
readv
=
st_Recv
;
session
->
writev
=
st_Send
;
session
->
recv
=
st_Recv
;
session
->
shutdown
=
st_SessionShutdown
;
session
->
close
=
st_SessionClose
;
crd
->
handshake
=
st_Handshake
;
...
...
src/network/tls.c
View file @
2f5e4399
...
...
@@ -220,9 +220,12 @@ error:
ssize_t
vlc_tls_Read
(
vlc_tls_t
*
session
,
void
*
buf
,
size_t
len
,
bool
waitall
)
{
struct
pollfd
ufd
;
struct
iovec
iov
;
ufd
.
fd
=
session
->
fd
;
ufd
.
events
=
POLLIN
;
iov
.
iov_base
=
buf
;
iov
.
iov_len
=
len
;
for
(
size_t
rcvd
=
0
;;)
{
...
...
@@ -232,16 +235,16 @@ ssize_t vlc_tls_Read(vlc_tls_t *session, void *buf, size_t len, bool waitall)
return
-
1
;
}
ssize_t
val
=
session
->
re
cv
(
session
,
buf
,
len
);
ssize_t
val
=
session
->
re
adv
(
session
,
&
iov
,
1
);
if
(
val
>
0
)
{
if
(
!
waitall
)
return
val
;
buf
=
((
char
*
)
buf
)
+
val
;
len
-=
val
;
iov
.
iov_base
=
(
char
*
)
iov
.
iov_base
+
val
;
iov
.
iov_
len
-=
val
;
rcvd
+=
val
;
}
if
(
len
==
0
||
val
==
0
)
if
(
iov
.
iov_
len
==
0
||
val
==
0
)
return
rcvd
;
if
(
val
==
-
1
&&
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
return
rcvd
?
(
ssize_t
)
rcvd
:
-
1
;
...
...
@@ -315,9 +318,15 @@ error:
return
NULL
;
}
static
ssize_t
vlc_tls_DummyReceive
(
vlc_tls_t
*
tls
,
void
*
buf
,
size_t
len
)
static
ssize_t
vlc_tls_DummyReceive
(
vlc_tls_t
*
tls
,
struct
iovec
*
iov
,
unsigned
count
)
{
return
recv
(
tls
->
fd
,
buf
,
len
,
0
);
struct
msghdr
msg
=
{
.
msg_iov
=
iov
,
.
msg_iovlen
=
count
,
};
return
recvmsg
(
tls
->
fd
,
&
msg
,
0
);
}
static
ssize_t
vlc_tls_DummySend
(
vlc_tls_t
*
tls
,
const
struct
iovec
*
iov
,
...
...
@@ -349,7 +358,7 @@ vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd)
session
->
obj
=
obj
;
session
->
fd
=
fd
;
session
->
re
c
v
=
vlc_tls_DummyReceive
;
session
->
re
ad
v
=
vlc_tls_DummyReceive
;
session
->
writev
=
vlc_tls_DummySend
;
session
->
shutdown
=
vlc_tls_DummyShutdown
;
session
->
close
=
vlc_tls_DummyClose
;
...
...
test/modules/misc/tls.c
View file @
2f5e4399
...
...
@@ -199,7 +199,9 @@ int main(void)
char
buf
[
12
];
struct
iovec
iov
;
val
=
tls
->
recv
(
tls
,
buf
,
sizeof
(
buf
));
iov
.
iov_base
=
buf
;
iov
.
iov_len
=
sizeof
(
buf
);
val
=
tls
->
readv
(
tls
,
&
iov
,
1
);
assert
(
val
==
-
1
&&
errno
==
EAGAIN
);
val
=
vlc_tls_Write
(
tls
,
"Hello "
,
6
);
...
...
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