Add send retry support for WIN32 TCP transport

This commit is contained in:
bossiel 2015-06-15 07:48:04 +00:00
parent a75e07604e
commit e989621fe0
4 changed files with 67 additions and 49 deletions

View File

@ -324,16 +324,17 @@ static tsk_size_t tdav_codec_vp8_decode(tmedia_codec_t* self, const void* in_dat
}
{ /* 4.2. VP8 Payload Descriptor */
uint8_t X, R, N, I, L, T, K;//FIXME: store
uint8_t X, R, N, I, L, T, K;//TODO: store
X = (*pdata & 0x80) >> 7;
R = (*pdata & 0x40) >> 6;
X = ((*pdata & 0x80) >> 7);
R = ((*pdata & 0x40) >> 6);
if (R) {
TSK_DEBUG_ERROR("R<>0");
return 0;
fatal_error = tsk_true;
goto bail;
}
N = (*pdata & 0x20) >> 5;
S = (*pdata & 0x10) >> 4;
N = ((*pdata & 0x20) >> 5);
S = ((*pdata & 0x10) >> 4);
PartID = (*pdata & 0x0F);
// skip "REQUIRED" header
if (++pdata >= pdata_end) {
@ -419,10 +420,14 @@ static tsk_size_t tdav_codec_vp8_decode(tmedia_codec_t* self, const void* in_dat
// Make sure the header is present
if (S != 1 || PartID != 0 || in_size < 3) {
TSK_DEBUG_WARN("VP8 payload header is missing");
fatal_error = tsk_true;
goto bail;
#if 0
if (in_size < 3)
#endif
{
fatal_error = tsk_true;
goto bail;
}
}
{
/* SizeN: The size of the first partition in bytes is calculated from
the 19 bits in Size0, Size1, and Size2 as 1stPartitionSize = Size0
@ -563,7 +568,6 @@ bail:
TMEDIA_CODEC_VIDEO(self)->in.result.proto_hdr = proto_hdr;
TMEDIA_CODEC_VIDEO(self)->in.callback(&TMEDIA_CODEC_VIDEO(self)->in.result);
}
fatal_error = tsk_true;
// vp8->decoder.last_PartID = PartID;
// vp8->decoder.last_S = S;

View File

@ -227,50 +227,55 @@ tsk_size_t tnet_transport_send(const tnet_transport_handle_t *handle, tnet_fd_t
{
tnet_transport_t *transport = (tnet_transport_t*)handle;
int ret = -1;
DWORD numberOfBytesSent = 0;
tsk_size_t sent = 0;
if (!transport){
TSK_DEBUG_ERROR("Invalid transport handle.");
goto bail;
}
if (transport->tls.enabled){
transport_socket_xt* socket = getSocket(transport->context, from);
if (socket && socket->tlshandle){
if (!tnet_tls_socket_send(socket->tlshandle, buf, size)){
numberOfBytesSent = (DWORD)size;
}
else{
TSK_DEBUG_ERROR("Tring to use a socket without TLS handle to send data");
numberOfBytesSent = 0;
}
goto bail;
}
}
else{
WSABUF wsaBuffer;
wsaBuffer.buf = (CHAR*)buf;
wsaBuffer.len = (ULONG)size;
if ((ret = WSASend(from, &wsaBuffer, 1, &numberOfBytesSent, 0, NULL, NULL)) == SOCKET_ERROR){
if ((ret = WSAGetLastError()) == WSA_IO_PENDING){
TSK_DEBUG_INFO("WSA_IO_PENDING error for WSASend SSESSION");
ret = 0;
}
else{
TNET_PRINT_LAST_ERROR("WSASend have failed.");
//tnet_sockfd_close(&from);
goto bail;
while (sent < size) {
int try_guard = 10;
if (transport->tls.enabled){
transport_socket_xt* socket = getSocket(transport->context, from);
if (socket && socket->tlshandle) {
if (tnet_tls_socket_send(socket->tlshandle, buf, size) == 0) {
sent = size;
}
else {
TSK_DEBUG_ERROR("Tring to use a socket without TLS handle to send data");
}
goto bail; // TLS do not retry
}
}
else{
ret = 0;
else {
WSABUF wsaBuffer;
DWORD numberOfBytesSent = 0;
wsaBuffer.buf = ((CHAR*)buf) + sent;
wsaBuffer.len = (ULONG)(size - sent);
try_again:
if ((ret = WSASend(from, &wsaBuffer, 1, &numberOfBytesSent, 0, NULL, NULL)) == SOCKET_ERROR) {
ret = WSAGetLastError();
if (ret == WSA_IO_PENDING || ret == WSAEWOULDBLOCK) {
TSK_DEBUG_INFO("SendTCP() - WouldBlock. Retrying...");
if (try_guard--) {
tsk_thread_sleep(10);
goto try_again;
}
}
else {
TNET_PRINT_LAST_ERROR("WSASend have failed.");
goto bail;
}
}
else {
sent += numberOfBytesSent;
}
}
}
bail:
return numberOfBytesSent;
return sent;
}
/*

View File

@ -1,7 +1,5 @@
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
* Copyright (C) 2010-2015 Mamadou DIOP.
*
* This file is part of Open Source Doubango Framework.
*
@ -23,9 +21,6 @@
/**@file tnet_utils.h
* @brief Network utility functions.
*
* @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
*
*/
#ifndef TNET_UTILS_H
#define TNET_UTILS_H
@ -39,7 +34,9 @@ TNET_BEGIN_DECLS
/**@ingroup tnet_utils_group
*/
#define TNET_CONNECT_TIMEOUT 2000
#if !defined(TNET_CONNECT_TIMEOUT)
# define TNET_CONNECT_TIMEOUT 2000
#endif /* TNET_CONNECT_TIMEOUT */
/**Interface.
*/

View File

@ -1496,13 +1496,21 @@ static int _tnet_turn_session_send_buff_0(tnet_turn_session_t* p_self, const tne
}
if (TNET_SOCKET_TYPE_IS_DGRAM(p_self->p_lcl_sock->type)) {
#if 0
u_sent_bytes = tnet_transport_sendto(p_self->p_transport, p_self->p_lcl_sock->fd, (const struct sockaddr *)&p_self->srv_addr, pc_buff_ptr, u_buff_size);
#else
u_sent_bytes = tnet_sockfd_sendto(p_self->p_lcl_sock->fd, (const struct sockaddr *)&p_self->srv_addr, pc_buff_ptr, u_buff_size);
#endif
}
else {
if (pc_peer && pc_peer->b_stream_connected && pc_peer->conn_fd != TNET_INVALID_FD) {
// Send using Peer connection if connected
// Should never be called because for now requested transport is always equal to UDP
#if 0
u_sent_bytes = tnet_transport_send(p_self->p_transport, pc_peer->conn_fd, pc_buff_ptr, u_buff_size);
#else
u_sent_bytes = tnet_sockfd_send(pc_peer->conn_fd, pc_buff_ptr, u_buff_size, 0);
#endif
}
else {
// Connect if not already done
@ -1511,7 +1519,11 @@ static int _tnet_turn_session_send_buff_0(tnet_turn_session_t* p_self, const tne
p_self->b_stream_connected = (ret == 0);
}
if (p_self->b_stream_connected) {
#if 0
u_sent_bytes = tnet_transport_send(p_self->p_transport, p_self->p_lcl_sock->fd, pc_buff_ptr, u_buff_size);
#else
u_sent_bytes = tnet_socket_send_stream(p_self->p_lcl_sock, pc_buff_ptr, u_buff_size);
#endif
}
}
}