gochatai/pachi_py/pachi/distributed/protocol.c
/* Main loop of a slave thread.
 * Send the current command to the slave machine and wait for a reply.
 * Resend command history if the slave machine is out of sync.
 * Returns when the connection with the slave machine is cut.
 * slave_lock is held on both entry and exit of this function. */
Main loop of a slave thread.
Send the current command to the slave machine and wait for a reply.
Resend command history if the slave machine is out of sync.
Returns when the connection with the slave machine is cut.
slave_lock is held on both entry and exit of this function.
Main loop of a slave thread . Send the current command to the slave machine and wait for a reply . Resend command history if the slave machine is out of sync . Returns when the connection with the slave machine is cut . slave_lock is held on both entry and exit of this function .
static void
slave_loop(FILE *f, char *reply_buf, struct slave_state *sstate, bool resend)
{
	char *to_send;
	int last_cmd_count = 0;
	int last_reply_id = -1;
	int reply_slot = -1;
	for (;;) {
		if (resend) {
			to_send = next_command(last_reply_id);
		} else {
			while (last_cmd_count == cmd_count)
				pthread_cond_wait(&cmd_cond, &slave_lock);
			to_send = gtp_cmd;
		}
		int bin_size = 0;
		void *bin_buf = get_binary_arg(sstate, gtp_cmd,
					       gtp_cmds + CMDS_SIZE - gtp_cmd,
					       &bin_size);
		resend = true;
		if (!bin_buf) continue;
		last_cmd_count = cmd_count;
		char buf[CMDS_SIZE];
		int reply_id = send_command(to_send, bin_buf, &bin_size, f,
					    sstate, buf);
		if (reply_id == -1) return;
		resend = process_reply(reply_id, buf, reply_buf, bin_buf, bin_size,
				       &last_reply_id, &reply_slot, sstate);
	}
}
static void slave_loop ( FILE * f , char * reply_buf , struct slave_state * sstate , bool resend ) { char * to_send ; int last_cmd_count = 0 ; int last_reply_id = -1 ; int reply_slot = -1 ; for ( ; ; ) { if ( resend ) { to_send = next_command ( last_reply_id ) ; } else { while ( last_cmd_count == cmd_count ) pthread_cond_wait ( & cmd_cond , & slave_lock ) ; to_send = gtp_cmd ; } int bin_size = 0 ; void * bin_buf = get_binary_arg ( sstate , gtp_cmd , gtp_cmds + CMDS_SIZE - gtp_cmd , & bin_size ) ; resend = true ; if ( ! bin_buf ) continue ; last_cmd_count = cmd_count ; char buf [ CMDS_SIZE ] ; int reply_id = send_command ( to_send , bin_buf , & bin_size , f , sstate , buf ) ; if ( reply_id == -1 ) return ; resend = process_reply ( reply_id , buf , reply_buf , bin_buf , bin_size , & last_reply_id , & reply_slot , sstate ) ; } }
Main loop of a slave thread.
Main loop of a slave thread .
/* Resend complete or partial history */ /* Wait for a new command. */ /* Command available, send it to slave machine.
		 * If slave was out of sync, send the history.
		 * But first get binary arguments if necessary. */ /* Check that the command is still valid. */ /* Send the command and get the reply, which always ends with \n\n
		 * The slave machine sends "=id reply" or "?id reply"
		 * with id == cmd_id if it is in sync. */