예제 #1
0
파일: ifm.c 프로젝트: openpts/openpts
// http://linux.die.net/man/2/sendfile
// sendfile - transfer data between file descriptors
// TODO offset?
ssize_t my_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
    char buf[SENDFILE_BUF_SIZE];
    ssize_t read_size;
    ssize_t write_size;
    ssize_t sum = 0;

    DEBUG_IFM("my_sendfile(), size=%d ############################\n", count);

    do {
        /* set read size */
        if ((count - sum) > SENDFILE_BUF_SIZE) {
            read_size = SENDFILE_BUF_SIZE;
        } else {
            read_size = count - sum;
        }

        /* read */
        read_size = wrapRead(in_fd, buf, read_size);
        if (read_size < 0) {
            // sum = -1;
            break;
        }

        /* write */
        write_size = wrapWrite(out_fd, buf, read_size);

        if (write_size < 0) {
            LOG(LOG_ERR, "\n");
            sum = -1;
            break;
        }
        if (write_size != read_size) {
            LOG(LOG_ERR, "\n");
            sum = -1;
            break;
        }

        sum += write_size;
    } while (sum < (ssize_t) count);

    return sum;
}
예제 #2
0
파일: ifm.c 프로젝트: openpts/openpts
/**
 * write IF-M PTS message ()
 *
 * we are using sendfile() here and send the data steb by step. 
 * but IF-M of IMC/IMV version need to create whole blob to send.
 *
 * v0.2.4 - sendfile() not work with ptsc. use my_sendfile()
 *
 * Retrun
 *  length of write data
 *  -1 ERROR
 */
int writePtsTlv(OPENPTS_CONTEXT *ctx, int fdout, int type) {
    int rc = -1;
    BYTE *message;
    int length = 0;
    int len;

    DEBUG_CAL("writePtsTlvToSock - start\n");

    /* check */
    if (ctx == NULL) {
        LOG(LOG_ERR, "null input");
        return -1;
    }

    message = getPtsTlvMessage(ctx, type, &length);
    if (message != NULL) {
        rc = wrapWrite(fdout, message, length);
        DEBUG_IFM("writePtsTlv - type=%d, length = %d", type, length);
    } else {
        DEBUG_IFM("getPtsTlvMessage() is null");
        goto error;
    }

    DEBUG_CAL("writePtsTlvToSock - done\n");

    /* done */
    rc = length;
    return rc;

  error:
    DEBUG_IFM("writePtsTlvToSock() fail, send error mgs\n");

    /* send ERROR */
    len = writePtsTlv(ctx, fdout, OPENPTS_ERROR);
    if (len < 0) {
        LOG(LOG_ERR, "send OPENPTS_ERROR was faild");
    }

    return -1;
}
예제 #3
0
void init(int *p, int size, int hotCache)
{
	WRAPTOKEN w = wrapOpen();
	int i;
	for (i=0; i  < size; i++)
		wrapWrite((p + i), &i, sizeof(int), w);
	wrapClose(w);

//  TODO for hot cache will need to have started stats before here!

	int *f = p;
	if (!hotCache)
	{
		printf("Flusing cache.\n");
		for (i = 0; i < size; i+=IntsPerLine)
		{
			f = p + i;
			//printf("clfush(%p)\n", f);
			clflush(f);
		}
	}
	p_msync();
}