本文整理汇总了C++中write_n函数的典型用法代码示例。如果您正苦于以下问题:C++ write_n函数的具体用法?C++ write_n怎么用?C++ write_n使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_n函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_block
static int write_block(unsigned char tr, unsigned char se, const unsigned char *blk, int size, int read_status)
{
int i = 0;
unsigned char status[2];
SETSTATEDEBUG((void)0);
status[0] = tr; status[1] = se;
write_n(status, 2);
SETSTATEDEBUG((void)0);
/* send first byte twice if length is odd */
if(size % 2) {
write_n(blk, 2);
i = 1;
}
SETSTATEDEBUG(debugLibImgByteCount=0);
write_n(blk+i, size-i);
SETSTATEDEBUG(debugLibImgByteCount=-1);
#ifndef USE_CBM_IEC_WAIT
if(size == BLOCKSIZE) {
arch_usleep(20000);
}
#endif
SETSTATEDEBUG((void)0);
read_n(status, 2);
SETSTATEDEBUG((void)0);
return status[1];
}
示例2: write_one
// Write one cv::Mat to file
bool write_one(FILE * file, const cv::Mat & data)
{
bool okay = true;
okay &= write_one(file, int32_t(data.rows));
okay &= write_one(file, int32_t(data.cols));
okay &= write_one(file, uint32_t(data.type()));
// If matrix memory is continuous, we can reshape the matrix
int rows = data.rows, cols = data.cols;
if (data.isContinuous()) {
cols = rows*cols;
rows = 1;
}
// Currently only supports float/double matrices!
assert(data.depth() == CV_32F || data.depth() == CV_64F);
if (data.depth() == CV_32F)
for (int r = 0; r < rows; ++r)
okay &= write_n(file, data.ptr<float>(r), cols);
else if (data.depth() == CV_64F)
for (int r = 0; r < rows; ++r)
okay &= write_n(file, data.ptr<double>(r), cols);
else
return false;
return okay;
}
示例3: process_data
/* Process the data from socket and pseudo tty */
static int process_data(int fd)
{
struct pollfd p[2];
char buf[1024];
int err, r;
p[0].fd = 0;
p[0].events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
p[1].fd = fd;
p[1].events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
err = 0;
while (!__io_canceled) {
p[0].revents = 0;
p[1].revents = 0;
err = poll(p, 2, -1);
if (err < 0)
break;
err = 0;
if (p[0].revents) {
if (p[0].revents & (POLLERR | POLLHUP | POLLNVAL))
break;
r = read(0, buf, sizeof(buf));
if (r < 0) {
if (errno != EINTR && errno != EAGAIN) {
err = r;
break;
}
}
err = write_n(fd, buf, r);
if (err < 0)
break;
}
if (p[1].revents) {
if (p[1].revents & (POLLERR | POLLHUP | POLLNVAL))
break;
r = read(fd, buf, sizeof(buf));
if (r < 0) {
if (errno != EINTR && errno != EAGAIN) {
err = r;
break;
}
}
err = write_n(1, buf, r);
if (err < 0)
break;
}
}
return err;
}
示例4: write_string
static int write_string (int fd, const char *str)
{
int len = strlen (str);
int rc;
if (write_n (fd, &len, sizeof (int)) < 0) {
fprintf (stderr, "systemsafe: write: %s\n", strerror (errno));
return (-1);
}
rc = write_n (fd, str, len);
return (rc);
}
示例5: process_msg
static void process_msg(msg_t* msg, int localfd)
{
void* buffer = NULL;
unsigned short len;
int sys;
size_t room_id;
if (parse_msg(msg, &sys, &buffer, &len, &room_id))
{
if (sys) client_process_sys(msg, buffer, len);
else
{
ssize_t written = write_n(localfd, buffer, len);
SYSLOG(LOG_INFO, "write local length: %ld", written);
}
}
else
{
SYSLOG(LOG_WARNING, "Parse message error");
return;
}
if (buffer) pool_room_free(&this.pool, room_id);
this.client.status = (this.client.status & ~CLIENT_STATUS_WAITING_BODY) | CLIENT_STATUS_WAITING_HEADER;
this.client.want = sizeof(msg_t);
this.client.read = this.client.buffer;
}
示例6: main
int main(int argc, char* argv[])
{
process_arg(argc,argv);
tcpudp_fd=open_socket();
assert(tcpudp_fd>0);
if(server)
server_accept(NULL);
tun_fd=tun_alloc(tun_name,IFF_TAP);
assert(tun_fd>0);
get_macaddr();
write_n(tcpudp_fd,tun_mac,6);
getack();
if(pthread_create(&pt_read_from_if,NULL,read_from_if,NULL)!=0){
perror("pthread_create");
exit(-1);
}
if(pthread_create(&pt_read_from_sock,NULL,read_from_sock,NULL)!=0){
perror("pthread_create");
exit(-1);
}
printf("engin started, main() going to sleep\n");
pthread_join(pt_read_from_if,NULL);
pthread_join(pt_read_from_sock,NULL);
return 0;
}
示例7: send_frame
int send_frame(pstream_head_t psh, pcodec_head_t pch, const void *buffer, int size)
{
unsigned char *ptr = send_buffer;
memcpy(ptr, psh, sizeof (*psh));
ptr += sizeof (*psh);
memcpy(ptr, pch, sizeof (*pch));
ptr += sizeof (*pch);
memcpy(ptr, buffer, size);
ptr += size;
memcpy(ptr, &sync_end_code, sizeof (sync_end_code));
ptr += sizeof (sync_end_code);
// if (psh == &video_sh)
// {
// LOGD("video frame %lu before sending: %lu", video_ch.serial_num, clock());
// }
// else
// {
// LOGD("audio frame %lu before sending: %lu", audio_ch.serial_num, clock());
// }
return write_n(sockfd, send_buffer, ptr - send_buffer);
}
示例8: main
int main(int argc, char* argv[])
{
if (argc > 1) {
int i, n = atoi(argv[1]);
if (argc == 2) {
for (i = 0; i < n; ++i) {
write(i);
}
}
else if (argv[2][1] == 'e') {
for (i = 0; i < n; ++i) {
write_e(i);
}
}
else if (argv[2][1] == 'c') {
for (i = 0; i < n; ++i) {
write_c(i);
}
}
else if (argv[2][1] == 'n') {
for (i = 0; i < n; ++i) {
write_n(i);
}
}
}
return 0;
}
示例9: hci_acl_data
static void hci_acl_data(uint8_t *data)
{
hci_acl_hdr *ah = (void *) data;
struct vhci_conn *conn;
uint16_t handle;
int fd;
handle = acl_handle(btohs(ah->handle));
if (handle > VHCI_MAX_CONN || !(conn = vconn[handle - 1])) {
syslog(LOG_ERR, "Bad connection handle %d", handle);
return;
}
fd = g_io_channel_unix_get_fd(conn->chan);
if (write_n(fd, data, btohs(ah->dlen) + HCI_ACL_HDR_SIZE) < 0) {
close_connection(conn);
return;
}
if (++vdev.acl_cnt > VHCI_ACL_MAX_PKT - 1) {
/* Send num of complete packets event */
num_completed_pkts(conn);
vdev.acl_cnt = 0;
}
}
示例10: client_loop
void client_loop(int remotefd, int localfd)
{
fd_set set;
int max;
this.client.status = CLIENT_STATUS_NORMAL | CLIENT_STATUS_WAITING_HEADER;
this.client.want = sizeof(msg_t);
this.client.buffer = this.client.read = pool_room_alloc(&this.pool, RECV_ROOM_IDX, this.client.want);
int keepalive_send = 0;
int rc;
if (this.client.buffer == NULL)
{
fprintf(stderr, "Not enough memory\n");
return;
}
this.keepalive_replyed = 1;
while (1)
{
struct timeval tv = {1, 0};
FD_ZERO(&set);
FD_SET(remotefd, &set);
FD_SET(localfd, &set);
max = remotefd > localfd ? remotefd : localfd;
if (this.keepalive_replyed && (time(NULL) - this.keepalive) > KEEPALIVE_INTERVAL)
{
msg_t* msg = new_keepalive_msg(1);
write_n(remotefd, msg, sizeof(msg_t));
printf("send keepalive message\n");
this.keepalive = time(NULL);
this.keepalive_replyed = 0;
pool_room_free(&this.pool, MSG_ROOM_IDX);
keepalive_send = 1;
}
max = select(max + 1, &set, NULL, NULL, &tv);
if (max > 0)
{
rc = client_process(max, &set, remotefd, localfd);
switch (rc)
{
case RETURN_CONNECTION_CLOSED:
case RETURN_READ_ERROR:
pool_room_free(&this.pool, RECV_ROOM_IDX);
return;
}
}
if (keepalive_send && !this.keepalive_replyed && (time(NULL) - this.keepalive) > KEEPALIVE_TIMEOUT)
{
fprintf(stderr, "keepalive reply timeouted, connection closed\n");
pool_room_free(&this.pool, RECV_ROOM_IDX);
return;
}
}
}
示例11: tcp_write
int tcp_write(int fd, char *buf, int len)
{
register char *ptr;
ptr = buf - sizeof(short);
*((unsigned short *)ptr) = htons(len);
len = (len & VTUN_FSIZE_MASK) + sizeof(short);
return write_n(fd, ptr, len);
}
示例12: send_coord
void send_coord(void *buf, int len)
{
if (current_proc == PROC_COORD) {
pinfo(PINFO_WARN, FALSE, "coordinator sending to itself?");
return;
}
if (write_n(coord_fd, buf, len) == -1) {
pinfo(PINFO_FATAL, TRUE, "write() to COORD failed");
srvr_term(1);
}
}
示例13: client_process
static void client_process(int max, fd_set* set, int remotefd, int localfd)
{
unsigned char buffer[1024] = {0};
ssize_t readen;
if (FD_ISSET(localfd, set))
{
readen = read(localfd, buffer, sizeof(buffer));
if (readen > 0) write_n(remotefd, buffer, readen);
}
if (FD_ISSET(remotefd, set))
{
readen = read(remotefd, buffer, sizeof(buffer));
if (readen > 0) write_n(localfd, buffer, readen);
else
{
fprintf(stderr, "read error\n");
close(remotefd);
exit(1);
}
}
}
示例14: print_p
/*
* Print padded messages.
* Used by 'auth' function to force all messages
* to be the same len.
*/
int print_p(int fd,const char *fmt, ...)
{
char buf[VTUN_MESG_SIZE];
va_list ap;
memset(buf,0,sizeof(buf));
/* print the argument string */
va_start(ap, fmt);
vsnprintf(buf,sizeof(buf)-1, fmt, ap);
va_end(ap);
return write_n(fd, buf, sizeof(buf));
}
示例15: accept_and_check
static void accept_and_check(int bindfd)
{
int fd = accept(bindfd, NULL, NULL);
char buffer[sizeof(CLIENT_AUTH_MSG) - 1];
ssize_t readen;
if (fd == -1) return;
write_n(fd, SERVER_AUTH_MSG, sizeof(SERVER_AUTH_MSG) - 1);
readen = read_t(fd, buffer, sizeof(buffer), 5);
if (readen <= 0)
{
struct sockaddr_in addr;
socklen_t len = sizeof(addr);
char* str;
if (getpeername(fd, (struct sockaddr*)&addr, &len) == -1)
{
perror("getpeername");
close(fd);
return;
}
str = inet_ntoa(addr.sin_addr);
fprintf(stderr, "authcheck failed: %s\n", str);
close(fd);
return;
}
if (strncmp(buffer, CLIENT_AUTH_MSG, sizeof(CLIENT_AUTH_MSG) - 5) == 0)
{
memcpy(&client_id, &buffer[sizeof(CLIENT_AUTH_MSG) - sizeof(client_id) - 2], sizeof(client_id));
client_id = ntohl(client_id);
connfd = fd;
}
else
{
struct sockaddr_in addr;
socklen_t len = sizeof(addr);
char* str;
if (getpeername(fd, (struct sockaddr*)&addr, &len) == -1)
{
perror("getpeername");
close(fd);
return;
}
str = inet_ntoa(addr.sin_addr);
fprintf(stderr, "authcheck failed: %s\n", str);
close(fd);
}
}