void View::onExtractClick(wxCommandEvent &event) { if (fileInput->GetValue().Len() == 0) { wxMessageBox(wxS("You didn't specify a file."), wxS("Error"), wxOK | wxICON_ERROR, this); return; } else if (!wxFileExists(fileInput->GetValue())) { wxMessageBox(wxS("The specified file does not exist."), wxS("Error"), wxOK | wxICON_ERROR, this); return; } fileInput->Enable(false); browseButton->Enable(false); extractButton->Enable(false); // Start a server socket ServerSocket *server; try { server = ServerSocket::create(wxT("127.0.0.1"), 0); } catch (SocketException &e) { wxString message; message.Printf(wxT("Unable to start a server socket: %s"), e.getMessage().c_str()); wxMessageBox(message, wxS("Error"), wxOK | wxICON_ERROR, this); Close(); return; } // Start the disassembler. wxString command; long pid; command = wxString::Format(wxT("\"%s\" -d -M intel --remote=%d \"%s\""), findObjdump().c_str(), server->getPort(), fileInput->GetValue().c_str()); pid = wxExecute(command, wxEXEC_ASYNC, NULL); if (pid == 0) { delete server; wxMessageBox(wxS("Unable to launch the disassembler."), wxS("Error"), wxOK | wxICON_ERROR, this); Close(); return; } thread = new WorkerThread(pid, server); server->unref(); thread->Create(); thread->Run(); timer.Start(100); }
int64_t readAtMost(ServerSocket &s, char *buf, int64_t max, int64_t atMost) { const int64_t target = atMost < max ? atMost : max; VLOG(3) << "readAtMost target " << target; // because we want to process data as soon as it arrives, tryFull option for // read is false int64_t n = s.read(buf, target, false); if (n < 0) { PLOG(ERROR) << "Read error on " << s.getPort() << " with target " << target; return n; } if (n == 0) { LOG(WARNING) << "Eof on " << s.getFd(); return n; } VLOG(3) << "readAtMost " << n << " / " << atMost << " from " << s.getFd(); return n; }
WdtTransferRequest Receiver::init() { vector<ServerSocket> successfulSockets; for (size_t i = 0; i < threadServerSockets_.size(); i++) { ServerSocket socket = std::move(threadServerSockets_[i]); int max_retries = WdtOptions::get().max_retries; for (int retries = 0; retries < max_retries; retries++) { if (socket.listen() == OK) { break; } } if (socket.listen() == OK) { successfulSockets.push_back(std::move(socket)); } else { LOG(ERROR) << "Couldn't listen on port " << socket.getPort(); } } LOG(INFO) << "Registered " << successfulSockets.size() << " sockets"; ErrorCode code = OK; if (threadServerSockets_.size() != successfulSockets.size()) { code = FEWER_PORTS; if (successfulSockets.size() == 0) { code = ERROR; } } threadServerSockets_ = std::move(successfulSockets); WdtTransferRequest transferRequest(getPorts()); transferRequest.protocolVersion = protocolVersion_; transferRequest.transferId = transferId_; LOG(INFO) << "Transfer id " << transferRequest.transferId; if (transferRequest.hostName.empty()) { char hostName[1024]; int ret = gethostname(hostName, sizeof(hostName)); if (ret == 0) { transferRequest.hostName.assign(hostName); } else { PLOG(ERROR) << "Couldn't find the host name"; code = ERROR; } } transferRequest.directory = destDir_; transferRequest.errorCode = code; return transferRequest; }
void Receiver::receiveOne(int threadIndex, ServerSocket &socket, int64_t bufferSize, TransferStats &threadStats) { INIT_PERF_STAT_REPORT auto guard = folly::makeGuard([&] { perfReports_[threadIndex] = *perfStatReport; // copy when done std::unique_lock<std::mutex> lock(mutex_); numActiveThreads_--; if (numActiveThreads_ == 0) { LOG(WARNING) << "Last thread finished. Duration of the transfer " << durationSeconds(Clock::now() - startTime_); transferFinished_ = true; } }); ThreadData data(threadIndex, socket, threadStats, protocolVersion_, bufferSize); if (!data.getBuf()) { LOG(ERROR) << "error allocating " << bufferSize; threadStats.setErrorCode(MEMORY_ALLOCATION_ERROR); return; } ReceiverState state = LISTEN; while (true) { ErrorCode abortCode = getCurAbortCode(); if (abortCode != OK) { LOG(ERROR) << "Transfer aborted " << socket.getPort() << " " << errorCodeToStr(abortCode); threadStats.setErrorCode(ABORT); incrFailedThreadCountAndCheckForSessionEnd(data); break; } if (state == FAILED) { return; } if (state == END) { if (isJoinable_) { return; } state = ACCEPT_FIRST_CONNECTION; } state = (this->*stateMap_[state])(data); } }