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
96868b69
Commit
96868b69
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 sending
parent
95ba2e83
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
22 deletions
+74
-22
include/vlc_tls.h
include/vlc_tls.h
+1
-1
modules/access/http/h2output.c
modules/access/http/h2output.c
+6
-1
modules/access/http/h2output_test.c
modules/access/http/h2output_test.c
+7
-4
modules/misc/gnutls.c
modules/misc/gnutls.c
+31
-5
modules/misc/securetransport.c
modules/misc/securetransport.c
+8
-3
src/network/tls.c
src/network/tls.c
+16
-7
test/modules/misc/tls.c
test/modules/misc/tls.c
+5
-1
No files found.
include/vlc_tls.h
View file @
96868b69
...
...
@@ -43,7 +43,7 @@ struct vlc_tls
int
fd
;
ssize_t
(
*
recv
)(
struct
vlc_tls
*
,
void
*
,
size_t
);
ssize_t
(
*
send
)(
struct
vlc_tls
*
,
const
void
*
,
size_t
);
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/h2output.c
View file @
96868b69
...
...
@@ -190,20 +190,25 @@ static void vlc_h2_output_flush_unlocked(struct vlc_h2_output *out)
static
ssize_t
vlc_https_send
(
vlc_tls_t
*
tls
,
const
void
*
buf
,
size_t
len
)
{
struct
pollfd
ufd
;
struct
iovec
iov
;
size_t
count
=
0
;
ufd
.
fd
=
tls
->
fd
;
ufd
.
events
=
POLLOUT
;
iov
.
iov_base
=
(
void
*
)
buf
;
iov
.
iov_len
=
len
;
while
(
count
<
len
)
{
int
canc
=
vlc_savecancel
();
ssize_t
val
=
tls
->
send
(
tls
,
(
char
*
)
buf
+
count
,
len
-
count
);
ssize_t
val
=
tls
->
writev
(
tls
,
&
iov
,
1
);
vlc_restorecancel
(
canc
);
if
(
val
>
0
)
{
iov
.
iov_base
=
(
char
*
)
iov
.
iov_base
+
val
;
iov
.
iov_len
-=
val
;
count
+=
val
;
continue
;
}
...
...
modules/access/http/h2output_test.c
View file @
96868b69
...
...
@@ -40,11 +40,14 @@ static bool send_failure = false;
static
bool
expect_hello
=
true
;
static
vlc_sem_t
rx
;
static
ssize_t
send_callback
(
vlc_tls_t
*
tls
,
const
void
*
buf
,
size_t
len
)
static
ssize_t
send_callback
(
vlc_tls_t
*
tls
,
const
struct
iovec
*
iov
,
unsigned
count
)
{
const
uint8_t
*
p
=
buf
;
assert
(
count
==
1
);
assert
(
tls
->
writev
==
send_callback
);
assert
(
tls
->
send
==
send_callback
);
const
uint8_t
*
p
=
iov
->
iov_base
;
size_t
len
=
iov
->
iov_len
;
if
(
expect_hello
)
{
...
...
@@ -71,7 +74,7 @@ static ssize_t send_callback(vlc_tls_t *tls, const void *buf, size_t len)
static
vlc_tls_t
fake_tls
=
{
.
send
=
send_callback
,
.
writev
=
send_callback
,
};
static
struct
vlc_h2_frame
*
frame
(
unsigned
char
c
)
...
...
modules/misc/gnutls.c
View file @
96868b69
...
...
@@ -159,11 +159,28 @@ static ssize_t vlc_gnutls_writev (gnutls_transport_ptr_t ptr,
}
#endif
static
ssize_t
gnutls_Send
(
vlc_tls_t
*
tls
,
const
void
*
buf
,
size_t
length
)
static
ssize_t
gnutls_Send
(
vlc_tls_t
*
tls
,
const
struct
iovec
*
iov
,
unsigned
count
)
{
gnutls_session_t
session
=
tls
->
sys
;
ssize_t
val
=
gnutls_record_send
(
session
,
buf
,
length
)
;
ssize_t
val
;
if
(
!
gnutls_record_check_corked
(
session
))
{
gnutls_record_cork
(
session
);
while
(
count
>
0
)
{
val
=
gnutls_record_send
(
session
,
iov
->
iov_base
,
iov
->
iov_len
);
if
(
val
<
(
ssize_t
)
iov
->
iov_len
)
break
;
iov
++
;
count
--
;
}
}
val
=
gnutls_record_uncork
(
session
,
0
);
return
(
val
<
0
)
?
gnutls_Error
(
tls
,
val
)
:
val
;
}
...
...
@@ -178,9 +195,18 @@ static ssize_t gnutls_Recv (vlc_tls_t *tls, void *buf, size_t length)
static
int
gnutls_Shutdown
(
vlc_tls_t
*
tls
,
bool
duplex
)
{
gnutls_session_t
session
=
tls
->
sys
;
int
val
=
gnutls_bye
(
session
,
duplex
?
GNUTLS_SHUT_RDWR
:
GNUTLS_SHUT_WR
);
ssize_t
val
;
/* Flush any pending data */
val
=
gnutls_record_uncork
(
session
,
0
);
if
(
val
<
0
)
return
gnutls_Error
(
tls
,
val
);
return
(
val
<
0
)
?
gnutls_Error
(
tls
,
val
)
:
0
;
val
=
gnutls_bye
(
session
,
duplex
?
GNUTLS_SHUT_RDWR
:
GNUTLS_SHUT_WR
);
if
(
val
<
0
)
return
gnutls_Error
(
tls
,
val
);
return
0
;
}
static
void
gnutls_Close
(
vlc_tls_t
*
tls
)
...
...
@@ -256,7 +282,7 @@ static int gnutls_SessionOpen(vlc_tls_creds_t *creds, vlc_tls_t *tls, int type,
gnutls_transport_set_vec_push_function
(
session
,
vlc_gnutls_writev
);
#endif
tls
->
sys
=
session
;
tls
->
send
=
gnutls_Send
;
tls
->
writev
=
gnutls_Send
;
tls
->
recv
=
gnutls_Recv
;
tls
->
shutdown
=
gnutls_Shutdown
;
tls
->
close
=
gnutls_Close
;
...
...
modules/misc/securetransport.c
View file @
96868b69
...
...
@@ -427,12 +427,16 @@ static int st_Handshake (vlc_tls_creds_t *crd, vlc_tls_t *session,
/**
* Sends data through a TLS session.
*/
static
ssize_t
st_Send
(
vlc_tls_t
*
session
,
const
void
*
buf
,
size_t
length
)
static
ssize_t
st_Send
(
vlc_tls_t
*
session
,
const
struct
iovec
*
iov
,
unsigned
count
)
{
vlc_tls_sys_t
*
sys
=
session
->
sys
;
assert
(
sys
);
OSStatus
ret
=
noErr
;
if
(
unlikely
(
count
==
0
))
return
0
;
/*
* SSLWrite does not return the number of bytes actually written to
* the socket, but the number of bytes written to the internal cache.
...
...
@@ -466,7 +470,8 @@ static ssize_t st_Send (vlc_tls_t *session, const void *buf, size_t length)
}
}
else
{
ret
=
SSLWrite
(
sys
->
p_context
,
buf
,
length
,
&
actualSize
);
ret
=
SSLWrite
(
sys
->
p_context
,
iov
->
iov_base
,
iov
->
iov_len
,
&
actualSize
);
if
(
ret
==
errSSLWouldBlock
)
{
sys
->
i_send_buffered_bytes
=
length
;
...
...
@@ -560,7 +565,7 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
sys
->
p_context
=
NULL
;
session
->
sys
=
sys
;
session
->
send
=
st_Send
;
session
->
writev
=
st_Send
;
session
->
recv
=
st_Recv
;
session
->
shutdown
=
st_SessionShutdown
;
session
->
close
=
st_SessionClose
;
...
...
src/network/tls.c
View file @
96868b69
...
...
@@ -253,9 +253,12 @@ ssize_t vlc_tls_Read(vlc_tls_t *session, void *buf, size_t len, bool waitall)
ssize_t
vlc_tls_Write
(
vlc_tls_t
*
session
,
const
void
*
buf
,
size_t
len
)
{
struct
pollfd
ufd
;
struct
iovec
iov
;
ufd
.
fd
=
session
->
fd
;
ufd
.
events
=
POLLOUT
;
iov
.
iov_base
=
(
void
*
)
buf
;
iov
.
iov_len
=
len
;
for
(
size_t
sent
=
0
;;)
{
...
...
@@ -265,14 +268,14 @@ ssize_t vlc_tls_Write(vlc_tls_t *session, const void *buf, size_t len)
return
-
1
;
}
ssize_t
val
=
session
->
send
(
session
,
buf
,
len
);
ssize_t
val
=
session
->
writev
(
session
,
&
iov
,
1
);
if
(
val
>
0
)
{
buf
=
((
const
char
*
)
buf
)
+
val
;
len
-=
val
;
iov
.
iov_base
=
((
char
*
)
iov
.
iov_base
)
+
val
;
iov
.
iov_
len
-=
val
;
sent
+=
val
;
}
if
(
len
==
0
||
val
==
0
)
if
(
iov
.
iov_
len
==
0
||
val
==
0
)
return
sent
;
if
(
val
==
-
1
&&
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
return
sent
?
(
ssize_t
)
sent
:
-
1
;
...
...
@@ -317,9 +320,15 @@ static ssize_t vlc_tls_DummyReceive(vlc_tls_t *tls, void *buf, size_t len)
return
recv
(
tls
->
fd
,
buf
,
len
,
0
);
}
static
ssize_t
vlc_tls_DummySend
(
vlc_tls_t
*
tls
,
const
void
*
buf
,
size_t
len
)
static
ssize_t
vlc_tls_DummySend
(
vlc_tls_t
*
tls
,
const
struct
iovec
*
iov
,
unsigned
count
)
{
return
send
(
tls
->
fd
,
buf
,
len
,
MSG_NOSIGNAL
);
const
struct
msghdr
msg
=
{
.
msg_iov
=
(
struct
iovec
*
)
iov
,
.
msg_iovlen
=
count
,
};
return
sendmsg
(
tls
->
fd
,
&
msg
,
MSG_NOSIGNAL
);
}
static
int
vlc_tls_DummyShutdown
(
vlc_tls_t
*
tls
,
bool
duplex
)
...
...
@@ -341,7 +350,7 @@ vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd)
session
->
obj
=
obj
;
session
->
fd
=
fd
;
session
->
recv
=
vlc_tls_DummyReceive
;
session
->
send
=
vlc_tls_DummySend
;
session
->
writev
=
vlc_tls_DummySend
;
session
->
shutdown
=
vlc_tls_DummyShutdown
;
session
->
close
=
vlc_tls_DummyClose
;
return
session
;
...
...
test/modules/misc/tls.c
View file @
96868b69
...
...
@@ -197,6 +197,7 @@ int main(void)
/* Do some I/O */
char
buf
[
12
];
struct
iovec
iov
;
val
=
tls
->
recv
(
tls
,
buf
,
sizeof
(
buf
));
assert
(
val
==
-
1
&&
errno
==
EAGAIN
);
...
...
@@ -228,13 +229,16 @@ int main(void)
size_t
bytes
=
0
;
unsigned
seed
=
0
;
iov
.
iov_base
=
data
;
iov
.
iov_len
=
sizeof
(
data
);
do
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
data
);
i
++
)
data
[
i
]
=
rand_r
(
&
seed
);
bytes
+=
sizeof
(
data
);
}
while
((
val
=
tls
->
send
(
tls
,
data
,
sizeof
(
data
)
))
==
sizeof
(
data
));
while
((
val
=
tls
->
writev
(
tls
,
&
iov
,
1
))
==
sizeof
(
data
));
bytes
-=
sizeof
(
data
);
if
(
val
>
0
)
...
...
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