本文整理汇总了C++中write_full函数的典型用法代码示例。如果您正苦于以下问题:C++ write_full函数的具体用法?C++ write_full怎么用?C++ write_full使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_full函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mserv_get_command_interleave
int mserv_get_command_interleave(
int client_fd,
char *cmd,
uint64_t num_pages_allocated,
int servno,
char *checkpoint_name){
int ret = -1;
if((ret = write_full(client_fd, cmd, CHKPT_CMD_LEN)) < 0){
printf(" mserv_get: Error: Unsuccessful cmd write: %s\n", cmd);
return ret;
}
if((ret = write_full(client_fd, &num_pages_allocated, sizeof(uint64_t))) < 0){
printf(" mserv_get: Error: Unsuccessful numpagealloc write %" PRIx64 "\n", num_pages_allocated);
return ret;
}
if((ret = write_full(client_fd, &servno, sizeof(int))) < 0){
printf(" mserv_get: Error: Unsuccessful numpagealloc write %" PRIx64 "\n", num_pages_allocated);
return ret;
}
//if((ret = write_full(client_fd, checkpoint_name, CHKPT_NAME_LEN)) < 0){
// printf(" mserv_get: Error: Unsuccessful chkptname write: %s\n", checkpoint_name);
// return ret;
//}
return ret;
}
示例2: mserv_init_command_block
int mserv_init_command_block(
int client_fd,
char *cmd,
uint64_t num_pages_allocated,
uint64_t base_page_id,
char *checkpoint_name){
int ret = -1;
if((ret = write_full(client_fd, cmd, CHKPT_CMD_LEN)) < 0){
printf(" mserv_init_set: Error: Unsuccessful cmd write: %s\n", cmd);
return ret;
}
if((ret = write_full(client_fd, &base_page_id, sizeof(uint64_t))) < 0){
printf(" mserv_init_set: Error: Unsuccessful basepageid write %" PRIx64 "\n", base_page_id);
return ret;
}
if((ret = write_full(client_fd, &num_pages_allocated, sizeof(uint64_t))) < 0){
printf(" mserv_init_set: Error: Unsuccessful numpagealloc write %" PRIx64 "\n", num_pages_allocated);
return ret;
}
//if((ret = write_full(client_fd, checkpoint_name, CHKPT_NAME_LEN)) < 0){
// printf(" mserv_init_set: Error: Unsuccessful chkptname write: %s\n", checkpoint_name);
// return ret;
//}
return ret;
}
示例3: save_file
static int save_file(const char *path)
{
struct line *line, *tmp;
int fd;
int ret = 0;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
if (fd < 0) {
printf("could not open file for writing: %s\n", errno_str());
return fd;
}
line = buffer;
while(line) {
tmp = line->next;
ret = write_full(fd, line->data, strlen(line->data));
if (ret < 0)
goto out;
ret = write_full(fd, "\n", 1);
if (ret < 0)
goto out;
line = tmp;
}
ret = 0;
out:
close(fd);
return ret;
}
示例4: mserv_base_set
int mserv_base_set(const void *mkey, size_t mkey_size, const void *buf, size_t buf_size){
int ret = -1;
uint64_t addr = *((uint64_t *)mkey);
uint64_t page_id;
// determine which server to send to based on block distribution
uint64_t mserv_id;
int fd = -1;
// assertion
if(!((tlc_chkpt_status == TLC_CHKPT_READY)&&(mserv_target_page_bits > 0))){
printf("mserv_set: assertion! error mserv_target_page_bits = % " PRId64 "\n",
mserv_target_page_bits);
exit(1);
}
// choose a memory server
page_id = addr >> mserv_target_page_bits;
if(
(tlc_chkpt_type_flag == TLC_MEM_ADDR_BLOCK) ||
(tlc_chkpt_type_flag == TLC_MEM_ADDR_BLOCK_DOUBLE_CHANNELS)
){
mserv_id = page_id/per_mserv_allocate_pages; // for block distribution
}
else if(
(tlc_chkpt_type_flag == TLC_MEM_ADDR_CYCLIC) ||
(tlc_chkpt_type_flag == TLC_MEM_ADDR_CYCLIC_DOUBLE_CHANNELS)
){
mserv_id = page_id % chkpt_mserv_cnt; // for cyclic distribution
}
if (mserv_id < chkpt_mserv_cnt){
fd = base_chkpt_mserv_client_fd[mserv_id];
}
else{
printf(" mserv_set: Abort! fatal error sending ptr = %" PRIx64 " key (addr) = %" PRId64 " page id = %" PRId64 "\n", (uint64_t)mkey, *((uint64_t *)mkey), page_id);
printf(" mserv_set: mserv_id = %" PRId64 " chkpt_cnt = %d per_mserv = %" PRId64 " sent_item %" PRId64 "\n", mserv_id, chkpt_mserv_cnt, per_mserv_allocate_pages, base_mserv_set_item_cnt);
fflush(stdout);
exit(1);
}
// sending addr and page's contents
base_mserv_set_item_cnt++;
if((ret = write_full(fd, mkey, mkey_size)) < 0){
printf(" mserv_set: Error: Unsuccessful key write %" PRIx64 "\n", (uint64_t) mkey);
return ret;
}
if((ret = write_full(fd, buf, buf_size)) < 0){
printf(" mserv_set: Error: Unsuccessful value write (key = %" PRIx64 ") \n", (uint64_t) mkey);
return ret;
}
return ret;
}
示例5: tcpwrap_client_handle
static void tcpwrap_client_handle(struct tcpwrap_client *client, int check_fd,
const char *daemon_name)
{
struct request_info request;
request_init(&request, RQ_DAEMON, daemon_name,
RQ_FILE, check_fd, 0);
fromhost(&request);
if (!hosts_access(&request))
(void)write_full(client->fd, "0\n", 2);
else
(void)write_full(client->fd, "1\n", 2);
exit(0);
}
示例6: mc_set2
int mc_set2(const void *mkey, size_t mkey_size, const void *buf, size_t buf_size){
int ret = -1;
if((ret = write_full(mclient_fd2, mkey, mkey_size)) < 0){
printf(" mc_set2: Error: Unsuccessful key write %" PRIx64 "\n", (uint64_t) mkey);
return ret;
}
//printf(" mc_set2: first write %d ret = %d\n", mclient_fd, ret);
if((ret = write_full(mclient_fd2, buf, buf_size)) < 0){
printf(" mc_set2: Error: Unsuccessful page write (key = %" PRIx64 ") \n", (uint64_t) mkey);
return ret;
}
//printf(" mc_set2: second write ret = %d\n", ret);
return ret;
}
示例7: mc_set
int mc_set(const void *mkey, size_t mkey_size, const void *buf, size_t buf_size){
int ret = -1;
if((ret = write_full(mclient_fd, mkey, mkey_size)) < 0){
printf(" mc_set: Error: Unsuccessful key write %" PRIx64 "\n", (uint64_t) mkey);
return ret;
}
if((ret = write_full(mclient_fd, buf, buf_size)) < 0){
printf(" mc_set: Error: Unsuccessful page write (key = %" PRIx64 ") \n", (uint64_t) mkey);
return ret;
}
return ret;
}
示例8: vic_report
int vic_report(char *message){
int ret;
if((ret = write_full(vic_fd, message, strlen(message))) < 0){
printf(" vic_report: Error: fail sending a message %s\n", message);
}
return ret;
}
示例9: o_stream_temp_fd_sendv
static ssize_t
o_stream_temp_fd_sendv(struct temp_ostream *tstream,
const struct const_iovec *iov, unsigned int iov_count)
{
size_t bytes = 0;
unsigned int i;
for (i = 0; i < iov_count; i++) {
if (write_full(tstream->fd, iov[i].iov_base, iov[i].iov_len) < 0) {
i_error("iostream-temp %s: write(%s*) failed: %m - moving to memory",
o_stream_get_name(&tstream->ostream.ostream),
tstream->temp_path_prefix);
if (o_stream_temp_move_to_memory(&tstream->ostream.ostream) < 0)
return -1;
for (; i < iov_count; i++) {
buffer_append(tstream->buf, iov[i].iov_base, iov[i].iov_len);
bytes += iov[i].iov_len;
tstream->ostream.ostream.offset += iov[i].iov_len;
}
i_assert(tstream->fd_tried);
return bytes;
}
bytes += iov[i].iov_len;
tstream->ostream.ostream.offset += iov[i].iov_len;
}
tstream->fd_size += bytes;
return bytes;
}
示例10: fts_queue_index
static void fts_queue_index(struct mailbox *box)
{
struct mail_user *user = box->storage->user;
string_t *str = t_str_new(256);
const char *path, *value;
unsigned int max_recent_msgs;
int fd;
path = t_strconcat(user->set->base_dir, "/"INDEXER_SOCKET_NAME, NULL);
fd = net_connect_unix(path);
if (fd == -1) {
i_error("net_connect_unix(%s) failed: %m", path);
return;
}
value = mail_user_plugin_getenv(user, "fts_autoindex_max_recent_msgs");
if (value == NULL || str_to_uint(value, &max_recent_msgs) < 0)
max_recent_msgs = 0;
str_append(str, INDEXER_HANDSHAKE);
str_append(str, "APPEND\t0\t");
str_append_tabescaped(str, user->username);
str_append_c(str, '\t');
str_append_tabescaped(str, box->vname);
str_printfa(str, "\t%u", max_recent_msgs);
str_append_c(str, '\t');
str_append_tabescaped(str, box->storage->user->session_id);
str_append_c(str, '\n');
if (write_full(fd, str_data(str), str_len(str)) < 0)
i_error("write(%s) failed: %m", path);
i_close_fd(&fd);
}
示例11: log_error_core
static void log_error_core(int logfile,const char *file, int line,
const char *fmt, va_list args)
{
char errstr[MAX_LOG_LEN];
memset(errstr,0,sizeof(errstr));
size_t len=0;
const char *p;
/* On Unix, __FILE__ may be an absolute path in a
* VPATH build. */
if (file[0] == '/' && (p = strrchr(file, '/')) != NULL) {
file = p + 1;
}
char time_str[CTIME_LEN];
log_ctime(time_str,time_now());
len += snprintf(errstr + len, MAX_LOG_LEN - len,
"[%s]%s(%d): ",time_str,file, line);
len += vsnprintf(errstr+len, MAX_LOG_LEN-len, fmt, args);
if (logfile) {
/* Truncate for the terminator (as apr_snprintf does) */
if (len > MAX_LOG_LEN - sizeof(EOL_STR)) {
len = MAX_LOG_LEN - sizeof(EOL_STR);
}
strcpy(errstr + len, EOL_STR);
size_t len;
len = strlen(errstr);
write_full(logfile, errstr, len);
}
}
示例12: mbox_seek_to_end
static int mbox_seek_to_end(struct mbox_save_context *ctx, uoff_t *offset)
{
struct stat st;
char ch;
int fd;
if (ctx->mbox->mbox_writeonly) {
*offset = 0;
return 0;
}
fd = ctx->mbox->mbox_fd;
if (fstat(fd, &st) < 0)
return mbox_set_syscall_error(ctx->mbox, "fstat()");
ctx->orig_atime = st.st_atime;
*offset = (uoff_t)st.st_size;
if (st.st_size == 0)
return 0;
if (lseek(fd, st.st_size-1, SEEK_SET) < 0)
return mbox_set_syscall_error(ctx->mbox, "lseek()");
if (read(fd, &ch, 1) != 1)
return mbox_set_syscall_error(ctx->mbox, "read()");
if (ch != '\n') {
if (write_full(fd, "\n", 1) < 0)
return write_error(ctx);
*offset += 1;
}
return 0;
}
示例13: sio_write
int sio_write(int level, const char * format, ...) {
char bf[1024];
int ilevel = level & 0xFFF;
if (ilevel==0) ilevel = 50;
switch (level & 0xF000) {
case SIO_DATA: ilevel = sio_dbglevel+1; bf[0] = 0; break;
case SIO_DEBUG: sprintf(bf, "SYS-DEBUG\t%s\t%d\t", appname, ilevel); break;
case SIO_LOG: ilevel += 100; sprintf(bf, "SYS-LOG\t%s\t", appname); break;
case SIO_ERROR: ilevel += 500; sprintf(bf, "SYS-LOG\t%s\tERR: ", appname); break;
case SIO_WARN: ilevel += 400; sprintf(bf, "SYS-LOG\t%s\tWARN: ", appname); break;
default:
sprintf(bf, "SYS-LOG\tag%X: ", level);
};
if (ilevel < sio_dbglevel) return 0;
va_list args;
va_start(args, format);
vsnprintf(strchr(bf,0), sizeof(bf)-strlen(bf)-4, format, args);
va_end(args);
strcat(bf, "\n");
if (sio_commdump & 1) {
printf("WRITE\t%s", bf);
};
GLOB_LOCK();
write_full(ser_fd_write, bf, strlen(bf));
GLOB_UNLOCK();
return 0;
};
示例14: o_stream_temp_move_to_fd
static int o_stream_temp_move_to_fd(struct temp_ostream *tstream)
{
string_t *path;
if (tstream->fd_tried)
return -1;
tstream->fd_tried = TRUE;
path = t_str_new(128);
str_append(path, tstream->temp_path_prefix);
tstream->fd = safe_mkstemp_hostpid(path, 0600, (uid_t)-1, (gid_t)-1);
if (tstream->fd == -1) {
i_error("safe_mkstemp(%s) failed: %m", str_c(path));
return -1;
}
if (i_unlink(str_c(path)) < 0) {
i_close_fd(&tstream->fd);
return -1;
}
if (write_full(tstream->fd, tstream->buf->data, tstream->buf->used) < 0) {
i_error("write(%s) failed: %m", str_c(path));
i_close_fd(&tstream->fd);
return -1;
}
/* make the fd available also to o_stream_get_fd(),
e.g. for unit tests */
tstream->ostream.fd = tstream->fd;
tstream->fd_size = tstream->buf->used;
buffer_free(&tstream->buf);
return 0;
}
示例15: get
int get(const char *hashfile, const char *logfile, const char *key) {
sparkey_hashreader *reader;
sparkey_logreader *logreader;
sparkey_logiter *iter;
assert(sparkey_hash_open(&reader, hashfile, logfile));
logreader = sparkey_hash_getreader(reader);
assert(sparkey_logiter_create(&iter, logreader));
uint64_t keylen = strlen(key);
assert(sparkey_hash_get(reader, (uint8_t*) key, keylen, iter));
int exitcode = 2;
if (sparkey_logiter_state(iter) == SPARKEY_ITER_ACTIVE) {
exitcode = 0;
uint8_t * res;
uint64_t len;
do {
assert(sparkey_logiter_valuechunk(iter, logreader, 1 << 31, &res, &len));
assert(write_full(STDOUT_FILENO, res, len));
} while (len > 0);
}
sparkey_logiter_close(&iter);
sparkey_hash_close(&reader);
return exitcode;
}