本文整理汇总了C++中perror_exit函数的典型用法代码示例。如果您正苦于以下问题:C++ perror_exit函数的具体用法?C++ perror_exit怎么用?C++ perror_exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了perror_exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serial_open
/* open the serial port */
void serial_open(const char *dev)
{
portfd = open(dev, O_RDWR | O_NOCTTY);
if (portfd < 0)
perror_exit(dev);
/* save current port settings */
if (tcgetattr(portfd, &oldtio) < 0)
perror_exit("tcgetattr");
/* set signal handlers before switching settings */
signal(SIGHUP, handler1);
signal(SIGINT, handler1);
signal(SIGPIPE, handler1);
signal(SIGTERM, handler1);
/* configure new port settings: 9600 8N1 */
memset(&newtio, 0, sizeof(newtio));
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
/* install new port settings */
tcflush(portfd, TCIFLUSH);
if (tcsetattr(portfd, TCSANOW, &newtio) < 0)
perror_exit("tcsetattr");
}
示例2: i2c_init
void i2c_init(struct plugin *p, struct plugin_set *__un1, struct plug_args *pa)
{
char filename[FILENAME_MAX];
struct i2c_data *i2c = p->data = g_new(struct i2c_data,1);
i2c->is = g_tree_new(comp_int64);
i2c->outstanding = 0;
i2c->maxouts = 0;
i2c->oio_f = NULL;
if(pa->i2c_oio_f) {
get_filename(filename, "i2c_oio", pa->i2c_oio_f, pa->end_range);
i2c->oio_f = fopen(filename,"w");
if(!i2c->oio_f) perror_exit("Opening I2C detail file");
}
i2c->oio_hist_f = NULL;
if(pa->i2c_oio_hist_f) {
get_filename(filename, "i2c_oio_hist", pa->i2c_oio_hist_f, pa->end_range);
i2c->oio_hist_f = fopen(filename,"w");
if(!i2c->oio_hist_f) perror_exit("Opening I2C detail file");
}
i2c->oio = NULL;
i2c->oio_size = 0;
i2c->oio_prev_time = UINT64_MAX;
}
示例3: dbg_dap_cmd
//-----------------------------------------------------------------------------
int dbg_dap_cmd(uint8_t *data, int size, int rsize)
{
char cmd = data[0];
int res;
memset(hid_buffer, 0xff, report_size + 1);
hid_buffer[0] = 0x00; // Report ID
memcpy(&hid_buffer[1], data, rsize);
res = hid_write(handle, hid_buffer, report_size + 1);
if (res < 0)
{
printf("Error: %ls\n", hid_error(handle));
perror_exit("debugger write()");
}
res = hid_read(handle, hid_buffer, report_size + 1);
if (res < 0)
perror_exit("debugger read()");
check(res, "empty response received");
check(hid_buffer[0] == cmd, "invalid response received");
res--;
memcpy(data, &hid_buffer[1], (size < res) ? size : res);
return res;
}
示例4: load_file
//-----------------------------------------------------------------------------
int load_file(char *name, uint8_t *data, int size)
{
struct stat stat;
int fd, rsize;
check(NULL != name, "input file name is not specified");
fd = open(name, O_RDONLY | O_BINARY);
if (fd < 0)
perror_exit("open()");
fstat(fd, &stat);
check(stat.st_size <= size, "image is too big for the selected chip");
rsize = read(fd, data, stat.st_size);
if (rsize < 0)
perror_exit("read()");
check(rsize == stat.st_size, "cannot fully read file");
close(fd);
return rsize;
}
示例5: malloc
void *connection_handler(void *arg){
int err,length;
char* directory;
QNode* node;
int newsock = ((information*)arg)->newsock;
int queue_size = ((information*)arg)->queue_size;
pthread_mutex_t *clientMutex = malloc(sizeof(pthread_mutex_t));
//---------------------------------------------
if ( err = pthread_detach(pthread_self())){
perror2("pthread_detach",err);
exit(1);
}
pthread_mutex_init(clientMutex,NULL ) ; /* Initialize client mutex */
if (read_all(newsock,&length,sizeof(int)) != sizeof(int) )
perror_exit("read");
directory = malloc(length);
if (read_all(newsock,directory,length) != length)
perror_exit("read");
//print directory
//printf("directory is: %s\n",directory);
printf("[Thread: %ld]: About to scan directory Server\n",pthread_self());
fflush(stdout);
findFiles(directory,newsock,queue_size,clientMutex);
//create ack
node = createQNode();
node->client_sock = newsock;
node->buf = NULL;
node->clientMutex = clientMutex;
place(workQueue,node,queue_size);
pthread_cond_broadcast(&cond_empty);
pthread_exit(NULL);
}
示例6: bind_sock
/* sock_bind: create and bind a new socket with @port
* @port: the port used to bind the socket
*
* */
int bind_sock(int port)
{
int listenfd;
struct sockaddr_in socket_addr;
/* create a new socket */
if ((listenfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
{
perror_exit("socket error");
}
/* fill the socket address struct */
memset(&socket_addr,0,sizeof(struct sockaddr_in));
socket_addr.sin_family = AF_INET;
socket_addr.sin_port = htons(port);
socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
/* bind the socket */
if (bind(listenfd,(struct sockaddr *)&socket_addr,sizeof(struct sockaddr_in)) < 0)
{
perror_exit("bind error");
}
return listenfd;
}
示例7: handle_connection
/* handle_connection: handle the connected clients
* @listenfd: the socket used to accept connections
*
* */
void handle_connection(int listenfd)
{
/* the number of readable fds in the pollfd array */
int nready, i;
/* receive buffer */
buffer_t recvbuf;
memset(&recvbuf,0,sizeof(buffer_t));
/* set the listenfd to non-block */
//setnonblock(listenfd);
/* epollfd set to monitor the related events */
int epollfd;
if ( (epollfd = epoll_create(EPOLL_SIZE)) < 0 )
{
perror_exit("epoll create error");
}
/* epoll event array */
struct epoll_event events[EPOLL_EVENTS];
/* add the listen socket to epoll set */
int state = EPOLLIN;
add_epoll_event(epollfd,listenfd,state);
while( 1 )
{
/* obtain the ready sockets from the epoll set */
if ( (nready = epoll_wait(epollfd,events,EPOLL_EVENTS,INFTIM)) < 0)
{
perror_exit("epoll wait error");
}
/* traverse the ready sockets */
for (i = 0; i < nready; ++i)
{
int fd = events[i].data.fd;
/* listenfd is ready */
if ( fd == listenfd && (events[i].events & EPOLLIN) )
{
do_accept(listenfd, epollfd);
}
/* connected sockets are ready */
else if ( events[i].events & EPOLLIN )
{
do_read(fd,epollfd,&recvbuf);
}
/* read the data from the connected socket and echo it also */
else if ( events[i].events & EPOLLOUT )
{
do_write(fd,epollfd,&recvbuf);
}
}
}
}
示例8: perror_exit
void *server(void *data)
{
data_struct *info = data;
int port = info->port;
pthread_t thr_server;
int sock, newsock,retValue =-1;
int optval;
struct sockaddr_in server, client;
socklen_t clientlen;
struct sockaddr *serverptr=(struct sockaddr *)&server;
struct sockaddr *clientptr=(struct sockaddr *)&client;
struct hostent *rem;
/* Create socket */
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0)
perror_exit("socket");
server.sin_family = AF_INET; /* Internet domain */
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(port); /* The given port */
optval = 1;//make the socket reuseable fast
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
/* Bind socket to address */
if (bind(sock, serverptr, sizeof(server)) < 0)
perror_exit("bind");
/* Listen for connections */
if (listen(sock, 5) < 0)
perror_exit("listen");
printf("Listening for connections to port %d\n", port);
while (1)
{ clientlen = sizeof(client);
/* accept connection */
if ((newsock = accept(sock, clientptr, &clientlen)) < 0)
perror_exit("accept");
printf("Accepted connection\n");
info->socket = newsock;
//thread pou tha eksyphrethsei thn aithsh
retValue = pthread_create(&thr_server, NULL, thread_server, (void *)info);
if(retValue == 1)
perror2("pthread_create", retValue);
//close(newsock); /* parent closes socket to client */
}
}
示例9: join_thread
void join_thread(pthread_t thread)
{
int ret = pthread_join(thread, NULL);
if (ret == -1) {
perror_exit("pthread_join failed");
}
}
示例10: getpwnam
struct passwd *xgetpwnam(char *name)
{
struct passwd *up = getpwnam(name);
if (!up) perror_exit("user '%s'", name);
return up;
}
示例11: getgrgid
struct group *xgetgrgid(gid_t gid)
{
struct group *group = getgrgid(gid);
if (!group) perror_exit("gid %ld", (long)gid);
return group;
}
示例12: do_accept
/* do_accept: establish the new connection
* @listenfd: the listening fd
* @epollfd: the epollfd used to monitor the listening fd and new connected fd
*
* */
void do_accept(int listenfd, int epollfd)
{
int connfd;
struct sockaddr_in clitaddr;
socklen_t socklen;
//while ( (connfd = accept(listenfd,(struct sockaddr *)&clitaddr,&socklen)) > 0 )
//{
connfd = accept(listenfd,(struct sockaddr *)&clitaddr,&socklen);
/* show client info */
show_peer_info(connfd);
/* set the connfd to non-block socket */
//setnonblock(connfd);
/* set the connfd events to EPOLLIN | EPLLET(edge trigger) */
//int state = EPOLLIN | EPOLLET;
int state = EPOLLIN;
/* add connected fd to epoll set */
add_epoll_event(epollfd,connfd,state);
//}
/* if accept error*/
if (connfd < 0)
{
if (errno != EINTR)
{
perror_exit("accept error");
}
}
}
示例13: xconnect
int xconnect(char *host, char *port, int family, int socktype, int protocol, int flags)
{
struct addrinfo info, *ai, *ai2;
int fd;
memset(&info, 0, sizeof(struct addrinfo));
info.ai_family = family;
info.ai_socktype = socktype;
info.ai_protocol = protocol;
info.ai_flags = flags;
fd = getaddrinfo(host, port, &info, &ai);
if (fd || !ai)
error_exit("Connect '%s%s%s': %s", host, port ? ":" : "", port ? port : "",
fd ? gai_strerror(fd) : "not found");
// Try all the returned addresses. Report errors if last entry can't connect.
for (ai2 = ai; ai; ai = ai->ai_next) {
fd = (ai->ai_next ? socket : xsocket)(ai->ai_family, ai->ai_socktype,
ai->ai_protocol);
if (!connect(fd, ai->ai_addr, ai->ai_addrlen)) break;
else if (!ai2->ai_next) perror_exit("connect");
close(fd);
}
freeaddrinfo(ai2);
return fd;
}
示例14: setnonblock
/* setnonblock: set the non-blocking @fd
* @fd: the fd to be set
*
* */
void setnonblock(int fd)
{
int opt;
/* get the orignal option */
if ( (opt = fcntl(fd,F_GETFD)) < 0 )
{
perror_exit("fctl error");
}
/* set non-block option */
opt |= O_NONBLOCK;
if ( (opt = fcntl(fd,F_SETFD)) < 0 )
{
perror_exit("fcntl error");
}
}
示例15: listen_sock
/* sock_listen: listen the @listenfd socket
* @listenfd: the socket used for listening
*
* */
void listen_sock(int listenfd)
{
if (listen(listenfd,LISTENQ) < 0)
{
perror_exit("listen error");
}
}