Exemplo n.º 1
0
void ts::server::Resource_download_server::handle_pong_message(const Client_message& client_message)
{
    const auto& client = client_message.client;
    const auto& message = client_message.message;

    const auto pong = downloads::parse_pong_message(message);

    auto client_it = client_downloads_.find(client);
    if (client_it != client_downloads_.end())
    {
        auto& downloads = client_it->second;
        auto search_result = std::find_if(downloads.begin(), downloads.end(),
                                          [pong](const Download_info& download_info)
        {
            return download_info.download_key_ == pong.download_key;
        });

        if (search_result != downloads.end())
        {
            send_file_chunk(*search_result, client);
        }
    }
}
Exemplo n.º 2
0
/* Send a file complete chunk. */
static int
send_file_complete (guestfs_h *g)
{
  char buf[1];
  return send_file_chunk (g, 0, buf, 0);
}
Exemplo n.º 3
0
/* Send a cancellation message. */
static int
send_file_cancellation (guestfs_h *g)
{
  return send_file_chunk (g, 1, NULL, 0);
}
Exemplo n.º 4
0
/* Send a chunk of file data. */
static int
send_file_data (guestfs_h *g, const char *buf, size_t len)
{
  return send_file_chunk (g, 0, buf, len);
}
Exemplo n.º 5
0
int program_device(HANDLE hCom, const char *program_file) {
	int err_cnt, chunk_err_cnt, try, failed_chunks;
	const int nbuff_words = 1024;
	unsigned char buff[nbuff_words*2];
	unsigned short progStart;
	DWORD progSize;
	HANDLE hProg;
	DWORD bytesRead;
	DWORD chunk_size, file_pos, lc3_pos, part, remain;

	hProg = CreateFile(program_file, GENERIC_READ, FILE_SHARE_READ, NULL,
			OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
	if (hProg == INVALID_HANDLE_VALUE) {
		local_message("Unable to open \"%s\" for reading (error: %lu)\n", program_file, GetLastError());
		wait_and_quit();
	}

	progSize = GetFileSize(hProg, NULL);
	progSize = progSize-2; // lc3_offset from file is counted separately

	if (progSize % 2 || progSize > 0x10000) {
		local_message("Error: Obj file's size has to be even and fit into LC3 memory\n");
		CloseHandle(hProg);
		return -1;
	}

	if (!ReadFile(hProg, buff, 4, &bytesRead, NULL)
          || bytesRead<4) {
		local_message("Error: unable to read \"%s\"\n", program_file);
		CloseHandle(hProg);
		return -1;
	}

	// This is obj file, need to calculate transmission size
	progStart = (buff[0] << 8) + buff[1];
	opt_start_address = progStart;

	if (wait_lc3_ready(hCom) < 0) {
		CloseHandle(hProg);
		return -1;
	}

	local_message("\nUploading \"%s\":\n\t%u words starting from x%04x\n",
		      program_file, progSize/2, progStart);

	remain = progSize;
	err_cnt = failed_chunks = 0;
	chunk_size = (arg_chunk_size) ? arg_chunk_size : remain;
	file_pos = 2;
	lc3_pos = progStart*2;  // scale LC3 offset from words to bytes
	while (remain) {
		part = min(remain, chunk_size);

		try = 0;
	Retry:
		if (send_file_chunk(hCom, hProg, file_pos, lc3_pos, part, progSize-remain, progSize) < 0) {
			CloseHandle(hProg);
			return -1;
		}
		local_message("\r%3d%% complete     --  %5lu of %5lu bytes send              ",
				   (int)((progSize-remain+part)*100/progSize), progSize-remain+part, progSize);
		if (!opt_no_program_check) {
			chunk_err_cnt = 0;
			if (check_file_chunk(hCom, hProg, file_pos, lc3_pos, part, &chunk_err_cnt, progSize-remain, progSize) < 0) {
				CloseHandle(hProg);
				return -1;
			} else if (chunk_err_cnt != 0) {
				if (try < arg_retransmit_retry) {
					try++;
					local_message("\r%d errors discovered in chunk. Trying to retransmit (%d time)\n", chunk_err_cnt, try);
					goto Retry;
				} else {
					local_message("\r%d errors discovered in chunk. %d retransmissions failed.\n", chunk_err_cnt, try);
					err_cnt += chunk_err_cnt;
					failed_chunks++;
				}
			} else {
				local_message( (try
								? "\rRetransmission successful.                                      \n"
								: "\r%3d%% complete     --  %5lu of %5lu bytes verified              "),
						(int)((progSize-remain+part)*100/progSize), (progSize-remain+part), progSize);
			}
		}

		remain -= part;
		file_pos += part;
		lc3_pos += part;

	}