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


C++ err_dump函数代码示例

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


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

示例1: db_delete

/* Find specified record.
Called by db_delete(), db_fetch() and db_store() */
int _db_find(DB *db, const char *key, int writelock)
{
    off_t offset, nextoffset;
    /* calculate hash value for this key, then calculate byte offset of corresponding chain ptr in hash table.
    */
    /* calculate offset in hash table for this key */
    db->chainoff = (_db_hash(db, key) * PTR_SZ) + db->hashoff;
    db->ptroff = db->chainoff;
    /* here's where we lock this hash chain. It's the caller responsibility to unlock it when done.
    Note that we lock and unlock only the first byte. */
    if(writelock)
    {
        if(writew_lock(db->idxfd, db->chainoff, SEEK_SET, 1) < 0)
            err_dump("error");
    }
    else
    {
        if(readw_lock(db->idxfd, db->chainoff, SEEK_SET, 1) < 0)
            err_dump("error");
    }
    /* Get the offset in the index file of first record on the bash chain (it can be 0 too) */
    offset = _db_readptr(db, db->ptroff);
    while(offset!=0)
    {
        nextoffset = _db_readidx(db, offset);
        if(strcmp(db->idxbuf, key) == 0)
            break; /* found a match */
        db->ptroff = offset; /* offset of this (unequal) record */
        offset = nextoffset; /* next one to compare */
    }
    if(offset == 0)
        return(-1); /* error -- record not found */
    return(0); /* if not error */
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:36,代码来源:db_find.c

示例2: db_nextrec

char *
db_nextrec(DB *db, char *key)
{
    char    c, *ptr;

        /* We read lock the free list so that we don't read
           a record in the middle of its being deleted. */
    if (readw_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
        err_dump("readw_lock error");

    do {
            /* read next sequential index record */
        if (_db_readidx(db, 0) < 0) {
            ptr = NULL;        /* end of index file, EOF */
            goto doreturn;
        }
            /* check if key is all blank (empty record) */
        ptr = db->idxbuf;
        while ( (c = *ptr++) != 0  &&  c == ' ')
            ;    /* skip until null byte or nonblank */
    } while (c == 0);    /* loop until a nonblank key is found */

    if (key != NULL)
        strcpy(key, db->idxbuf);    /* return key */
    ptr = _db_readdat(db);    /* return pointer to data buffer */

    db->cnt_nextrec++;
doreturn:
    if (un_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
        err_dump("un_lock error");

    return(ptr);
}
开发者ID:no7dw,项目名称:cpp-learning,代码行数:33,代码来源:nextrec.c

示例3: db_rewind

/* Returning the sequential record...
Just gotta step ahead through the index file where we gotta ignore deleted records.
db_rewind() essential to be called before this function at initial stage itself */
char *db_nextrec(DB *db, char *key)
{
	char c, *ptr;
	/* Locking the free list where we don't actually read a record in the mid of deletion*/
	if(readw_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
		err_dump("error");
	do
	{
		/* read next sequential index record */
		if(_db_readidx(db, 0) < 0)
		{
			ptr = NULL; /* end of index file --- EOF */
			goto doreturn;
		}
		/* Checking if the key is still blank or empty record */
		ptr = db->idxbuf;
		while((c = *ptr++) != 0 && c = ' ');
		/* skip if it's not blank */
	}
	while(c == 0) /* loop untill a non-empty key is found*/
		if(key != NULL)
			strcpy(key, db->idxbuf); /* return key */
	ptr = _db_readdat(db); /* return pointer to data buffer */
	db->cnt_nextrec++;
doreturn:
	if(un_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
		err_dump("error");
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:31,代码来源:MeowDBLibrary.c

示例4: str_cli

void str_cli(register FILE *fp, register int sockfd) {
  int n;
  char sendline[MAXLINE];
  char recvline[MAXLINE + 1];

  while (fgets(sendline, MAXLINE, fp) != NULL) {
    n = strlen(sendline);

    if (writen(sockfd, sendline, n) != n) {
      printf("MAXLINE: %d, n: %d\n", MAXLINE, n);
      err_dump("str_cli : written error on socket");
    }

    n = readline(sockfd, recvline, MAXLINE);

    if (n < 0) {
      err_dump("str_cli : reading error");
    }
    recvline[n] = '\0';
    printf("Received string from Server: ");
    fputs(recvline, stdout);
  }

  if (ferror(fp)) {
    err_dump("str_cli : error reading file");
  }
}
开发者ID:dolpang2,项目名称:Basic-TCP-Server-Client,代码行数:27,代码来源:cli.c

示例5: _db_writedat

/* writing an index record
_db_writedat() is called before this function inorder to set fields datoff and datlen in the database structure where we gotta write index record */
void _db_writeidx(DB *db, const char *key, off_t offset, int whence, off_t ptrval)
{
	struct iovec iov[2];
	char asciiptrlen[PTR_SZ + IDXLEN_SZ + 1];
	int len;
	if((db->ptrval = ptrval) < 0 || ptrval > PTR_MAX)
		err_quit("invalid ptr: %d", ptrval);
	sprintf(db->idxbuf, "%s%c%d%c%d\n", key, SEP, db->datoff, SEP, db->datlen);
	if((len = strlen(sb->idxbuf)) < IDXLEN_MIN || len > IDXLEN_MAX)
		err_dump("invalid length");
	sprintf(asciiptrlen, "%*d%*d", PTR_SZ, ptrval, IDXLEN_SZ, len);
	/* If we are appending, then we gotta lock before doing lseek() and write() in making the two as atomic operation.
	If we are overwriting an existing record, then we don't have to lock */
	if(whence == SEEK_END) /* we are appending, then lock the entire file. */
		if(writew_lock(db->idxfd, 0, SEEK_SET, 0) < 0)
			err_dump("error");
	if((db->idxoff = lseek(db->idxfd, offset, whence)) == -1)
		err_dump("error");
	iov[0].iov_base = asciiptrlen;
	iov[0].iov_len = PTR_SZ + IDXLEN_SZ;
	iov[1].iov_base = db->idxbuf;
	iov[1].iov_len = len;
	if(writev(db->idxfd, &iov[0], 2) != PTR_SZ + IDXLEN_SZ + len)
		err_dump("error");
	if(whence == SEEK_END)
		if(un_lock(db->idxfd, ((db->nhash + 1)*PTR_SZ)+1, SEEK_SET, 0) < 0)
			err_dump("error");
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:30,代码来源:MeowDBLibrary.c

示例6: main

int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in serv_addr;
  pname = argv[0];

  //
  // Fill in the structure "serv_addr" with the address of
  // the server that we want to connect with
  //

  memset((char *) &serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
  serv_addr.sin_port = htons(SERV_TCP_PORT);

  //
  // Open a TCP socket (an Internet stream socket)
  //
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    err_dump("client : can't open stream socket");
  }

  //
  // Connect the server
  //
  if (connect(sockfd, (
      struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    err_dump("client : can't connect to server");
  }

  str_cli(stdin, sockfd);
  close(sockfd);

  return EXIT_SUCCESS;
}
开发者ID:dolpang2,项目名称:Basic-TCP-Server-Client,代码行数:35,代码来源:cli.c

示例7: myfunc

static int
myfunc(const char *pathname, const struct stat *statptr, int type)
{
    switch (type) {
    case FTW_F:
        switch (statptr->st_mode & S_IFMT) {
        case S_IFREG:    nreg++;        break;
        case S_IFBLK:    nblk++;        break;
        case S_IFCHR:    nchr++;        break;
        case S_IFIFO:    nfifo++;    break;
        case S_IFLNK:    nslink++;    break;
        case S_IFSOCK:    nsock++;    break;
        case S_IFDIR:    /* directories should have type = FTW_D */
            err_dump("for S_IFDIR for %s", pathname);
        }
        break;
    case FTW_D:
        ndir++;
        break;
    case FTW_DNR:
        err_ret("can't read directory %s", pathname);
        break;
    case FTW_NS:
        err_ret("stat error for %s", pathname);
        break;
    default:
        err_dump("unknown type %d for pathname %s", type, pathname);
    }
    return(0);
}
开发者ID:daidaotian,项目名称:apue.3e-1,代码行数:30,代码来源:ftw8.c

示例8: _db_alloc

DB *
_db_alloc(int namelen)
{
    DB        *db;

            /* Use calloc, to init structure to zero */
    if ( (db = calloc(1, sizeof(DB))) == NULL)
        err_dump("calloc error for DB");

    db->idxfd = db->datfd = -1;                /* descriptors */

        /* Allocate room for the name.
           +5 for ".idx" or ".dat" plus null at end. */

    if ( (db->name = malloc(namelen + 5)) == NULL)
        err_dump("malloc error for name");

        /* Allocate an index buffer and a data buffer.
           +2 for newline and null at end. */

    if ( (db->idxbuf = malloc(IDXLEN_MAX + 2)) == NULL)
        err_dump("malloc error for index buffer");
    if ( (db->datbuf = malloc(DATLEN_MAX + 2)) == NULL)
        err_dump("malloc error for data buffer");

    return(db);
}
开发者ID:no7dw,项目名称:cpp-learning,代码行数:27,代码来源:alloc.c

示例9: strlen

/* Opening or Creating a database */
DB *db_open(const char *pathname, int oflag, int mode)
{
	DB *db;
	int i, len;
	char asciiptr[PTR_SZ + 1], hash[(NHASH_DEF + 1) * PTR_SZ +2]; /* +2 for newline and NULL */
	struct stat statbuff;
	/* Allocating a Database structure and the buffer it requires. */
	len = strlen(pathname);
	if((db = _db_alloc(len)) == NULL)
		err_dump("error");
	db->oflag = oflag; /* saving a copy of the open flags */
	/* Opening index file */
	strcpy(db->name, pathname);
	strcat(db->name, ".idx");
	if((db->idxfd = open(db->name, oflag, mode)) < 0)
	{
		_db_free(db);
		return(NULL);
	}
	/* Opening data file */
	strcpy(db->name + len, ".dat");
	if((db->datfd = open(db->name, oflag, mode)) < 0)
	{
		_db_free(db);
		return(NULL);
	}
	/* If the database was created, then initialize it */
	if((oflag & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
	{
		/* write lock the entire file and so that, we can stat the file, check it's size & initialize it */
		if(writew_lock(db->idxfd, 0, SEEK_SET, 0) < 0)
			err_dump("error");
		if(fstat(db->idxfd, &statbuff) < 0)
			err_sys("error");
		if(statbuff.st_size==0)
		{
			/* 
			We gotta build a list of (NHASH_DEF + 1) chain ptr with a value of 0.
			The +1 is for free list pointer that precedes the hash table.
			*/
			sprintf(asciiptr, "%*d", PTR_SZ, 0);
			hash[0] = 0;
			for(i=0;i<(NHASH_DEF + 1);i++)
				strcat(hash, asciiptr);
			strcat(hash, "\n");
			i = strlen(hash);
			if(write(db->idxfd, hash, i) != i)
				err_dump("error");
		}
		if(un_lock(db->idxfd, 0, SEEK_SET, 0) < 0)
			err_dump("error");
	}
	db->nhash = NHASH_DEF; /* hash table size */
	db->hashoff = HASH_OFF; /* offset in index file of hash table */
							/* free list ptr always at FREE_OFF */
	db_rewind(db);
	return(db);
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:59,代码来源:MeowDBLibrary.c

示例10: recv_fd

/*
 * receive a file descriptor from a server process. Also, any data
 * received is passed to (*userfunc)(STDERR_FILENO, buf, nbytes).
 * we have a 2-byte protocol for receiving the fd from send_fd().
 */
int recv_fd(int fd, ssize_t (*userfunc)(int, const void *, size_t))
{
	int		newfd, nr, status;
	char		*ptr;
	char		buf[MAXLINE];
	struct iovec	iov[1];
	struct msghdr	msg;

	status = -1;
	for (;;) {
		iov[0].iov_base	= buf;
		iov[0].iov_len	= sizeof(buf);
		msg.msg_iov	= iov;
		msg.msg_iovlen	= 1;
		msg.msg_name	= NULL;
		msg.msg_namelen	= 0;
		if (cmptr == NULL && (cmptr = malloc(CONTROLLEN)) == NULL)
			return -1;
		msg.msg_control	= cmptr;
		msg.msg_controllen = CONTROLLEN;
		if ((nr = recvmsg(fd, &msg, 0)) < 0) {
			err_ret("recvmsg error");
			return -1;
		} else if (nr == 0) {
			err_ret("connection closed by server");
			return -1;
		}

		/*
		 * see if this is the final data with null & status. null
		 * is next to last byte of buffer; status byte is last byte.
		 * zero status means there is a file descriptor to receive.
		 */
		for (ptr = buf; ptr < &buf[nr]; ) {
			if (*ptr++ == 0) {
				if (ptr != &buf[nr - 1])
					err_dump("message format error");
				/*
				 * prevent sign extension
				 */
				status = *ptr & 0xff;
				if (status == 0) {
					if (msg.msg_controllen < CONTROLLEN)
						err_dump("status = 0 but no fd");
					newfd = *(int *)CMSG_DATA(cmptr);
				} else {
					newfd = -status;
				}
				nr -= 2;
			}
		}
		if (nr > 0 && (*userfunc)(STDERR_FILENO, buf, nr) != nr)
			return -1;
		if (status >= 0)	/* final data has arrived */
			return newfd;	/* descriptor, or -status */
	}
}
开发者ID:wuzhouhui,项目名称:misc,代码行数:62,代码来源:17-14.c

示例11: _db_readptr

/* Read a chain ptr field from anywhere in the index file:
--- the free list pointer, hash table chain ptr, or index record chain ptr */
off_t _db_readptr(DB *db, off_t offset)
{
	char asciiptr[PTR_SZ + 1];
	if(lseek(db->idxfd, offset, SEEK_SET) == -1)
		err_dump("error");
	if(read(db->idxfd, asciiptr, PTR_SZ) != PTR_SZ)
		err_dump("error");
	asciiptr[PTR_SZ] = 0; /* null terminate */
	return(atol(asciiptr));
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:12,代码来源:db_readptr.c

示例12: _db_writeptr

/* Writing a chain ptr field somewhere in the index file:
	=== The free list
	=== The hash table
	=== index record
*/
void _db_writeptr(DB *db, off_t offset, off_t ptrval)
{
	char asciiptr[PTR_SZ + 1];
	if(ptrval < 0 || ptrval > PTR_MAX)
		err_quit("invalid ptr: %d", ptrval);
	sprintf(asciiptr, "%*d", PTR_SZ, ptrval);
	if(lseek(db->idxfd, offset, SEEK_SET) == -1)
		err_dump("error");
	if(write(db->idxfd, asciiptr, PTR_SZ) != PTR_SZ)
		err_dump("error");
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:16,代码来源:MeowDBLibrary.c

示例13: err_dump

/* Returning the pointer to the null terminated data buffer */
char *_db_readdat(DB *db)
{
	if(lseek(db->datfd, db->datoff, SEEK_SET) == -1)
		err_dump("error");
	if(read(db->datfd, db->datbuf, db->datlen) != db->datlen)
		err_dump("error");
	if(db->datbuf[db->datlen - 1] != '\n') /* clean checking */
		err_dump("missing newline");
	db->datbuf[db->datlen - 1] = 0; /* replace newline with NULL */
	return(db->datbuf); /* returns pointer to data record */
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:12,代码来源:MeowDBLibrary.c

示例14: _db_readidx

/* Reading next index record.
Starting at the specified offset in the index file.
Reading the index record into db->idxbuf and replacing the separators with null bytes.
If all were cool, then setting db->datoff and db->datlen to the offset & length of the corresponding data record in data file.
*/
off_t _db_readidx(DB *db, off_t offset)
{
	int i;
	char *ptr1, *ptr2;
	char asciiptr[PTR_SZ + 1], asciilen[IDXLEN_SZ + 1];
	struct iovec iov[2];
	/* Positioning index file and recording the offset.
	db_nextrec() calls with offset==0 which means reading from current offset.
	we still need to call lseek() to record the current offset. */
	if((db->idxoff = lseek(db->idxfd, offset, offset == 0 ? SEEK_CUR : SEEK_SET)) == -1)
		err_dump("error");
	/* Reading the ASCII chain ptr and ASCII length at the front of index record.
	This tells us the remaining size of the index record. */
	iov[0].iov_base = asciiptr;
	iov[0].iov_len = PTR_SZ;
	iov[1].iov_base = asciilen;
	iov[1].iov_len = IDXLEN_SZ;
	if((i = readv(db->idxfd, &iov[0], 2)) != PTR_SZ + IDXLEN_SZ)
	{
		if(i == 0 && offset == 0)
			return(-1); /* EOF for db_nextrec() */
	err_dump("error");
	}
asciiptr[PTR_SZ] = 0; /* null terminate */
db->ptrval = atol(asciiptr); /* offset of next key in chain */
							/* this is our return value, always >= 0 */
asciilen[IDXLEN_SZ] = 0; /* null terminate */
if((db->idxlen = atoi(asciilen)) < IDXLEN_MIN || db->idxlen > IDXLEN_MAX)
	err_dump("invalid length");
/* Now reading the actual index record. We'll be reading it into the buffer we have memory allocated after we opened a DB */
if((i = read(db->idxfd, db->idxbuf, db->idxlen)) != db->idxlen)
	err_dump("error");
if(db->idxbuf[db->idxlen-1] != '\n')
	err_dump("missing newline"); /* clean checking */
db->idxbuf[db->idxlen-1] = 0; /* replace newline with NULL */
/* Finding the separators in the index record */
if((ptr1 = strchr(db->idxbuf, SEP)) == NULL)
	err_dump("missing first separator");
*ptr1++ = 0;
if((ptr2 = strchr(ptr1, SEP)) == NULL)
	err_dump("missing seconf separator");
*ptr2++ = 0;
if(strchr(ptr2, SEP) != NULL)
	err_dump("too many separators");
/* Getting the initial offset and length of the data record */
if((db->datoff = atol(ptr1)) < 0)
	err_dump("initial offset < 0");
if((db->datlen = atol(ptr2)) <= 0 || db->datlen > DATLEN_MAX)
	err_dump("invalid length");
return(db->ptrval); /* return the offset of the next key in chain */
}
开发者ID:Geek-Research-Lab,项目名称:UNIX-DatabaseLibrary,代码行数:56,代码来源:MeowDBLibrary.c

示例15: main

int main(int argc, char *argv[]) {
    int sockfd, newsockfd,  childpid;
    struct sockaddr_in cli_addr, serv_addr;
    socklen_t clilen;
    
    pname = argv[0];

    /* Open a TCP socker (an Internet stream socket). */
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        err_dump("Server: can't open stream socket\n");

    /* Bind our local address so that the client can send to us. */
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(SERV_TCP_PORT);

    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
        err_dump("Server : can't bind local address\n");
    printf("\t[Info] binding...\n");

    listen(sockfd, 5);
    printf("\t[Info] listening...\n");

    for( ; ; ) {
        /* 
         * Wait for a connection from a client process.
         * This is an example of a concurrent server.
         */
        printf("\t[Info] wait for connection...\n");
        clilen = sizeof(cli_addr);
        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
        char *paddr_str = inet_ntoa(cli_addr.sin_addr);
        printf("\t[Info] Receive connection from %s\n",paddr_str);
        if (newsockfd < 0)
            err_dump("server: accept error\n");

        if ( (childpid = fork()) < 0)
            err_dump("server: fork error\n");
        else if (childpid == 0) {
            close(sockfd);
            str_echo(newsockfd);
            exit(0);
        }

        close(newsockfd);
    }

    return 0;
}
开发者ID:David-Guo,项目名称:NetworkPrograming,代码行数:50,代码来源:server.c


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