/* Process the reply received from a slave machine. * Copy the ascii part to reply_buf and insert the binary part * (if any) in the receive queue. * Return false if ok, true if the slave is out of sync. * slave_lock is held on both entry and exit of this function. */ static bool process_reply(int reply_id, char *reply, char *reply_buf, void *bin_reply, int bin_size, int *last_reply_id, int *reply_slot, struct slave_state *sstate) { /* Resend everything if slave returned an error. */ if (*reply != '=') { *last_reply_id = -1; return true; } /* Make sure we are still in sync. cmd_count may have * changed but the reply is valid as long as cmd_id didn't * change (this only occurs for consecutive genmoves). */ int cmd_id = atoi(gtp_cmd); if (reply_id != cmd_id) { *last_reply_id = reply_id; return true; } strncpy(reply_buf, reply, CMDS_SIZE); if (reply_id != *last_reply_id) *reply_slot = reply_count++; gtp_replies[*reply_slot] = reply_buf; if (bin_size) insert_buf(sstate, bin_reply, bin_size); pthread_cond_signal(&reply_cond); *last_reply_id = reply_id; return false; }
int send_cached_pkts(VhostServer* port, void* input_buf, size_t size){ int ret=0; VringTable* vring_table = &port->vring_table; ret = flush_bufs(vring_table); if (input_buf != 0) { if (vring_table->start_i == vring_table->end_i) { ret = send_pkt(&port->vring_table, VHOST_CLIENT_VRING_IDX_RX,input_buf, size); if (ret < 0) { ret = 0; ret = insert_buf(vring_table, input_buf, size); } return ret; } else { ret = ret + insert_buf(vring_table, input_buf, size); } } return ret; }
static void wrap_writech (SLOT *sp, char ch) { char *space, buf[MAXWIDTH + 1]; if (ch == '\n') { insert_buf (sp, sp->wrap_base, sp->wrap_ptr - sp->wrap_base); insert (sp, '\n', 0); sp->wrap_ptr = sp->wrap_base; } else { *sp->wrap_ptr++ = ch; if (sp->wrap_ptr - sp->wrap_base == sp->acct.width - 3) { for (space = sp->wrap_ptr; space != sp->last_roll; space--) if (isspace (*space)) { insert_buf (sp, sp->wrap_base, space - sp->wrap_base); insert (sp, '\n', 0); *sp->wrap_ptr = '\0'; strcpy (buf, space + 1); strcpy (sp->wrap_base, " "); strcat (sp->wrap_base, buf); sp->last_roll = sp->wrap_ptr = sp->wrap_base + strlen (sp->wrap_base); return; } insert_buf (sp, sp->wrap_base, sp->wrap_ptr - sp->wrap_base); insert (sp, '\n', 0); strcpy (sp->wrap_base, " "); sp->last_roll = sp->wrap_ptr = sp->wrap_base+ strlen(sp->wrap_base); } } }