示例#1
0
static long readfile(int sock,FILE *f)
{
	int partition_id;
	if (!sendLong(sock, partition_id))
        return kReadFileFailure;
    long filesize;
    if (!readlong(sock, &filesize))
        return kReadFileFailure;
    if (filesize > 0)
    {
        char buffer[1024];
        do
        {
            int num = min(filesize, sizeof(buffer));
            if (!readdata(sock, buffer, num))
                return kReadFileFailure;
            int offset = 0;
            do
            {
                size_t written = fwrite(&buffer[offset], 1, num-offset, f);
                if (written < 1)
                    return kReadFileFailure;
                offset += written;
            }
            while (offset < num);
            filesize -= num;
        }
        while (filesize > 0);
    }
    return partition_id;
}
示例#2
0
void Server::handleGetFirstId()
{
    // "tp_hash" is not the same as "oid", but we can still use
    // the class GitOid for tp_hashes.
    GitOid tp_hash = recvOid();

    std::pair<int, int> first_ids = m_db->getFirstId(tp_hash);
    int first_id = first_ids.first;
    int id_count = first_ids.second;

    if (first_id == 0) {
        char tp_hash_str[GIT_OID_HEXSZ + 1];
        tp_hash_str[GIT_OID_HEXSZ] = '\0';
        git_oid_fmt(tp_hash_str, tp_hash.oid());
        printf("First ID not found for this tp_hash: %s\n", tp_hash_str);
    }

    // "first_id == 0" means that the given tp_hash is unknown.
    sendLong((uint32_t)first_id);
    sendLong((uint32_t)id_count);
}
示例#3
0
void Server::handleGetFirstIdMulti()
{
    size_t count = (size_t)recvLong();
    for (size_t i = 0; i < count; ++i) {
        GitOid tp_hash = recvOid();

        std::pair<int, int> first_ids = m_db->getFirstId(tp_hash);
        int first_id = first_ids.first;
        int id_count = first_ids.second;

        if (first_id == 0) {
            char tp_hash_str[GIT_OID_HEXSZ + 1];
            tp_hash_str[GIT_OID_HEXSZ] = '\0';
            git_oid_fmt(tp_hash_str, tp_hash.oid());
            printf("First ID not found for this tp_hash: %s\n", tp_hash_str);
        }

        // "first_id == 0" means that the given tp_hash is unknown.
        sendLong((uint32_t)first_id);
        sendLong((uint32_t)id_count);
    }
}
示例#4
0
void Server::sendLongVector(std::vector<int> vec)
{
    sendLong((uint32_t)vec.size());
    sendLongArray(vec);
}