result Enrollment::SendData() { String data = ""; ByteBuffer* pTxBuffer = null; ByteBuffer buffer; result res = E_SUCCESS; for (int i = 0; i < 4; i++) { data.Append(__pWorkList[i]->GetText()); data.Append("\n"); } if (data.IsEmpty()) { AppLog("There is no data to send"); return E_SUCCESS; } pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(data); TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer"); AppLog("Text Length %d", pTxBuffer->GetLimit()); buffer.Construct(pTxBuffer->GetLimit()); buffer.CopyFrom(*pTxBuffer); buffer.Flip(); delete pTxBuffer; res = __pSocket->SendTo(buffer, *__pUdpEndpoint); if (res != E_SUCCESS && res != E_WOULD_BLOCK) AppLog("Error sending data"); buffer.Clear(); return res; }
result Enrollment::SendDataCommand(String command) { ByteBuffer* pTxBuffer = null; ByteBuffer buffer; result res = E_SUCCESS; TryReturn(__isTcp == false, E_SYSTEM, "Sending Command not required for TCP connection"); pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(command); TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer"); buffer.Construct(1024); buffer.CopyFrom(*pTxBuffer); delete pTxBuffer; buffer.Flip(); do { if (__pUdpEndpoint != null) { res = __pSocket->SendTo(buffer, *__pUdpEndpoint); } if (res == E_WOULD_BLOCK) { AppLog("Would block for data sending will try to retransmit"); Tizen::Base::Runtime::Thread::Sleep(500); } else if (res != E_SUCCESS) { AppLog("Error sending data"); break; } else { AppLog("Command successfully sent"); break; } } while (1); AppLog("Loop completed"); buffer.Clear(); return res; }