diff --git a/microstack/ILibAsyncSocket.c b/microstack/ILibAsyncSocket.c index e1579b8..a32bac2 100644 --- a/microstack/ILibAsyncSocket.c +++ b/microstack/ILibAsyncSocket.c @@ -583,15 +583,20 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc #endif { // Still Pending Data to be sent - data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), 0, NULL, NULL); + data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), bytesSent < 0 ? 0 : (int)(module->writeBioBuffer->length) - bytesSent, NULL, NULL); data->UserFree = ILibAsyncSocket_MemoryOwnership_BIO; + data->bytesSent = 0; module->PendingSend_Head = module->PendingSend_Tail = data; if (bytesSent > 0) { - module->writeBioBuffer->data += bytesSent; - module->writeBioBuffer->length -= bytesSent; + // Some data was sent, so we need to pull the data and buffer it + module->PendingSend_Head->buffer = ILibMemory_GetExtraMemory(data, sizeof(ILibAsyncSocket_SendData)); + module->PendingSend_Head->bufferSize = (int)(module->writeBioBuffer->length) - bytesSent; + memcpy_s(module->PendingSend_Head->buffer, module->PendingSend_Head->bufferSize, module->writeBioBuffer->data + bytesSent, module->PendingSend_Head->bufferSize); + module->TotalBytesSent += bytesSent; - module->PendingBytesToSend = (unsigned int)(module->writeBioBuffer->length); + module->PendingBytesToSend = (unsigned int)(module->PendingSend_Head->bufferSize); + BIO_reset(module->writeBio); } retVal = ILibAsyncSocket_NOT_ALL_DATA_SENT_YET; } diff --git a/microstack/ILibWebRTC.c b/microstack/ILibWebRTC.c index 269b2dd..b0ca994 100644 --- a/microstack/ILibWebRTC.c +++ b/microstack/ILibWebRTC.c @@ -3098,8 +3098,7 @@ ILibTransport_DoneState ILibStun_SendDtls(struct ILibStun_Module *obj, int sessi { r = (ILibTransport_DoneState)ILibAsyncUDPSocket_SendTo(((struct ILibStun_Module*)obj)->UDP, (struct sockaddr*)obj->dTlsSessions[session]->remoteInterface, obj->dTlsSessions[session]->writeBIOBuffer->data, obj->dTlsSessions[session]->writeBIOBuffer->length, ILibAsyncSocket_MemoryOwnership_USER); } - obj->dTlsSessions[session]->writeBIOBuffer->data += (obj->dTlsSessions[session]->writeBIOBuffer->length); - obj->dTlsSessions[session]->writeBIOBuffer->length = 0; + BIO_reset(obj->dTlsSessions[session]->writeBIO); } return r; } @@ -6124,9 +6123,7 @@ void ILibStun_OnUDP(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer, ILibAsyncUDPSocket_SendTo(((struct ILibStun_Module*)obj)->UDP, (struct sockaddr*)remoteInterface, obj->dTlsSessions[existingSession]->writeBIOBuffer->data, obj->dTlsSessions[existingSession]->writeBIOBuffer->length, ILibAsyncSocket_MemoryOwnership_USER); } if(obj->dTlsSessions[existingSession]->state == 4) {ILibWebRTC_DTLS_HandshakeDetect(obj, "S ", obj->dTlsSessions[existingSession]->writeBIOBuffer->data, 0, (int)obj->dTlsSessions[existingSession]->writeBIOBuffer->length);} - - obj->dTlsSessions[existingSession]->writeBIOBuffer->data += (obj->dTlsSessions[existingSession]->writeBIOBuffer->length); - obj->dTlsSessions[existingSession]->writeBIOBuffer->length = 0; + BIO_reset(obj->dTlsSessions[existingSession]->writeBIO); } sem_post(&(obj->dTlsSessions[existingSession]->Lock)); }