void respond_put(t_socket *connection, t_message packet) { t_message message = receive(connection); unsigned long size; memcpy(&size, message.data, sizeof(unsigned long)); if (size > free_disk_space()) { connection->window_index = message.sequence + 1; send_message(connection, error_message(3, message.sequence)); return; } send_ack(connection, message.sequence); FILE *fp = fopen(packet.data, "wb"); t_message next; do { next = receive(connection); if (next.type == TYPE_EOF) break; if (next.type == TYPE_DATA) { fwrite(next.data, next.size - 3, 1, fp); free(next.data); } } while (1); fclose(fp); }
u64 DiskCachingFileLoaderCache::FreeDiskSpace() { std::string dir = cacheDir_; if (dir.empty()) { dir = GetSysDirectory(DIRECTORY_CACHE); } uint64_t result = 0; if (free_disk_space(dir, result)) { return result; } // We can't know for sure how much is free, so we have to assume none. return 0; }