コード例 #1
0
/*
 * corrupt_metadata --
 *	Corrupt the metadata by scribbling on the "corrupt" URI string.
 */
static void
corrupt_metadata(void)
{
	FILE *fp;
	struct stat sb;
	long off;
	size_t meta_size;
	bool corrupted;
	uint8_t *buf, *corrupt;
	char path[256];

	/*
	 * Open the file, read its contents. Find the string "corrupt" and
	 * modify one byte at that offset. That will cause a checksum error
	 * when WiredTiger next reads it.
	 */
	testutil_check(__wt_snprintf(
	    path, sizeof(path), "%s/%s", home, WT_METAFILE));
	if ((fp = fopen(path, "r+")) == NULL)
		testutil_die(errno, "fopen: %s", path);
	testutil_check(fstat(fileno(fp), &sb));
	meta_size = (size_t)sb.st_size;
	buf = dcalloc(meta_size, 1);
	if (fread(buf, 1, meta_size, fp) != meta_size)
		testutil_die(errno, "fread: %" WT_SIZET_FMT, meta_size);
	corrupted = false;
	/*
	 * Corrupt all occurrences of the string in the file.
	 */
	while ((corrupt = byte_str(buf, meta_size, CORRUPT)) != NULL) {
		corrupted = true;
		testutil_assert(*(char *)corrupt != 'X');
		*(char *)corrupt = 'X';
		off = (long)(corrupt - buf);
		if (fseek(fp, off, SEEK_SET) != 0)
			testutil_die(errno, "fseek: %ld", off);
		if (fwrite("X", 1, 1, fp) != 1)
			testutil_die(errno, "fwrite");
	}
	if (!corrupted)
		testutil_die(errno, "corrupt string did not occur");
	if (fclose(fp) != 0)
		testutil_die(errno, "fclose");
	free(buf);
}
コード例 #2
0
    bool NetSelectSocket::read() {
        EPYX_ASSERT(sock);
        const int size = 4096;
        byte data[size];
        int recvSize = sock->recv(data, size);

        // Quit on End-Of-File
        if (recvSize == 0)
            return false;

        // Eat data
        try {
            this->eat(byte_str(data, recvSize));
        } catch (MinorException e) {
            log::error << e << log::endl;
            log::error << "Closing socket to " << sock->getAddress() <<
                " due to an exception" << log::endl;
            return false;
        }
        return sock->isOpened();
    }