注: 本文档主要根据原作者的英文文档protocol.en.txt写成,做了一些翻译工作和添加了一些例子以及一些需要注意的地方。如果本文档对你有所帮助,欢迎关注我的新浪微博:http://weibo.com/u/1857063732 如果有建议,欢迎发送到我的邮箱xiaoxuye1988@163.com 目前就职于 欢聚时代(YY), 从事于后台开发工作
Authentication
英文原文如下
Authentication
The'auth' request has the following syntax.
A <atyp> <akey>
-<atyp> must be '1'
-An 'auth' request succeeds iff <akey> is the correct secret specified by
the 'handlersocket_plain_secret' or'handlersocket_plain_secret_rw'.
-If an authentication is enabled for a listener, any other requests on a
connection fail before an 'auth' requestsucceeded on the connection.
认证
'auth'请求为以下形式:
A <atyp> <akey>
- <atyp> 必须是 '1'
-一个'auth'请求只有在<akey>和'handlersocket_plain_secret' 或'handlersocket_plain_secret_rw'指定的密码一致才能执行成功。
-如果对于一个监听的(服务)进程启动了认证,那么在这个连接上,在 'auth'请求成功执行之前任何其他请求都会失败。
Responsefor 'auth'
If'auth' is succeeded, HanderSocket returns a line of the following syntax.
0 1
'auth'请求的回应:
如果'auth'请求成功发送,HanderSocket 会返回0或1.
在哪里设置查看'handlersocket_plain_secret' 和'handlersocket_plain_secret_wr'?
一般在/etc/mysql/my.cnf中。
所使用的成员函数的原型:
virtual void request_buf_auth(const char *secret, const char *typ) =0;
举个简单例子:
cli->request_buf_auth("1234","1"); //第二个参数必须是"1"
do { //发送request_buf_open_index请求
if (cli->request_send()!= 0) {
fprintf(stderr, "request_send:%s\n", cli->get_error().c_str());
break;
}
if ((code =cli->response_recv(numflds)) != 0) {
fprintf(stderr, "response_recv:%s\n", cli->get_error().c_str());
break;
}
} while (false);
cli->response_buf_remove();
注意hstcpcli_ptr cli所使用的端口和对应的密码要和my.cnf配置文件中对应。