handlersocket使用 第七章 Authentication

注: 本文档主要根据原作者的英文文档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配置文件中对应。

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值