Some changes to socket handling

This commit is contained in:
Huntereb 2020-09-25 12:07:45 -04:00
parent 0c929ca357
commit 1446217d1e
4 changed files with 20 additions and 8 deletions

View File

@ -22,6 +22,8 @@ SOFTWARE.
#include <vector>
namespace netInstStuff {
void OnUnwound();
void sendExitCommands();
void installTitleNet(std::vector<std::string> ourUrlList, int ourStorage, std::vector<std::string> urlListAltNames, std::string ourSource);
std::vector<std::string> OnSelected();
}

View File

@ -108,6 +108,17 @@ namespace netInstStuff{
curl_global_cleanup();
}
void sendExitCommands()
{
LOG_DEBUG("Telling the server we're done installing\n");
// Send 1 byte ack to close the server, OG tinfoil compatibility
u8 ack = 0;
tin::network::WaitSendNetworkData(m_clientSocket, &ack, sizeof(u8));
// Send 'DEAD\r\n' so ns-usbloader knows we're done
//u8 nsUsbAck [6] = {0x44,0x45,0x41,0x44,0x0D,0x0A};
//tin::network::WaitSendNetworkData(m_clientSocket, &nsUsbAck, sizeof(u8) * 6);
}
void installTitleNet(std::vector<std::string> ourUrlList, int ourStorage, std::vector<std::string> urlListAltNames, std::string ourSource)
{
inst::util::initInstallServices();
@ -178,10 +189,8 @@ namespace netInstStuff{
inst::util::setClockSpeed(2, previousClockValues[2]);
}
LOG_DEBUG("Telling the server we're done installing\n");
// Send 1 byte ack to close the server
u8 ack = 0;
tin::network::WaitSendNetworkData(m_clientSocket, &ack, sizeof(u8));
sendExitCommands();
OnUnwound();
if(nspInstalled) {
inst::ui::instPage::setInstInfoText("inst.info_page.complete"_lang);
@ -206,8 +215,6 @@ namespace netInstStuff{
u64 freq = armGetSystemTickFreq();
u64 startTime = armGetSystemTick();
OnUnwound();
try
{
ASSERT_OK(curl_global_init(CURL_GLOBAL_ALL), "Curl failed to initialized");

View File

@ -156,6 +156,9 @@ namespace inst::ui {
void netInstPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) {
if (Down & KEY_B) {
if (this->menu->GetItems().size() > 0) {}
netInstStuff::sendExitCommands();
netInstStuff::OnUnwound();
mainApp->LoadLayout(mainApp->mainPage);
}
if ((Down & KEY_A) || (Up & KEY_TOUCH)) {

View File

@ -235,7 +235,7 @@ namespace tin::network
int ret = 0;
size_t read = 0;
while ((((ret = recv(sockfd, (u8*)buf + read, len - read, 0)) > 0 && (read += ret) < len) || errno == EAGAIN) && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B))
while ((((ret = recv(sockfd, (u8*)buf + read, len - read, 0)) > 0 && (read += ret) < len) || errno == EAGAIN))
{
errno = 0;
}
@ -249,7 +249,7 @@ namespace tin::network
int ret = 0;
size_t written = 0;
while ((((ret = send(sockfd, (u8*)buf + written, len - written, 0)) > 0 && (written += ret) < len) || errno == EAGAIN) && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B))
while ((((ret = send(sockfd, (u8*)buf + written, len - written, 0)) > 0 && (written += ret) < len) || errno == EAGAIN))
{
errno = 0;
}