当前位置: 首页>>代码示例>>C++>>正文


C++ readx函数代码示例

本文整理汇总了C++中readx函数的典型用法代码示例。如果您正苦于以下问题:C++ readx函数的具体用法?C++ readx怎么用?C++ readx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: adb_status

int adb_status(int fd)
{
    unsigned char buf[5];
    unsigned len;

    if(readx(fd, buf, 4)) {
        strcpy(__adb_error, "protocol fault (no status)");
        return -1;
    }

    if(!memcmp(buf, "OKAY", 4)) {
        return 0;
    }

    if(memcmp(buf, "FAIL", 4)) {
        sprintf(__adb_error,
                "protocol fault (status %02x %02x %02x %02x?!)",
                buf[0], buf[1], buf[2], buf[3]);
        return -1;
    }

    if(readx(fd, buf, 4)) {
        strcpy(__adb_error, "protocol fault (status len)");
        return -1;
    }
    buf[4] = 0;
    len = strtoul((char*)buf, 0, 16);
    if(len > 255) len = 255;
    if(readx(fd, __adb_error, len)) {
        strcpy(__adb_error, "protocol fault (status read)");
        return -1;
    }
    __adb_error[len] = 0;
    return -1;
}
开发者ID:2Habibie,项目名称:platform_system_core,代码行数:35,代码来源:adb_client.c

示例2: main

int main(const int argc, const char *argv[]) {
    char buf[BUFFER_MAX];
    struct sockaddr addr;
    socklen_t alen;
    int lsocket, s, count;

    if (initialize_globals() < 0) {
        LOGE("Could not initialize globals; exiting.\n");
        exit(1);
    }

    if (initialize_directories() < 0) {
        LOGE("Could not create directories; exiting.\n");
        exit(1);
    }

    lsocket = android_get_control_socket(SOCKET_PATH);
    if (lsocket < 0) {
        LOGE("Failed to get socket from environment: %s\n", strerror(errno));
        exit(1);
    }
    if (listen(lsocket, 5)) {
        LOGE("Listen on socket failed: %s\n", strerror(errno));
        exit(1);
    }
    fcntl(lsocket, F_SETFD, FD_CLOEXEC);

    for (;;) {
        alen = sizeof(addr);
        s = accept(lsocket, &addr, &alen);
        if (s < 0) {
            LOGE("Accept failed: %s\n", strerror(errno));
            continue;
        }
        fcntl(s, F_SETFD, FD_CLOEXEC);

        LOGI("new connection\n");
        for (;;) {
            unsigned short count;
            if (readx(s, &count, sizeof(count))) {
                LOGE("failed to read size\n");
                break;
            }
            if ((count < 1) || (count >= BUFFER_MAX)) {
                LOGE("invalid size %d\n", count);
                break;
            }
            if (readx(s, buf, count)) {
                LOGE("failed to read command\n");
                break;
            }
            buf[count] = 0;
            if (execute(s, buf)) break;
        }
        LOGI("closing connection\n");
        close(s);
    }

    return 0;
}
开发者ID:F4k,项目名称:android_framework_base,代码行数:60,代码来源:installd.c

示例3: D

char *adb_query(const char *service) {
    char buf[5];
    unsigned n;
    char *tmp;

    D("adb_query: %s\n", service);
    int fd = adb_connect(service);
    if(fd < 0) {
        fprintf(stderr,"error: %s\n", __adb_error);
        return 0;
    }

    if(readx(fd, buf, 4)) goto oops;

    buf[4] = 0;
    n = strtoul(buf, 0, 16);
    if(n >= 0xffff) {
        strcpy(__adb_error, "reply is too long (>= 64kB)");
        goto oops;
    }

    tmp = malloc(n + 1);
    if(tmp == 0) goto oops;

    if(readx(fd, tmp, n) == 0) {
        tmp[n] = 0;
        adb_close(fd);
        return tmp;
    }
    free(tmp);

oops:
    adb_close(fd);
    return 0;
}
开发者ID:wiiiky,项目名称:pyadb,代码行数:35,代码来源:adb_client.c

示例4: remote_read

static int remote_read(apacket *p, atransport *t)
{
    if(readx(t->sfd, &p->msg, sizeof(amessage))){
        D("remote local: read terminated (message)\n");
        return -1;
    }

    fix_endians(p);

#if 0 && defined __ppc__
    D("read remote packet: %04x arg0=%0x arg1=%0x data_length=%0x data_check=%0x magic=%0x\n",
      p->msg.command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->msg.data_check, p->msg.magic);
#endif
    if(check_header(p)) {
        D("bad header: terminated (data)\n");
        return -1;
    }

    if(readx(t->sfd, p->data, p->msg.data_length)){
        D("remote local: terminated (data)\n");
        return -1;
    }

    if(check_data(p)) {
        D("bad data: terminated (data)\n");
        return -1;
    }

    return 0;
}
开发者ID:Markgorden,项目名称:SafeUSBDisk,代码行数:30,代码来源:transport_local.c

示例5: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    char x[512];

    struct fbinfo fbinfo;
    int w, h, f;
    int s[2];
    int fb;
    unsigned int i;
    int rv;

    if(adb_socketpair(s)) {
        printf("cannot create service socket pair\n");
        goto done;
    }

    pid_t pid = fork();
    if (pid < 0) {
        printf("- fork failed: %s -\n", strerror(errno));
        goto done;
    }

    if (pid == 0) {
        dup2(s[1], STDOUT_FILENO);
        const char* cmd_path = "/system/bin/screencap";
        const char* cmd = "screencap";
        execl(cmd_path, cmd, NULL);
        exit(1);
    }

    fb = s[0];

    /* read w, h, f */
    if (readx(fb, &w, 4)) goto done;
    if (readx(fb, &h, 4)) goto done;
    if (readx(fb, &f, 4)) goto done;

    fbinfo.version = DDMS_RAWIMAGE_VERSION;
    fbinfo.size = w * h * 4;
    fbinfo.width = w;
    fbinfo.height = h;
    rv = fill_format(&fbinfo, f);
    if (rv != 0) goto done;

    if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;

    for(i = 0; i < fbinfo.size; i += sizeof(x)) {
        if(readx(fb, &x, sizeof(x))) goto done;
        if(writex(fd, &x, sizeof(x))) goto done;
    }

    if(readx(fb, &x, fbinfo.size % sizeof(x))) goto done;
    if(writex(fd, &x, fbinfo.size % sizeof(x))) goto done;

done:
    adb_close(s[0]);
    adb_close(s[1]);
    adb_close(fd);
}
开发者ID:OMFGB,项目名称:system_core,代码行数:59,代码来源:framebuffer_service.c

示例6: file_sync_service

void file_sync_service(int fd, void *cookie)
{
    syncmsg msg;
    char name[1025];
    unsigned namelen;

    char *buffer = malloc(SYNC_DATA_MAX);
    if(buffer == 0) goto fail;

    for(;;) {
        D("sync: waiting for command\n");

        if(readx(fd, &msg.req, sizeof(msg.req))) {
            fail_message(fd, "command read failure");
            break;
        }
        namelen = ltohl(msg.req.namelen);
        if(namelen > 1024) {
            fail_message(fd, "invalid namelen");
            break;
        }
        if(readx(fd, name, namelen)) {
            fail_message(fd, "filename read failure");
            break;
        }
        name[namelen] = 0;

        msg.req.namelen = 0;
        D("sync: '%s' '%s'\n", (char*) &msg.req, name);

        switch(msg.req.id) {
        case ID_STAT:
            if(do_stat(fd, name)) goto fail;
            break;
        case ID_LIST:
            if(do_list(fd, name)) goto fail;
            break;
        case ID_SEND:
            if(do_send(fd, name, buffer)) goto fail;
            break;
        case ID_RECV:
            if(do_recv(fd, name, buffer)) goto fail;
            break;
        case ID_QUIT:
            goto fail;
        default:
            fail_message(fd, "unknown command");
            goto fail;
        }
    }

fail:
    if(buffer != 0) free(buffer);
    D("sync: done\n");
    adb_close(fd);
}
开发者ID:0omega,项目名称:platform_system_core,代码行数:56,代码来源:file_sync_service.c

示例7: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    struct fb_var_screeninfo vinfo;
    int fb, offset;
    char x[256];

    struct fbinfo fbinfo;
    unsigned i, bytespp;

    fb = open("/dev/graphics/fb0", O_RDONLY);
    if(fb < 0) goto done;

    if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
    fcntl(fb, F_SETFD, FD_CLOEXEC);

    bytespp = vinfo.bits_per_pixel / 8;

    fbinfo.version = DDMS_RAWIMAGE_VERSION;
    fbinfo.bpp = vinfo.bits_per_pixel;
    fbinfo.size = vinfo.xres * vinfo.yres * bytespp;
    fbinfo.width = vinfo.xres;
    fbinfo.height = vinfo.yres;
    fbinfo.red_offset = vinfo.red.offset;
    fbinfo.red_length = vinfo.red.length;
    fbinfo.green_offset = vinfo.green.offset;
    fbinfo.green_length = vinfo.green.length;
    fbinfo.blue_offset = vinfo.blue.offset;
    fbinfo.blue_length = vinfo.blue.length;
    fbinfo.alpha_offset = vinfo.transp.offset;
    fbinfo.alpha_length = vinfo.transp.length;

    /* HACK: for several of our 3d cores a specific alignment
     * is required so the start of the fb may not be an integer number of lines
     * from the base.  As a result we are storing the additional offset in
     * xoffset. This is not the correct usage for xoffset, it should be added
     * to each line, not just once at the beginning */
    offset = vinfo.xoffset * bytespp;

    offset += vinfo.xres * vinfo.yoffset * bytespp;

    if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;

    lseek(fb, offset, SEEK_SET);
    for(i = 0; i < fbinfo.size; i += 256) {
      if(readx(fb, &x, 256)) goto done;
      if(writex(fd, &x, 256)) goto done;
    }

    if(readx(fb, &x, fbinfo.size % 256)) goto done;
    if(writex(fd, &x, fbinfo.size % 256)) goto done;

done:
    if(fb >= 0) close(fb);
    close(fd);
}
开发者ID:2fast4u88,项目名称:oxygen_system_core,代码行数:55,代码来源:framebuffer_service.c

示例8: main

int main(const int argc, const char *argv[])
{
	int server_fd, client_fd;
	int read_size;
	short cmd_len;
	struct sockaddr addr;
	socklen_t alen;

	info_sys("backuprestore service start!");

	if ((server_fd = srv_create_sk()) < 0)
		err_sys("create socket server error");
	alen = sizeof(addr);

	info_sys("Server socket create successfully!");

	while(1){
		client_fd = accept(server_fd, (struct sockaddr*) &addr, &alen);
		if (client_fd < 0) {
			debug_sys("socket accept failed, please try again!");
			continue;
		}
		info_sys("before excute");
		while (1) {
			cmd_len = 0;
			if (readx(client_fd, &cmd_len, sizeof(cmd_len)) <= 0){
				debug_sys("cmd length read fail");
				break;
			}

			if (cmd_len < 1 || cmd_len > 2048){
				debug_sys("cmd length is not right");
				break;
			}

			if (readx(client_fd, &cmd, cmd_len) <= 0){
				debug_sys("read cmd fail");
				break;
			}
			cmd[cmd_len] = 0;
			if (excute(client_fd, cmd) < 0)
				break;
		}
		close(client_fd);
	}
	close(server_fd);
	info_sys("backuprestore service end!");
	return EXIT_SUCCESS;
}
开发者ID:ferhung,项目名称:p201-mediatek,代码行数:49,代码来源:backup_restore_service.c

示例9: sync_readtime

int sync_readtime(int fd, const char *path, unsigned int *timestamp,
                  unsigned int *mode)
{
    syncmsg msg;
    int len = strlen(path);

    msg.req.id = ID_STAT;
    msg.req.namelen = htoll(len);

    if(writex(fd, &msg.req, sizeof(msg.req)) ||
       writex(fd, path, len)) {
        return -1;
    }

    if(readx(fd, &msg.stat, sizeof(msg.stat))) {
        return -1;
    }

    if(msg.stat.id != ID_STAT) {
        return -1;
    }

    *timestamp = ltohl(msg.stat.time);
    *mode = ltohl(msg.stat.mode);
    return 0;
}
开发者ID:phybio,项目名称:adb,代码行数:26,代码来源:file_sync_client.c

示例10: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    struct fb_var_screeninfo vinfo;
    int fb;
    void *ptr = MAP_FAILED;
    char x;

    unsigned fbinfo[4];

    fb = open("/dev/graphics/fb0", O_RDONLY);
    if(fb < 0) goto done;

    if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
    fcntl(fb, F_SETFD, FD_CLOEXEC);

    fbinfo[0] = 16;
    fbinfo[1] = vinfo.xres * vinfo.yres * 2;
    fbinfo[2] = vinfo.xres;
    fbinfo[3] = vinfo.yres;

    ptr = mmap(0, fbinfo[1], PROT_READ, MAP_SHARED, fb, 0);
    if(ptr == MAP_FAILED) goto done;

    if(writex(fd, fbinfo, sizeof(unsigned) * 4)) goto done;

    for(;;) {
        if(readx(fd, &x, 1)) goto done;
        if(writex(fd, ptr, fbinfo[1])) goto done;
    }

done:
    if(ptr != MAP_FAILED) munmap(ptr, fbinfo[1]);
    if(fb >= 0) close(fb);
    close(fd);
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:35,代码来源:framebuffer_service.c

示例11: getkval

int
getkval(unsigned long offset, caddr_t ptr, int size, char *refstr)

{
    int upper_2gb = 0;

    /* reads above 2Gb are done by seeking to offset%2Gb, and supplying
     * 1 (opposed to 0) as fourth parameter to readx (see 'man kmem')
     */
    if (offset > 1<<31) {
	upper_2gb = 1;
	offset &= 0x7fffffff;
    }

    if (lseek(kmem, offset, SEEK_SET) != offset) {
	fprintf(stderr, "top: lseek failed\n");
	quit(2);
    }

    if (readx(kmem, ptr, size, upper_2gb) != size) {
	if (*refstr == '!')
	    return 0;
	else {
	    fprintf(stderr, "top: kvm_read for %s: %s\n", refstr,
		    sys_errlist[errno]);
	    quit(2);
	}
    }

    return 1 ;
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:31,代码来源:m_aix43.c

示例12: upload

static int upload(int s, int txfd, int txlen) {
	char buf[65536];
	msg_hdr_t hdr;

	while (txlen > 0) {
		int xfer = (txlen > 65536) ? 65536 : txlen;
		if (readx(txfd, buf, xfer)) {
			fprintf(stderr, "error: reading from file\n");
			return -1;
		}
		hdr.opcode = MSG_SEND_DATA;
		hdr.extra = 0;
		hdr.length = xfer - 1;
		if (write(s, &hdr, sizeof(hdr)) != sizeof(hdr)) {
			fprintf(stderr, "error: writing socket\n");
			return -1;
		}
		if (write(s, buf, xfer) != xfer) {
			fprintf(stderr, "error: writing socket\n");
			return -1;
		}
		txlen -= xfer;
	}
	hdr.opcode = MSG_END_DATA;
	hdr.extra = 0;
	hdr.length = 0;
	if (write(s, &hdr, sizeof(hdr)) != sizeof(hdr)) {
		fprintf(stderr, "error: writing socket\n");
		return -1;
	}
	return 0;
}
开发者ID:chychc,项目名称:lk,代码行数:32,代码来源:liblkboot.c

示例13: main

int main(){

	int i,j,k,l,k1,l1,test,t=1,q,ans;

	//freopen("in.txt","r",stdin);
	
	scanf("%d",&test);

	while(test--){
		
		memset(tree,0,sizeof(tree));
		memset(fl,0,sizeof(fl));
		scanf("%d",&q);
		printf("Case %d:\n",t++);
		for(i=1;i<=q;i++){
			scanf("%d",&j);
			if(j==0){
				scanf("%d %d",&k,&l);
				k++; l++;
				if(fl[k][l]) continue;
				fl[k][l]=1;
				updatex(k,l,1);
			}
			else{
				scanf("%d %d %d %d",&k,&l,&k1,&l1);
				k++; l++; k1++; l1++;
				ans=readx(k1,l1);
				ans-=readx(k1,l);
				ans-=readx(k,l1);
				ans+=readx(k,l);
				for(j=k;j<=k1;j++){
					if(fl[j][l]) ans++;
				}
				for(j=l;j<=l1;j++){
					if(fl[k][j]) ans++;
				}
				if(fl[k][l]) ans--;
				//ans-=readx(k,l-1);
				//ans+=readx(k-1,l-1);
				printf("%d\n",ans);
			}
		}

	}

	return 0;
}
开发者ID:JohnXinhua,项目名称:Algorithm_ACM,代码行数:47,代码来源:1266+Points+in+rectangle.cpp

示例14: adb_download_buffer

int adb_download_buffer(const char *service, const void* data, int sz,
                        unsigned progress)
{
    char buf[4096];
    unsigned total;
    int fd;
    const unsigned char *ptr;

    sprintf(buf,"%s:%d", service, sz);
    fd = adb_connect(buf);
    if(fd < 0) {
        fprintf(stderr,"error: %s\n", adb_error());
        return -1;
    }

    int opt = CHUNK_SIZE;
    opt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const char *)&opt, sizeof(opt));

    total = sz;
    ptr = (const unsigned char *)data;

    if(progress) {
        char *x = strrchr((char*)service, ':');
        if(x) service = x + 1;
    }

    while(sz > 0) {
        unsigned xfer = (sz > CHUNK_SIZE) ? CHUNK_SIZE : sz;
        if(writex(fd, ptr, xfer)) {
            adb_status(fd);
            fprintf(stderr,"* failed to write data '%s' *\n", adb_error());
            return -1;
        }
        sz -= xfer;
        ptr += xfer;
        if(progress) {
            printf("sending: '%s' %4d%%    \r", service, (int)(100LL - ((100LL * sz) / (total))));
            fflush(stdout);
        }
    }
    if(progress) {
        printf("\n");
    }

    if(readx(fd, buf, 4)){
        fprintf(stderr,"* error reading response *\n");
        adb_close(fd);
        return -1;
    }
    if(memcmp(buf, "OKAY", 4)) {
        buf[4] = 0;
        fprintf(stderr,"* error response '%s' *\n", buf);
        adb_close(fd);
        return -1;
    }

    adb_close(fd);
    return 0;
}
开发者ID:JustFFunny,项目名称:WorkSpace,代码行数:59,代码来源:commandline.cpp

示例15: read_list

static ptr read_list() {
  INT t; ptr v, x;

  t = read_token(&v);
  if (t == r_RPAREN) return Snil;
  x = readx(t, v);
  return Scons(x, read_list());
}
开发者ID:1u4nx,项目名称:ChezScheme,代码行数:8,代码来源:itest.c


注:本文中的readx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。