Commit b616c49e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: move TLS send function and remove dead non-TLS send function

parent 9889e17c
......@@ -23,7 +23,11 @@
#endif
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#ifdef HAVE_POLL
# include <poll.h>
#endif
#include <vlc_common.h>
#include <vlc_tls.h>
#include "h2frame.h"
......@@ -172,6 +176,44 @@ static void vlc_h2_output_flush_unlocked(struct vlc_h2_output *out)
}
}
/**
* Sends bytes to a connection.
* @note This may be a cancellation point.
* The caller is responsible for serializing writes on a given connection.
*/
static ssize_t vlc_https_send(vlc_tls_t *tls, const void *buf, size_t len)
{
struct pollfd ufd;
size_t count = 0;
ufd.fd = tls->fd;
ufd.events = POLLOUT;
while (count < len)
{
int canc = vlc_savecancel();
ssize_t val = tls->send(tls, (char *)buf + count, len - count);
vlc_restorecancel(canc);
if (val > 0)
{
count += val;
continue;
}
if (val == 0)
break;
if (errno != EINTR && errno != EAGAIN)
return count ? (ssize_t)count : -1;
poll(&ufd, 1, -1);
}
return count;
}
/**
* Sends one HTTP/2 frame through TLS.
*
......
......@@ -92,62 +92,6 @@ ssize_t vlc_http_recv(int fd, void *buf, size_t len)
return count;
}
ssize_t vlc_https_send(vlc_tls_t *tls, const void *buf, size_t len)
{
struct pollfd ufd;
size_t count = 0;
ufd.fd = tls->fd;
ufd.events = POLLOUT;
while (count < len)
{
int canc = vlc_savecancel();
ssize_t val = tls->send(tls, (char *)buf + count, len - count);
vlc_restorecancel(canc);
if (val > 0)
{
count += val;
continue;
}
if (val == 0)
break;
if (errno != EINTR && errno != EAGAIN)
return -1;
poll(&ufd, 1, -1);
}
return count;
}
ssize_t vlc_http_send(int fd, const void *buf, size_t len)
{
size_t count = 0;
while (count < len)
{
ssize_t val = send(fd, buf, len, MSG_NOSIGNAL);
if (val > 0)
{
count += val;
continue;
}
if (val == 0)
break;
if (errno != EINTR)
return -1;
}
return count;
}
static void cleanup_addrinfo(void *data)
{
freeaddrinfo(data);
......
......@@ -38,15 +38,6 @@ ssize_t vlc_http_recv(int fd, void *buf, size_t len);
*/
ssize_t vlc_https_recv(struct vlc_tls *tls, void *buf, size_t len);
ssize_t vlc_http_send(int fd, const void *buf, size_t len);
/**
* Sends bytes to a connection.
* @note This may be a cancellation point.
* The caller is responsible for serializing writes on a given connection.
*/
ssize_t vlc_https_send(struct vlc_tls *tls, const void *buf, size_t len);
struct vlc_tls *vlc_https_connect(struct vlc_tls_creds *creds,
const char *name, unsigned port,
bool *restrict two);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment