• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ readn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: while

int Session::on_read_event()
{
    int ret;
    while (true)
    {
        if (!m_has_head)
        {
            ret = read_head();
            if (ret < 0)
            {
                return -1;
            }
            if (ret == SESSION_RET_NO_DATA)
            {
                return 0;
            }
            if (m_msg_type == MSG_HEART_BEAT)
            {
                if (g_is_master)
                {
                    update_active_time();
                }
                else
                {
                    struct commu_msg msg;
                    msg.ip = get_cli_addr();
                    msg.msg = MSG_HEART_BEAT;
                    notify_master(msg);
                }
                continue;
            }
            m_has_head = true;
            m_buff = (u_char *)glb_mempool()->get(m_msg_len);
        }
        int n_read = readn(m_sockfd, &m_buff[m_n_read], m_msg_len - m_n_read);
        if (n_read < 0)
        {
            logerr("socket broken\n");
            m_msg_len = 0;
            m_has_head = false;
            return -1;
        }
        m_n_read += n_read;
        if (m_n_read == m_msg_len)
        {
            write_msg(m_buff, m_msg_len);
            reset_buffer();
        }
    }
    return 0;

}
开发者ID:adan830,项目名称:simplesvr,代码行数:52,代码来源:session.cpp


示例2: vncrdstringx

/*
 * on the server side of the negotiation protocol, we read
 * the client response and then run the negotiated function.
 * in some cases (e.g., TLS) the negotiated function needs to
 * use v->datafd directly and be sure that no data has been
 * buffered away in the Bio.  since we know the client is waiting
 * for our response, it won't have sent any until we respond.
 * thus we read the response with vncrdstringx, which goes
 * behind bio's back.
 */
char*
vncrdstringx(Vnc *v)
{
	char tmp[4];
	char *s;
	ulong len;

	assert(Bbuffered(&v->in) == 0);
	if(readn(v->datafd, tmp, 4) != 4){
		fprint(2, "cannot rdstringx: %r");
		vnchungup(v);
	}
	len = LONG(tmp);
	s = malloc(len+1);
	assert(s != nil);
	if(readn(v->datafd, s, len) != len){
		fprint(2, "cannot rdstringx len %lud: %r", len);
		vnchungup(v);
	}
	s[len] = '\0';
	return s;
}
开发者ID:AustenConrad,项目名称:plan-9,代码行数:32,代码来源:proto.c


示例3: priv_sock_get_int

int priv_sock_get_int(int fd)
{
	int the_int;
	int ret;
	ret = readn(fd, &the_int, sizeof(the_int));
	if (ret != sizeof(the_int))
	{
		fprintf(stderr, "priv_sock_get_int error\n");
		exit(EXIT_FAILURE);
	}

	return the_int;
}
开发者ID:Tachone,项目名称:Tachftp,代码行数:13,代码来源:privsock.c


示例4: sckClient_rcv

int sckClient_rcv(void *handle, unsigned char *out, int *outlen)
{
    int ret = 0;
    SckHandle *tmp = handle;
    ret = read_timeout(tmp->sockfd, tmp->recvtime);
    if(ret < 0){
        if(ret == -1 && errno == ETIMEDOUT){
            ret = SCK_ERRTIMEOUT;
            printf("sckClient_rcv() err: %d\n", ret);
            return ret;
        }

        return ret;
    }
    int netdatalen = 0;
    ret = readn(tmp->sockfd, &netdatalen, 4);
    if(ret == -1 ){
        printf("func sckClient_rcv() first err: %d\n", ret);
        return ret;
    }else if(ret < 4){
        ret = SCK_ERRPEERCLOSED;
        printf("func sckClient_rcv() first err: %d\n", ret);
        return ret;
    }
    int n;
    n = ntohl(netdatalen);
    ret = readn(tmp->sockfd, out, n);
    if(ret == -1 ){
        printf("func sckClient_rcv() second err: %d\n", ret);
        return ret;
    }else if(ret < n){
        ret = SCK_ERRPEERCLOSED;
        printf("func sckClient_rcv() second err: %d\n", ret);
        return ret;
    }
    *outlen = n;

    return 0;
}
开发者ID:xsun89,项目名称:linuxstudy,代码行数:39,代码来源:commsocket.c


示例5: priv_sock_get_result

char priv_sock_get_result(int fd)
{
    char res;
    int ret;
    ret = readn(fd, &res, sizeof(res));
    if (ret != sizeof(res))
    {
        fprintf(stderr, "priv_sock_get_result error\n");
        exit(EXIT_FAILURE);
    }

    return res;
}
开发者ID:yosef-gao,项目名称:miniftpd,代码行数:13,代码来源:privsock.c


示例6: xread

static void
xread(Ioclust *c)
{
	int n;
	Xdata *dev;

	dev = c->dev;
	seek(dev->dev, (vlong)c->addr * Sectorsize, 0);
	n = readn(dev->dev, c->iobuf, BUFPERCLUST*Sectorsize);
	if(n < Sectorsize)
		error("I/O read error");
	c->nbuf = n/Sectorsize;
}
开发者ID:srk-cmu,项目名称:9problems,代码行数:13,代码来源:iobuf.c


示例7: usc_mrcp_asr_destroy

int usc_mrcp_asr_destroy(HANDLE_MRCPINTF asr)
{
    char buf[48];
    off_t offset = 0;
    PUSH_FUN(buf, offset, sizeof(buf));
    PUSH_HEAD(buf, offset, sizeof(buf));

    writen(asr, buf, offset + 4);
    /*read return value*/
    readn(asr, buf, 8);
    close(asr);
    return 0;
}
开发者ID:Luci4r,项目名称:recycle_bin,代码行数:13,代码来源:libusc_mrcp.c


示例8: doread

char *
doread(Ram *r, int64_t off, int32_t cnt)
{
	int n;

	seek(tapefile, Tblock*r->addr + off, 0);
	if (cnt > sizeof dblock.tbuf)
		error("read too big");
	n = readn(tapefile, dblock.tbuf, cnt);
	if (n != cnt)
		memset(dblock.tbuf + n, 0, cnt - n);
	return dblock.tbuf;
}
开发者ID:aahud,项目名称:harvey,代码行数:13,代码来源:tarfs.c


示例9: readline

ssize_t readline(int sockfd, void *buf, size_t maxline)
{
    int ret;
    int nread;
    char *bufp = (char *)buf;
    int nleft = maxline;
    while(nleft > 0)
    {
        ret = recv_peek(sockfd, bufp, nleft);
        if(ret < 0)
            return ret;
        else if(ret == 0)
            return 0;

        nread = ret;
        int i;
        for(i=0; i<nread; i++){
            if(bufp[i] == '\n') {
                ret = readn(sockfd, bufp, i + 1);
                if( ret != i+1)
                    exit(-1);

                return ret;
            }
        }
        if(nread > nleft)
            exit(-1);

        nleft -= nread;
        ret = readn(sockfd, bufp, nread);
        if(ret != nread)
            exit(-1);

        bufp += nread;

    }

    return -1;
}
开发者ID:xsun89,项目名称:linuxstudy,代码行数:39,代码来源:commsocket.c


示例10: readline

ssize_t readline(int fd, void *buf, size_t maxlen)
{
	size_t nleft = maxlen - 1;
	char *bufp = (char *)buf;
	ssize_t total = 0;
	ssize_t nread;

	while (nleft > 0) {
		//recv+peek为预读取
		nread = recv_peek(fd, bufp, nleft);
		if (nread <= 0)
			return nread;

		//检查此段内有无\n
		int i;
		for (i = 0; i < nread; ++i) {
			if (bufp[i] == '\n') {
				//找到\n后读取退出
				size_t nsize = i + 1;
				if (readn(fd, bufp, nsize) != nsize)
					return -1;
				bufp += nsize;
				*bufp = '\0';
				total += nsize;
				return total;
			}
		}

		//到此步说明没有找到\n,继续
		if (readn(fd, bufp, nread) != nread)
			return -1;
		bufp += nread;
		total += nread;
		nleft -= nread;
	}
	//读取到最大长度,返回
	*bufp = '\0';
	return maxlen - 1;
}
开发者ID:sdwvskyo,项目名称:C-Cplusplus,代码行数:39,代码来源:sysutil.c


示例11: while

ssize_t SocketIO::readline(char * buf, size_t maxlen)
{
	size_t nleft = maxlen - 1;
	char * pbuf = buf;
	ssize_t nread;
	size_t total = 0;

	while(nleft > 0)
	{
		nread = recv_peek(pbuf, nleft);
		if(nread <= 0)
			return nread;
		int i;
		for(i = 0; i != nread; ++i)
		{
			 //当找到'\n'
			if(pbuf[i] == '\n')
			{
				size_t nsize = i + 1;
				if(static_cast<ssize_t>(nsize) 
						!= readn(pbuf, nsize))
					return -1;
				pbuf += nsize;
				total += nsize;
				*pbuf = 0;
				return total;
			}
		}

		//当没有找到'\n'
		if(readn(pbuf, nread) != nread)
			return -1;
		total += nread;
		pbuf += nread;
		nleft -= nread;
	}
	*pbuf = 0;
	return maxlen - 1;
}
开发者ID:guker,项目名称:SearchEngine,代码行数:39,代码来源:SocketIO.cpp


示例12: readline

char *
readline (int fd)
{
	char * line;
	char * ptr;
	int i = 0;
	int nread = 0;
	int len = 0;
	int buflen = 0;
	
	
	if ((line = (char *) malloc (LINE_BUF_SIZE * sizeof (char))) == NULL)
		return NULL;
	ptr = line;
	
	/* we accept \r\n and \n as endline. */
	
	while (len < (MAX_LINE_BUF_SIZE-1) && (nread = readn (fd, ptr, 1)) == 1
		   && *ptr != '\n') {
		
		if (*ptr != '\r') {
			len += nread;
			ptr += nread;
			buflen += nread;
			
			if (buflen == LINE_BUF_SIZE) {
				i ++;
				if ((line = realloc (line, (i+1) * LINE_BUF_SIZE * sizeof (char))) == NULL) {
					free (line);
					return NULL;
				}
				ptr = line + i * LINE_BUF_SIZE;
				buflen = 0;
			}
		}
	}
	
	/* EOF */
	if (len == 0 && nread == 0) {
		free (line);
		return NULL;
	}
	
	if (nread == -1 || len >= MAX_LINE_BUF_SIZE) {
		free (line);
		return NULL;
	}
		
	line [len] = 0;
	return line;
}
开发者ID:spolu,项目名称:ur,代码行数:51,代码来源:io.c


示例13: main

int main (int argc, char *argv[]) {
    double C = 60 * log(2);
    double PI = 2 * acos(0);
    fread_unlocked(s, sizeof(char), 10 * 1024 * 1024, stdin);
    readn();
    int i, t = n;
    for (I = 0; I < t; I += 1) {
        readn_signed();
        a = n;
        readn_signed();
        b = n;
        theta = atan2 (b, a) / PI;
        r = log( (double)( a * a + b * b ) );
        written = 1;


        for (k = 1; k <= 4; k += 1) {

            if ( k * r <= C && fabs ( k * theta - (int)(k * theta + 0.5) ) < 0.00001 ) {

                writen(k);
                written = 101;
                break;
            }
        }
        if ( written != 101 ) {
            out[++wcount] = 'T';
            out[++wcount] = 'O';
            out[++wcount] = 'O';
            out[++wcount] = ' ';
            out[++wcount] = 'C';
            out[++wcount] = 'O';
            out[++wcount] = 'M';
            out[++wcount] = 'P';
            out[++wcount] = 'L';
            out[++wcount] = 'I';
            out[++wcount] = 'C';
            out[++wcount] = 'A';
            out[++wcount] = 'T';
            out[++wcount] = 'E';
            out[++wcount] = 'D';

        }

        out[++wcount] = '\n';
    }

    fwrite_unlocked(out, 1, wcount + 1, stdout);

    return 0;
}
开发者ID:Corei13,项目名称:contest-programming-codes,代码行数:51,代码来源:11042.c


示例14: elf

/* elf ----------------------------------------------------------------------*/
void
elf(int fd_s, int fd_d, Elf32_Word p_type, Elf32_Word p_flags,
					Elf32_Addr* addr, int* size, int flag)
{
	int		i;	
	Elf32_Ehdr	e_eh;
	static Elf32_Phdr	e_ph[32];

	lseek(fd_s, 0, SEEK_SET);	/* rewind */

	readn(fd_s, &e_eh, sizeof(Elf32_Ehdr));
	lseek(fd_s, e_eh.e_phoff, SEEK_SET);
	readn(fd_s, (char*)e_ph, e_eh.e_phentsize * e_eh.e_phnum);

printf("#-----------------------------------------------------------------#\n");
printf("# [t]ype, [f]lag, [v]addr, [m]emsz, [s]filesz, [o]ffset           #\n");
printf("# e_eh.e_phnum = %d\n", e_eh.e_phnum);
	for (i = 0 ; i < e_eh.e_phnum ; i ++) {
printf("# ph[%d]: t = 0x%x, f = 0x%x, v = 0x%x, m = 0x%x, s = 0x%x o = %d\n", 
	i, e_ph[i].p_type, e_ph[i].p_flags, e_ph[i].p_vaddr, e_ph[i].p_memsz,
		e_ph[i].p_filesz, e_ph[i].p_offset);
		if (e_ph[i].p_type == p_type &&
				e_ph[i].p_flags == p_flags) {
			/* do everything ------------------------------------*/
			if (flag) {
				write_space(fd_d,
					(int)(e_ph[i].p_vaddr - *addr) - *size);
			}
			lseek(fd_s, e_ph[i].p_offset, SEEK_SET);
			readn(fd_s, buf, e_ph[i].p_filesz);
			writen(fd_d, buf, e_ph[i].p_filesz);
			*addr = e_ph[i].p_vaddr;
			*size = e_ph[i].p_memsz;
printf("# virtual address = 0x%x, size = 0x%x\n", *addr, *size);
			break;
		}
	}
}
开发者ID:Q-Taro,项目名称:BootCode,代码行数:39,代码来源:elf.c


示例15: sckServer_rcv

int sckServer_rcv(int connfd, unsigned char *out, int *outlen, int timeout){
    int ret = 0;
	printf("sckServer_rcv() connfd=%d\n", connfd);
    ret = read_timeout(connfd, timeout);
    if(ret < 0){
        if(ret == -1 && errno == ETIMEDOUT){
            ret = SCK_ERRTIMEOUT;
            printf("sckServer_rcv() read timeout err: %d\n", ret);
            return ret;
        }

        return ret;
    }
    int netdatalen = 0;
    ret = readn(connfd, &netdatalen, 4);
    if(ret == -1 ){
        printf("func sckServer_rcv() first err: %d\n", ret);
        return ret;
    }else if(ret < 4){
        ret = SCK_ERRPEERCLOSED;
        printf("func sckServer_rcv() first err: %d\n", ret);
        return ret;
    }
    int n;
    n = ntohl(netdatalen);
    ret = readn(connfd, out, n);
    if(ret == -1 ){
        printf("func sckServer_rcv() second err: %d\n", ret);
        return ret;
    }else if(ret < n){
        ret = SCK_ERRPEERCLOSED;
        printf("func sckServer_rcv() second err: %d\n", ret);
        return ret;
    }
    *outlen = n;

    return 0;
}
开发者ID:xsun89,项目名称:linuxstudy,代码行数:38,代码来源:commsocket.c


示例16: tcpreader

static void
tcpreader(void *a)
{
	Session *s = a;
	uint8_t *buf;
	int buflen = smbglobals.maxreceive + 4;
	buf = nbemalloc(buflen);
	for (;;) {
		int n;
		uint8_t flags;
		uint16_t length;

		n = readn(s->fd, buf, 4);
		if (n != 4) {
		die:
			free(buf);
			if (s->state == Connected)
				(*s->write)(s, nil, -1);
			deletesession(s);
			return;
		}
		flags = buf[1];
		length = nhgets(buf + 2) | ((flags & 1) << 16);
		if (length > buflen - 4) {
			print("nbss: too much data (%ud)\n", length);
			goto die;
		}
		n = readn(s->fd, buf + 4, length);
		if (n != length)
			goto die;
		if (s->state == Connected) {
			if ((*s->write)(s, buf + 4, length) != 0) {
				s->state = Dead;
				goto die;
			}
		}
	}
}
开发者ID:bhanug,项目名称:harvey,代码行数:38,代码来源:smblisten.c


示例17: ungz

void ungz (int ifd, int ofd) {
	uint8_t x[10];
	switch (readn (ifd, x, 10)) {
	case  0: return;
	case 10: break;
	default: errx (-1, "not in gz format");
	}
	if (x[0] != 0x1F || x[1] != 0x8B) errx (-1, "not in gz format");
	if (x[2] != 8) errx (-1, "unknown z-algorithm: 0x%0hhX", x[2]);
	if (x[3] & 1 << 2) /* FEXTRA */ {
		uint16_t n;
		uint8_t n_[2], _[1];
		readn (ifd, n_, 2);
		for (n = n_[0] << 0 | n_[1] << 8; n-- > 0; readn (ifd, _, 1));
	}
	if (x[3] & 1 << 3) /* FNAME    */ skipString (ifd);
	if (x[3] & 1 << 4) /* FCOMMENT */ skipString (ifd);
	if (x[3] & 1 << 1) /* FCRC */ {
		uint16_t _[1];
		readn (ifd, _, 2);
	}
	go (0, ifd, ofd);
}
开发者ID:strake,项目名称:gzip,代码行数:23,代码来源:gzip.c


示例18: load

static uchar*
load(int fd, ulong off, int size)
{
	uchar *a;

	a = malloc(size);
	if(a == nil)
		return nil;
	if(seek(fd, off, 0) < 0 || readn(fd, a, size) != size){
		free(a);
		return nil;
	}
	return a;
}
开发者ID:00001,项目名称:plan9port,代码行数:14,代码来源:crackmacho.c


示例19: do_service

void do_service(int peerfd)
{
    char recvbuf[1024];
    int ret;
    while(1)
    {
        memset(recvbuf, 0, sizeof recvbuf);
        int data;
        int len;
        readn(peerfd, &data, sizeof data);
        len = htonl(data);
        ret = readn(peerfd, recvbuf, len);
        if(ret == -1)
            return;
        else if(ret == 0)
            break;
        else
        {
            writen(peerfd, &data, sizeof data);
            writen(peerfd, recvbuf,len);
        }
    }
}
开发者ID:lvchao0428,项目名称:ultrapp,代码行数:23,代码来源:server2.c


示例20: readblock

static int
readblock(void *fd, DwarfBlock *b, ulong off, ulong len)
{
	b->data = malloc(len);
	if(b->data == nil)
		return -1;
	if(!seek(fd, off, 0) || !readn(fd, (char *)b->data, len)){
		free(b->data);
		b->data = nil;
		return -1;
	}
	b->len = len;
	return 0;
}
开发者ID:GYGit,项目名称:reactos,代码行数:14,代码来源:pe.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ readreg函数代码示例发布时间:2022-05-30
下一篇:
C++ readmem函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap