1 #ifndef ZZGO_DISTRIBUTED_PROTOCOL_H
2 #define ZZGO_DISTRIBUTED_PROTOCOL_H
4 #include <sys/socket.h>
10 /* Each slave thread maintains a ring of 32 buffers holding
11 * incremental stats received from the slave. The oldest
12 * buffer is recycled to hold stats sent to the slave and
13 * received the next reply. */
14 #define BUFFERS_PER_SLAVE_BITS 5
15 #define BUFFERS_PER_SLAVE (1 << BUFFERS_PER_SLAVE_BITS)
18 typedef void (*buffer_hook
)(void *buf
, int size
);
19 typedef void (*state_alloc_hook
)(struct slave_state
*sstate
);
20 typedef int (*getargs_hook
)(void *buf
, struct slave_state
*sstate
, int cmd_id
);
25 struct in_addr client
; // for debugging only
26 state_alloc_hook alloc_hook
;
27 buffer_hook insert_hook
;
28 getargs_hook args_hook
;
30 /* Index in received_queue of most recent processed
31 * buffer, -1 if none processed yet. */
34 /* --- PRIVATE DATA for protocol.c --- */
39 /* Index in received_queue, -1 if not there. */
41 } b
[BUFFERS_PER_SLAVE
];
46 /* Id of gtp command at time of last_processed. */
49 /* --- PRIVATE DATA for merge.c --- */
51 /* Hash table of incremental stats. */
52 struct incr_stats
*stats_htable
;
56 /* Hash indices updated by stats merge. */
60 extern struct slave_state default_sstate
;
62 void protocol_lock(void);
63 void protocol_unlock(void);
65 void logline(struct in_addr
*client
, char *prefix
, char *s
);
67 void clear_receive_queue(void);
68 void update_cmd(struct board
*b
, char *cmd
, char *args
, bool new_id
);
69 void new_cmd(struct board
*b
, char *cmd
, char *args
);
70 void get_replies(double time_limit
, int min_replies
);
71 void protocol_init(char *slave_port
, char *proxy_port
, int max_slaves
);
73 extern int reply_count
;
74 extern char **gtp_replies
;
75 extern int active_slaves
;
77 /* All binary buffers received from all slaves in current move are in
78 * receive_queue[0..queue_length-1] */
81 /* All buffers have the same physical size.
82 * size is the number of valid bytes. */
84 /* id of the thread that received the buffer. */
87 extern struct receive_buf
*receive_queue
;
88 extern int queue_length
;
90 /* Max size of all gtp commands for one game.
91 * 60 chars for the first line of genmoves plus 100 lines
92 * of 30 chars each for the stats at last move. */
93 #define CMDS_SIZE (60*MAX_GAMELEN + 30*100)
95 /* Max size for one line of reply or slave log. */