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

adaptive: use TLS I/O functions

parent 3aee65c9
...@@ -130,43 +130,21 @@ bool TLSSocket::connected() const ...@@ -130,43 +130,21 @@ bool TLSSocket::connected() const
ssize_t TLSSocket::read(vlc_object_t *, void *p_buffer, size_t len) ssize_t TLSSocket::read(vlc_object_t *, void *p_buffer, size_t len)
{ {
ssize_t size; return vlc_tls_Read(tls, p_buffer, len, true) == (ssize_t)len;
size_t totalread = 0;
do
{
size = tls_Recv(tls, (uint8_t*)p_buffer + totalread, len - totalread); /* only returns partial chunks */
if(size >= 0)
{
totalread += (size_t) size;
}
else if(errno != EINTR && errno!=EAGAIN)
{
break;
}
} while ( totalread < len );
return totalread;
} }
std::string TLSSocket::readline(vlc_object_t *stream) std::string TLSSocket::readline(vlc_object_t *)
{ {
std::string ret; char *line = ::vlc_tls_GetLine(tls);
ret.reserve(256); if(line == NULL)
char c[2] = {0,0}; return "";
ssize_t size = TLSSocket::read(stream, c, 1);
while(size > 0)
{
ret.append( &c[0] );
if(c[0] == '\n')
break;
size = TLSSocket::read(stream, c, 1);
}
std::string ret(line);
::free(line);
return ret; return ret;
} }
bool TLSSocket::send(vlc_object_t *stream, const void *buf, size_t size) bool TLSSocket::send(vlc_object_t *, const void *buf, size_t size)
{ {
if (!connected()) if (!connected())
return false; return false;
...@@ -174,14 +152,7 @@ bool TLSSocket::send(vlc_object_t *stream, const void *buf, size_t size) ...@@ -174,14 +152,7 @@ bool TLSSocket::send(vlc_object_t *stream, const void *buf, size_t size)
if (size == 0) if (size == 0)
return true; return true;
ssize_t ret = tls_Send(tls, buf, size); return vlc_tls_Write(tls, buf, size) == (ssize_t)size;
if (ret <= 0)
return false;
if ( (size_t)ret < size )
send( stream, ((uint8_t*)buf) + ret, size - ret );
return true;
} }
void TLSSocket::disconnect() void TLSSocket::disconnect()
......
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