Beispiel #1
0
int read_block(int client_socket, const dfs_cli_dn_req_t *request)
{
	assert(client_socket != INVALID_SOCKET);
	assert(request != NULL);
	//char buffer[DFS_BLOCK_SIZE];
	char *buffer = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE);
	ext_read_block(request->block.owner_name, request->block.block_id, (void *)buffer);

	//TODO:response the client with the data
	printf("dfs_datanode.c: read_block(): Sending block to client. \n");
	if (send(client_socket, buffer, DFS_BLOCK_SIZE, 0) == -1) printf("dfs_datanode.c: read_block(): Send failure. \n");
	
	free(buffer);
	return 0;
}
Beispiel #2
0
//Reads a block from the specified socket
int read_block(int client_socket, const dfs_cli_dn_req_t *request)
{
	assert(client_socket != INVALID_SOCKET);
	assert(request != NULL);
	char buffer[DFS_BLOCK_SIZE];
	ext_read_block(request->block.owner_name, request->block.block_id, (void *)buffer);
	
	//Respond to the client with the data
	dfs_cm_block_t block_to_return;
	memset(&block_to_return, 0, sizeof(block_to_return));

	strcpy(block_to_return.owner_name, request->block.owner_name);
	block_to_return.dn_id = datanode_id;
	block_to_return.block_id = request->block.block_id;
	strcpy(block_to_return.content, buffer);

	send_data(client_socket, &block_to_return, sizeof(block_to_return));
	return 0;
}