gochatai/pachi_py/pachi/distributed/protocol.c
/* Send the gtp command to_send and get a reply from the slave machine.
 * Write the reply in buf which must have at least CMDS_SIZE bytes.
 * If *bin_size > 0, send bin_buf after the gtp command.
 * Return any binary reply in bin_buf and set its size in bin_size.
 * bin_buf is private to the slave and need not be copied.
 * Return the gtp command id, or -1 if error.
 * slave_lock is held on both entry and exit of this function. */
Send the gtp command to_send and get a reply from the slave machine.
Write the reply in buf which must have at least CMDS_SIZE bytes.
If *bin_size > 0, send bin_buf after the gtp command.
Return any binary reply in bin_buf and set its size in bin_size.
bin_buf is private to the slave and need not be copied.
Return the gtp command id, or -1 if error.
slave_lock is held on both entry and exit of this function.
Send the gtp command to_send and get a reply from the slave machine . Write the reply in buf which must have at least CMDS_SIZE bytes . If * bin_size > 0 send bin_buf after the gtp command . Return any binary reply in bin_buf and set its size in bin_size . bin_buf is private to the slave and need not be copied . Return the gtp command id or - 1 if error . slave_lock is held on both entry and exit of this function .
static int
send_command(char *to_send, void *bin_buf, int *bin_size,
	     FILE *f, struct slave_state *sstate, char *buf)
{
	assert(to_send && gtp_cmd && bin_buf && bin_size);
	strncpy(buf, to_send, CMDS_SIZE);
	bool resend = to_send != gtp_cmd;
	pthread_mutex_unlock(&slave_lock);
	if (DEBUGL(1) && resend)
		logline(&sstate->client, "? ",
			to_send == gtp_cmds ? "resend all\n" : "partial resend\n");
	double start = time_now();
	fputs(buf, f);
	if (*bin_size)
		fwrite(bin_buf, 1, *bin_size, f);
	fflush(f);
	if (DEBUGV(strchr(buf, '@'), 2)) {
		double ms = (time_now() - start) * 1000.0;
		if (!DEBUGL(3)) {
			char *s = strchr(buf, '\n');
			if (s) s[1] = '\0';
		}
		logline(&sstate->client, ">>", buf);
		if (*bin_size) {
			char b[1024];
			snprintf(b, sizeof(b),
				 "sent cmd %d+%d bytes in %.4fms\n",
				 (int)strlen(buf), *bin_size, ms);
			logline(&sstate->client, "= ", b);
		}
	}
	*bin_size = sstate->max_buf_size;
	int reply_id = get_reply(f, sstate->client, buf, bin_buf, bin_size);
	pthread_mutex_lock(&slave_lock);
	return reply_id;
}
static int send_command ( char * to_send , void * bin_buf , int * bin_size , FILE * f , struct slave_state * sstate , char * buf ) { assert ( to_send && gtp_cmd && bin_buf && bin_size ) ; strncpy ( buf , to_send , CMDS_SIZE ) ; bool resend = to_send != gtp_cmd ; pthread_mutex_unlock ( & slave_lock ) ; if ( DEBUGL ( 1 ) && resend ) logline ( & sstate -> client , " " , to_send == gtp_cmds ? " \n " : " \n " ) ; double start = time_now ( ) ; fputs ( buf , f ) ; if ( * bin_size ) fwrite ( bin_buf , 1 , * bin_size , f ) ; fflush ( f ) ; if ( DEBUGV ( strchr ( buf , ' ' ) , 2 ) ) { double ms = ( time_now ( ) - start ) * 1000.0 ; if ( ! DEBUGL ( 3 ) ) { char * s = strchr ( buf , ' \n ' ) ; if ( s ) s [ 1 ] = ' \0 ' ; } logline ( & sstate -> client , " " , buf ) ; if ( * bin_size ) { char b [ 1024 ] ; snprintf ( b , sizeof ( b ) , " \n " , ( int ) strlen ( buf ) , * bin_size , ms ) ; logline ( & sstate -> client , " " , b ) ; } } * bin_size = sstate -> max_buf_size ; int reply_id = get_reply ( f , sstate -> client , buf , bin_buf , bin_size ) ; pthread_mutex_lock ( & slave_lock ) ; return reply_id ; }
Send the gtp command to_send and get a reply from the slave machine.
Send the gtp command to_send and get a reply from the slave machine .
/* Reuse the buffers for the reply. */